=> $error_code, 'api_message' => $api_message, ], ] ); return false; } // HTTP 400 - Validation error like BAD_SITE_URL. if ( 400 === $http_code ) { $error_code = isset( $json->error->code ) ? $json->error->code : 'UNKNOWN_ERROR'; $api_message = isset( $json->error->message ) ? $json->error->message : null; Logger::error( 'License validation failed.', [ 'license validation process', 'http_code' => 400, 'error_code' => $error_code, ] ); // CL: Store error code for later translation in admin notice (after init hook). set_transient( 'rocket_check_key_errors', [ [ 'code' => $error_code, 'api_message' => $api_message, ], ] ); return false; } // HTTP 5xx - Server error, don't delete key. if ( $http_code >= 500 ) { Logger::error( 'License validation failed. Server error.', [ 'license validation process', 'http_code' => $http_code, ] ); // CL: Store error code for later translation in admin notice (after init hook). set_transient( 'rocket_check_key_errors', [ [ 'code' => 'SERVER_ERROR', 'http_code' => $http_code, ], ] ); return $return; } // HTTP 200 - Success. if ( 200 === $http_code && isset( $json->data->secret_key ) ) { delete_transient( 'wp_rocket_customer_data' ); $rocket_options['secret_key'] = $json->data->secret_key; if ( ! get_rocket_option( 'license' ) ) { $rocket_options['license'] = '1'; } Logger::info( 'License validation successful.', [ 'license validation process' ] ); set_transient( rocket_get_constant( 'WP_ROCKET_SLUG' ), $rocket_options ); delete_transient( 'rocket_check_key_errors' ); rocket_delete_licence_data_file(); update_option( 'wp_rocket_no_licence', 0 ); return $rocket_options; } // Unexpected response. Logger::error( 'License validation failed. Unexpected response.', [ 'license validation process', 'http_code' => $http_code, ] ); // CL: Store error code for later translation in admin notice (after init hook). set_transient( 'rocket_check_key_errors', [ [ 'code' => 'UNEXPECTED_RESPONSE', 'http_code' => $http_code, ], ] ); return $return; } /** * Deletes the licence-data.php file if it exists * * @since 3.5 * @author Remy Perona * * @return void */ function rocket_delete_licence_data_file() { // CL: Do not delete licence-data.php in non-standalone mode. if ( false === clsop_is_standalone() ) { return; } if ( is_multisite() ) { return; } $rocket_path = rocket_get_constant( 'WP_ROCKET_PATH' ); if ( ! rocket_direct_filesystem()->exists( $rocket_path . 'licence-data.php' ) ) { return; } rocket_direct_filesystem()->delete( $rocket_path . 'licence-data.php' ); } /** * Is WP a MultiSite and a subfolder install? * * @since 3.1.1 * @author Grégory Viguier * * @return bool */ function rocket_is_subfolder_install() { global $wpdb; static $subfolder_install; if ( isset( $subfolder_install ) ) { return $subfolder_install; } if ( is_multisite() ) { $subfolder_install = ! is_subdomain_install(); } elseif ( ! is_null( $wpdb->sitemeta ) ) { $subfolder_install = ! $wpdb->get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery } else { $subfolder_install = false; } return $subfolder_install; } /** * Get the name of the "home directory", in case the home URL is not at the domain's root. * It can be seen like the `RewriteBase` from the .htaccess file, but without the trailing slash. * * @since 3.1.1 * @author Grégory Viguier * * @return string */ function rocket_get_home_dirname() { static $home_root; if ( isset( $home_root ) ) { return $home_root; } $home_root = wp_parse_url( rocket_get_main_home_url() ); if ( ! empty( $home_root['path'] ) ) { $home_root = '/' . trim( $home_root['path'], '/' ); $home_root = rtrim( $home_root, '/' ); } else { $home_root = ''; } return $home_root; } /** * Get the URL of the site's root. It corresponds to the main site's home page URL. * * @since 3.1.1 * @author Grégory Viguier * * @return string */ function rocket_get_main_home_url() { static $root_url; if ( isset( $root_url ) ) { return $root_url; } if ( ! is_multisite() || is_main_site() ) { $root_url = rocket_get_home_url( '/' ); return $root_url; } $current_network = get_network(); if ( $current_network ) { $root_url = set_url_scheme( 'https://' . $current_network->domain . $current_network->path ); $root_url = trailingslashit( $root_url ); } else { $root_url = rocket_get_home_url( '/' ); } return $root_url; }