add wp-rocket
This commit is contained in:
572
wp-content/plugins/wp-rocket/inc/admin/admin.php
Normal file
572
wp-content/plugins/wp-rocket/inc/admin/admin.php
Normal file
@@ -0,0 +1,572 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Link to the configuration page of the plugin, support & documentation
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $actions Array of links to display.
|
||||
* @return array Updated array of links
|
||||
*/
|
||||
function rocket_settings_action_links( $actions ) {
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', 'https://wp-rocket.me/support/?utm_source=wp_plugin&utm_medium=wp_rocket', __( 'Support', 'rocket' ) ) );
|
||||
|
||||
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', get_rocket_documentation_url(), __( 'Docs', 'rocket' ) ) );
|
||||
|
||||
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', get_rocket_faq_url(), __( 'FAQ', 'rocket' ) ) );
|
||||
|
||||
array_unshift( $actions, sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG ), __( 'Settings', 'rocket' ) ) );
|
||||
|
||||
return $actions;
|
||||
}
|
||||
add_filter( 'plugin_action_links_' . plugin_basename( WP_ROCKET_FILE ), 'rocket_settings_action_links' );
|
||||
|
||||
/**
|
||||
* Add a link "Renew your licence" when you can't do it automatically (expired licence but new version available)
|
||||
*
|
||||
* @since 2.2
|
||||
*
|
||||
* @param array $plugin_meta An array of the plugin's metadata, including the version, author, author URI, and plugin URI.
|
||||
* @param string $plugin_file Path to the plugin file, relative to the plugins directory.
|
||||
* @return array Updated meta content if license is expired
|
||||
*/
|
||||
function rocket_plugin_row_meta( $plugin_meta, $plugin_file ) {
|
||||
if ( 'wp-rocket/wp-rocket.php' === $plugin_file ) {
|
||||
|
||||
$update_plugins = get_site_transient( 'update_plugins' );
|
||||
|
||||
if ( false !== $update_plugins && isset( $update_plugins->response[ $plugin_file ] ) && empty( $update_plugins->response[ $plugin_file ]->package ) ) {
|
||||
|
||||
$link = '<span class="dashicons dashicons-update rocket-dashicons"></span> <span class="rocket-renew">Renew your licence of WP Rocket to receive access to automatic upgrades and support.</span> <a href="http://wp-rocket.me" target="_blank" class="rocket-purchase">Purchase now</a>.';
|
||||
|
||||
$plugin_meta = array_merge( (array) $link, $plugin_meta );
|
||||
}
|
||||
}
|
||||
|
||||
return $plugin_meta;
|
||||
}
|
||||
add_action( 'plugin_row_meta', 'rocket_plugin_row_meta', 10, 2 );
|
||||
|
||||
/**
|
||||
* Add a link "Purge this cache" in the post edit area
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $actions An array of row action links.
|
||||
* @param object $post The post object.
|
||||
* @return array Updated array of row action links
|
||||
*/
|
||||
function rocket_post_row_actions( $actions, $post ) {
|
||||
if ( ! current_user_can( 'rocket_purge_posts' ) ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=post-' . $post->ID ), 'purge_cache_post-' . $post->ID );
|
||||
$actions['rocket_purge'] = sprintf( '<a href="%s">%s</a>', $url, __( 'Clear this cache', 'rocket' ) );
|
||||
|
||||
return $actions;
|
||||
}
|
||||
add_filter( 'page_row_actions', 'rocket_post_row_actions', 10, 2 );
|
||||
add_filter( 'post_row_actions', 'rocket_post_row_actions', 10, 2 );
|
||||
|
||||
/**
|
||||
* Add a link "Purge this cache" in the user edit area
|
||||
*
|
||||
* @since 2.6.12
|
||||
* @param array $actions An array of row action links.
|
||||
* @param object $user The user object.
|
||||
* @return array Updated array of row action links
|
||||
*/
|
||||
function rocket_user_row_actions( $actions, $user ) {
|
||||
if ( ! current_user_can( 'rocket_purge_users' ) || ! get_rocket_option( 'cache_logged_user', false ) ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=user-' . $user->ID ), 'purge_cache_user-' . $user->ID );
|
||||
$actions['rocket_purge'] = sprintf( '<a href="%s">%s</a>', $url, __( 'Clear this cache', 'rocket' ) );
|
||||
|
||||
return $actions;
|
||||
}
|
||||
add_filter( 'user_row_actions', 'rocket_user_row_actions', 10, 2 );
|
||||
|
||||
/**
|
||||
* Manage the dismissed boxes.
|
||||
*
|
||||
* @since 3.6 Reverse dependency with rocket_dismiss_box().
|
||||
* @since 2.4 Add a delete_transient on function name (box name).
|
||||
* @since 1.3.0 $args can replace $_GET when called internaly.
|
||||
* @since 1.1.10
|
||||
*
|
||||
* @param array $args An array of query args. Should not be used: see rocket_dismiss_box().
|
||||
*/
|
||||
function rocket_dismiss_boxes( $args = [] ) {
|
||||
global $pagenow;
|
||||
|
||||
$args = empty( $args ) ? $_GET : $args; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
|
||||
if ( ! isset( $args['box'], $args['action'], $args['_wpnonce'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! wp_verify_nonce( $args['_wpnonce'], "{$args['action']}_{$args['box']}" ) ) {
|
||||
if ( rocket_get_constant( 'DOING_AJAX' ) ) {
|
||||
wp_send_json( [ 'error' => 1 ] );
|
||||
} else {
|
||||
wp_nonce_ays( '' );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_dismiss_box( $args['box'] );
|
||||
|
||||
if ( 'admin-post.php' === $pagenow ) {
|
||||
if ( rocket_get_constant( 'DOING_AJAX' ) ) {
|
||||
wp_send_json( [ 'error' => 0 ] );
|
||||
} else {
|
||||
wp_safe_redirect( esc_url_raw( wp_get_referer() ) );
|
||||
rocket_get_constant( 'WP_ROCKET_IS_TESTING', false ) ? wp_die() : exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'wp_ajax_rocket_ignore', 'rocket_dismiss_boxes' );
|
||||
add_action( 'admin_post_rocket_ignore', 'rocket_dismiss_boxes' );
|
||||
|
||||
/**
|
||||
* Renew the plugin modification warning on plugin de/activation
|
||||
*
|
||||
* @since 1.3.0
|
||||
*
|
||||
* @param string $plugin plugin name.
|
||||
*/
|
||||
function rocket_dismiss_plugin_box( $plugin ) {
|
||||
if ( plugin_basename( WP_ROCKET_FILE ) !== $plugin ) {
|
||||
rocket_renew_box( 'rocket_warning_plugin_modification' );
|
||||
}
|
||||
}
|
||||
add_action( 'activated_plugin', 'rocket_dismiss_plugin_box' );
|
||||
add_action( 'deactivated_plugin', 'rocket_dismiss_plugin_box' );
|
||||
|
||||
/**
|
||||
* Display a prevention message when enabling or disabling a plugin can be in conflict with WP Rocket
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
function rocket_deactivate_plugin() {
|
||||
if ( ! isset( $_GET['plugin'], $_GET['_wpnonce'] ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'deactivate_plugin' ) ) {
|
||||
wp_nonce_ays( '' );
|
||||
}
|
||||
|
||||
deactivate_plugins( sanitize_text_field( wp_unslash( $_GET['plugin'] ) ) );
|
||||
|
||||
wp_safe_redirect( wp_get_referer() );
|
||||
die();
|
||||
}
|
||||
add_action( 'admin_post_deactivate_plugin', 'rocket_deactivate_plugin' );
|
||||
|
||||
/**
|
||||
* This function will force the direct download of the plugin's options, compressed.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
function rocket_do_options_export() {
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rocket_export' ) ) {
|
||||
wp_nonce_ays( '' );
|
||||
}
|
||||
|
||||
$filename = sprintf( 'wp-rocket-settings-%s-%s.json', date( 'Y-m-d' ), uniqid() ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
|
||||
$gz = 'gz' . strrev( 'etalfed' );
|
||||
$options = wp_json_encode( get_option( WP_ROCKET_SLUG ) ); // do not use get_rocket_option() here.
|
||||
nocache_headers();
|
||||
@header( 'Content-Type: application/json' );
|
||||
@header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
|
||||
@header( 'Content-Transfer-Encoding: binary' );
|
||||
@header( 'Content-Length: ' . strlen( $options ) );
|
||||
@header( 'Connection: close' );
|
||||
echo $options; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
exit();
|
||||
}
|
||||
add_action( 'admin_post_rocket_export', 'rocket_do_options_export' );
|
||||
|
||||
/**
|
||||
* Do the rollback
|
||||
*
|
||||
* @since 2.4
|
||||
*/
|
||||
function rocket_rollback() {
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rocket_rollback' ) ) {
|
||||
wp_nonce_ays( '' );
|
||||
}
|
||||
|
||||
$plugin_transient = get_site_transient( 'update_plugins' );
|
||||
$plugin_folder = plugin_basename( dirname( WP_ROCKET_FILE ) );
|
||||
$plugin = $plugin_folder . '/' . basename( WP_ROCKET_FILE );
|
||||
|
||||
$plugin_transient->response[ $plugin ] = (object) [
|
||||
'slug' => $plugin_folder,
|
||||
'new_version' => WP_ROCKET_LASTVERSION,
|
||||
'url' => 'https://wp-rocket.me',
|
||||
'package' => sprintf( 'https://wp-rocket.me/%s/wp-rocket_%s.zip', get_rocket_option( 'consumer_key' ), WP_ROCKET_LASTVERSION ),
|
||||
];
|
||||
|
||||
set_site_transient( 'update_plugins', $plugin_transient );
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
// translators: %s is the plugin name.
|
||||
$title = sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME );
|
||||
$nonce = 'upgrade-plugin_' . $plugin;
|
||||
$url = 'update.php?action=upgrade-plugin&plugin=' . rawurlencode( $plugin );
|
||||
$upgrader_skin = new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) );
|
||||
$upgrader = new Plugin_Upgrader( $upgrader_skin );
|
||||
|
||||
remove_filter( 'site_transient_update_plugins', 'rocket_check_update', 1 );
|
||||
add_filter( 'update_plugin_complete_actions', 'rocket_rollback_add_return_link' );
|
||||
rocket_put_content( WP_CONTENT_DIR . '/advanced-cache.php', '' );
|
||||
|
||||
$upgrader->upgrade( $plugin );
|
||||
|
||||
wp_die(
|
||||
'',
|
||||
// translators: %s is the plugin name.
|
||||
esc_html( sprintf( __( '%s Update Rollback', 'rocket' ), WP_ROCKET_PLUGIN_NAME ) ),
|
||||
[
|
||||
'response' => 200,
|
||||
]
|
||||
);
|
||||
}
|
||||
add_action( 'admin_post_rocket_rollback', 'rocket_rollback' );
|
||||
|
||||
/**
|
||||
* After a rollback has been done, replace the "return to" link by a link pointing to WP Rocket's tools page.
|
||||
* A link to the plugins page is kept in case the plugin is not reactivated correctly.
|
||||
*
|
||||
* @since 3.2.4
|
||||
* @author Grégory Viguier
|
||||
* @author Arun Basil Lal
|
||||
*
|
||||
* @param array $update_actions Array of plugin action links.
|
||||
* @return array The array of links where the "return to" link has been replaced.
|
||||
*/
|
||||
function rocket_rollback_add_return_link( $update_actions ) {
|
||||
if ( ! isset( $update_actions['plugins_page'] ) ) {
|
||||
return $update_actions;
|
||||
}
|
||||
|
||||
$update_actions['plugins_page'] = sprintf(
|
||||
/* translators: 1 and 3 are link openings, 2 is a link closing. */
|
||||
__( '%1$sReturn to WP Rocket%2$s or %3$sgo to Plugins page%2$s', 'rocket' ),
|
||||
'<a href="' . esc_url( admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG ) . '#tools' ) . '" target="_parent">',
|
||||
'</a>',
|
||||
'<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '" target="_parent">'
|
||||
);
|
||||
|
||||
return $update_actions;
|
||||
}
|
||||
|
||||
if ( ! defined( 'DOING_AJAX' ) && ! defined( 'DOING_AUTOSAVE' ) ) {
|
||||
add_action( 'admin_init', 'rocket_init_cache_dir' );
|
||||
add_action( 'admin_init', 'rocket_maybe_generate_advanced_cache_file' );
|
||||
add_action( 'admin_init', 'rocket_maybe_generate_config_files' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate the advanced-cache.php file if an issue is detected.
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
function rocket_maybe_generate_advanced_cache_file() {
|
||||
if ( ! defined( 'WP_ROCKET_ADVANCED_CACHE' ) || ( defined( 'WP_ROCKET_ADVANCED_CACHE_PROBLEM' ) && WP_ROCKET_ADVANCED_CACHE_PROBLEM ) ) {
|
||||
rocket_generate_advanced_cache_file();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate config file if an issue is detected.
|
||||
*
|
||||
* @since 2.6.5
|
||||
*/
|
||||
function rocket_maybe_generate_config_files() {
|
||||
$home = get_rocket_parse_url( rocket_get_home_url() );
|
||||
|
||||
$path = ( ! empty( $home['path'] ) ) ? str_replace( '/', '.', untrailingslashit( $home['path'] ) ) : '';
|
||||
|
||||
if ( ! file_exists( WP_ROCKET_CONFIG_PATH . strtolower( $home['host'] ) . $path . '.php' ) ) {
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter plugin fetching API results to inject Imagify
|
||||
*
|
||||
* @since 2.10.7
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param object|WP_Error $result Response object or WP_Error.
|
||||
* @param string $action The type of information being requested from the Plugin Install API.
|
||||
* @param object $args Plugin API arguments.
|
||||
*
|
||||
* @return array Updated array of results
|
||||
*/
|
||||
function rocket_add_imagify_api_result( $result, $action, $args ) {
|
||||
if ( empty( $args->browse ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( 'featured' !== $args->browse && 'recommended' !== $args->browse && 'popular' !== $args->browse ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( ! isset( $result->info['page'] ) || 1 < $result->info['page'] ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( is_plugin_active( 'imagify/imagify.php' ) || is_plugin_active_for_network( 'imagify/imagify.php' ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// grab all slugs from the api results.
|
||||
$result_slugs = wp_list_pluck( $result->plugins, 'slug' );
|
||||
|
||||
if ( in_array( 'imagify', $result_slugs, true ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$query_args = [
|
||||
'slug' => 'imagify',
|
||||
'fields' => [
|
||||
'icons' => true,
|
||||
'active_installs' => true,
|
||||
'short_description' => true,
|
||||
'group' => true,
|
||||
],
|
||||
];
|
||||
$imagify_data = plugins_api( 'plugin_information', $query_args );
|
||||
|
||||
if ( is_wp_error( $imagify_data ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( 'featured' === $args->browse ) {
|
||||
array_push( $result->plugins, $imagify_data );
|
||||
} else {
|
||||
array_unshift( $result->plugins, $imagify_data );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
add_filter( 'plugins_api_result', 'rocket_add_imagify_api_result', 11, 3 );
|
||||
|
||||
/**
|
||||
* Gets all data to send to the analytics system
|
||||
*
|
||||
* @since 3.0 Send CDN zones, sitemaps paths, and count the number of CDN URLs used
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return mixed An array of data, or false if WP Rocket options is not an array
|
||||
*/
|
||||
function rocket_analytics_data() {
|
||||
global $wp_version, $is_nginx, $is_apache, $is_iis7, $is_IIS;
|
||||
|
||||
if ( ! is_array( get_option( WP_ROCKET_SLUG ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$untracked_wp_rocket_options = [
|
||||
'license' => 1,
|
||||
'consumer_email' => 1,
|
||||
'consumer_key' => 1,
|
||||
'secret_key' => 1,
|
||||
'secret_cache_key' => 1,
|
||||
'minify_css_key' => 1,
|
||||
'minify_js_key' => 1,
|
||||
'cloudflare_email' => 1,
|
||||
'cloudflare_api_key' => 1,
|
||||
'cloudflare_zone_id' => 1,
|
||||
'cloudflare_old_settings' => 1,
|
||||
'submit_optimize' => 1,
|
||||
'analytics_enabled' => 1,
|
||||
];
|
||||
|
||||
$theme = wp_get_theme();
|
||||
$data = array_diff_key( get_option( WP_ROCKET_SLUG ), $untracked_wp_rocket_options );
|
||||
$locale = explode( '_', get_locale() );
|
||||
$data['web_server'] = 'Unknown';
|
||||
|
||||
if ( $is_nginx ) {
|
||||
$data['web_server'] = 'NGINX';
|
||||
} elseif ( $is_apache ) {
|
||||
$data['web_server'] = 'Apache';
|
||||
} elseif ( $is_iis7 ) {
|
||||
$data['web_server'] = 'IIS 7';
|
||||
} elseif ( $is_IIS ) {
|
||||
$data['web_server'] = 'IIS';
|
||||
}
|
||||
|
||||
$data['php_version'] = preg_replace( '@^(\d\.\d+).*@', '\1', phpversion() );
|
||||
$data['wordpress_version'] = preg_replace( '@^(\d\.\d+).*@', '\1', $wp_version );
|
||||
$data['current_theme'] = $theme->get( 'Name' );
|
||||
$data['active_plugins'] = rocket_get_active_plugins();
|
||||
$data['locale'] = $locale[0];
|
||||
$data['multisite'] = is_multisite();
|
||||
|
||||
if ( ! empty( $data['cdn_cnames'] ) && is_array( $data['cdn_cnames'] ) ) {
|
||||
$data['cdn_cnames'] = count( $data['cdn_cnames'] );
|
||||
} else {
|
||||
$data['cdn_cnames'] = 0;
|
||||
}
|
||||
|
||||
if ( ! empty( $data['sitemaps'] ) && is_array( $data['sitemaps'] ) ) {
|
||||
$data['sitemaps'] = array_map( 'rocket_clean_exclude_file', $data['sitemaps'] );
|
||||
} else {
|
||||
$data['sitemaps'] = [];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if we should send the analytics data
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return bool True if we should send them, false otherwise
|
||||
*/
|
||||
function rocket_send_analytics_data() {
|
||||
if ( ! get_rocket_option( 'analytics_enabled' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'administrator' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false === get_transient( 'rocket_send_analytics_data' ) ) {
|
||||
set_transient( 'rocket_send_analytics_data', 1, 7 * DAY_IN_SECONDS );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the analytics opt-in notice selection and prevent further display
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_analytics_optin() {
|
||||
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'analytics_optin' ) ) {
|
||||
wp_nonce_ays( '' );
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'administrator' ) ) {
|
||||
wp_safe_redirect( wp_get_referer() );
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $_GET['value'] ) && 'yes' === $_GET['value'] ) {
|
||||
update_rocket_option( 'analytics_enabled', 1 );
|
||||
set_transient( 'rocket_analytics_optin', 1 );
|
||||
}
|
||||
|
||||
update_option( 'rocket_analytics_notice_displayed', 1 );
|
||||
|
||||
wp_safe_redirect( wp_get_referer() );
|
||||
die();
|
||||
}
|
||||
add_action( 'admin_post_rocket_analytics_optin', 'rocket_analytics_optin' );
|
||||
|
||||
/**
|
||||
* Handle WP Rocket settings import.
|
||||
*
|
||||
* @since 3.0 Hooked on admin_post now
|
||||
* @since 2.10.7
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function rocket_handle_settings_import() {
|
||||
check_ajax_referer( 'rocket_import_settings', 'rocket_import_settings_nonce' );
|
||||
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
rocket_settings_import_redirect( __( 'Settings import failed: you do not have the permissions to do this.', 'rocket' ), 'error' );
|
||||
}
|
||||
|
||||
if ( ! isset( $_FILES['import'] ) || ( isset( $_FILES['import']['size'] ) && 0 === $_FILES['import']['size'] ) ) {
|
||||
rocket_settings_import_redirect( __( 'Settings import failed: no file uploaded.', 'rocket' ), 'error' );
|
||||
}
|
||||
|
||||
if ( isset( $_FILES['import']['name'] ) && ! preg_match( '/wp-rocket-settings-20\d{2}-\d{2}-\d{2}-[a-f0-9]{13}\.(?:txt|json)/', sanitize_file_name( $_FILES['import']['name'] ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||
rocket_settings_import_redirect( __( 'Settings import failed: incorrect filename.', 'rocket' ), 'error' );
|
||||
}
|
||||
|
||||
add_filter( 'mime_types', 'rocket_allow_json_mime_type' );
|
||||
add_filter( 'wp_check_filetype_and_ext', 'rocket_check_json_filetype', 10, 4 );
|
||||
|
||||
$mimes = get_allowed_mime_types();
|
||||
$mimes = rocket_allow_json_mime_type( $mimes );
|
||||
$file_data = wp_check_filetype_and_ext( $_FILES['import']['tmp_name'], sanitize_file_name( $_FILES['import']['name'] ), $mimes ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
|
||||
|
||||
if ( 'text/plain' !== $file_data['type'] && 'application/json' !== $file_data['type'] ) {
|
||||
rocket_settings_import_redirect( __( 'Settings import failed: incorrect filetype.', 'rocket' ), 'error' );
|
||||
}
|
||||
|
||||
$_post_action = isset( $_POST['action'] ) ? wp_unslash( sanitize_key( $_POST['action'] ) ) : '';
|
||||
$_POST['action'] = 'wp_handle_sideload';
|
||||
$overrides = [];
|
||||
$overrides['mimes'] = $mimes;
|
||||
$file = wp_handle_sideload( $_FILES['import'], $overrides ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
|
||||
|
||||
if ( isset( $file['error'] ) ) {
|
||||
rocket_settings_import_redirect( __( 'Settings import failed: ', 'rocket' ) . $file['error'], 'error' );
|
||||
}
|
||||
|
||||
$_POST['action'] = $_post_action;
|
||||
$settings = rocket_direct_filesystem()->get_contents( $file['file'] );
|
||||
remove_filter( 'mime_types', 'rocket_allow_json_mime_type' );
|
||||
remove_filter( 'wp_check_filetype_and_ext', 'rocket_check_json_filetype', 10 );
|
||||
|
||||
if ( 'text/plain' === $file_data['type'] ) {
|
||||
$gz = 'gz' . strrev( 'etalfni' );
|
||||
$settings = $gz( $settings );
|
||||
$settings = maybe_unserialize( $settings );
|
||||
} elseif ( 'application/json' === $file_data['type'] ) {
|
||||
$settings = json_decode( $settings, true );
|
||||
|
||||
if ( null === $settings ) {
|
||||
rocket_settings_import_redirect( __( 'Settings import failed: unexpected file content.', 'rocket' ), 'error' );
|
||||
}
|
||||
}
|
||||
|
||||
rocket_put_content( $file['file'], '' );
|
||||
rocket_direct_filesystem()->delete( $file['file'] );
|
||||
|
||||
if ( is_array( $settings ) ) {
|
||||
$options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' );
|
||||
$current_options = $options_api->get( 'settings', [] );
|
||||
|
||||
$settings['consumer_key'] = $current_options['consumer_key'];
|
||||
$settings['consumer_email'] = $current_options['consumer_email'];
|
||||
$settings['secret_key'] = $current_options['secret_key'];
|
||||
$settings['secret_cache_key'] = $current_options['secret_cache_key'];
|
||||
$settings['minify_css_key'] = $current_options['minify_css_key'];
|
||||
$settings['minify_js_key'] = $current_options['minify_js_key'];
|
||||
$settings['version'] = $current_options['version'];
|
||||
|
||||
$options_api->set( 'settings', $settings );
|
||||
|
||||
rocket_settings_import_redirect( __( 'Settings imported and saved.', 'rocket' ), 'updated' );
|
||||
}
|
||||
}
|
||||
add_action( 'admin_post_rocket_import_settings', 'rocket_handle_settings_import' );
|
241
wp-content/plugins/wp-rocket/inc/admin/options.php
Normal file
241
wp-content/plugins/wp-rocket/inc/admin/options.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
use WP_Rocket\Logger\Logger;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* When our settings are saved: purge, flush, preload!
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* When the settins menu is hidden, redirect on the main settings page to avoid the same thing
|
||||
* (Only when a form is sent from our options page )
|
||||
*
|
||||
* @since 2.1
|
||||
*
|
||||
* @param array $oldvalue An array of previous values for the settings.
|
||||
* @param array $value An array of submitted values for the settings.
|
||||
*/
|
||||
function rocket_after_save_options( $oldvalue, $value ) {
|
||||
if ( ! is_array( $oldvalue ) || ! is_array( $value ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// These values do not need to clean the cache domain.
|
||||
$removed = [
|
||||
'cache_mobile' => true,
|
||||
'purge_cron_interval' => true,
|
||||
'purge_cron_unit' => true,
|
||||
'sitemap_preload' => true,
|
||||
'sitemaps' => true,
|
||||
'database_revisions' => true,
|
||||
'database_auto_drafts' => true,
|
||||
'database_trashed_posts' => true,
|
||||
'database_spam_comments' => true,
|
||||
'database_trashed_comments' => true,
|
||||
'database_expired_transients' => true,
|
||||
'database_all_transients' => true,
|
||||
'database_optimize_tables' => true,
|
||||
'schedule_automatic_cleanup' => true,
|
||||
'automatic_cleanup_frequency' => true,
|
||||
'do_cloudflare' => true,
|
||||
'cloudflare_email' => true,
|
||||
'cloudflare_api_key' => true,
|
||||
'cloudflare_zone_id' => true,
|
||||
'cloudflare_devmode' => true,
|
||||
'cloudflare_auto_settings' => true,
|
||||
'cloudflare_old_settings' => true,
|
||||
'heartbeat_admin_behavior' => true,
|
||||
'heartbeat_editor_behavior' => true,
|
||||
'varnish_auto_purge' => true,
|
||||
'do_beta' => true,
|
||||
'analytics_enabled' => true,
|
||||
'sucury_waf_cache_sync' => true,
|
||||
'sucury_waf_api_key' => true,
|
||||
'manual_preload' => true,
|
||||
];
|
||||
|
||||
// Create 2 arrays to compare.
|
||||
$oldvalue_diff = array_diff_key( $oldvalue, $removed );
|
||||
$value_diff = array_diff_key( $value, $removed );
|
||||
|
||||
// If it's different, clean the domain.
|
||||
if ( md5( wp_json_encode( $oldvalue_diff ) ) !== md5( wp_json_encode( $value_diff ) ) ) {
|
||||
// Purge all cache files.
|
||||
rocket_clean_domain();
|
||||
|
||||
wp_remote_get(
|
||||
home_url(),
|
||||
[
|
||||
'timeout' => 0.01,
|
||||
'blocking' => false,
|
||||
'user-agent' => 'WP Rocket/Homepage Preload',
|
||||
'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
if ( ( array_key_exists( 'minify_js', $oldvalue ) && array_key_exists( 'minify_js', $value ) && $oldvalue['minify_js'] !== $value['minify_js'] )
|
||||
||
|
||||
( array_key_exists( 'exclude_js', $oldvalue ) && array_key_exists( 'exclude_js', $value ) && $oldvalue['exclude_js'] !== $value['exclude_js'] )
|
||||
||
|
||||
( array_key_exists( 'cdn', $oldvalue ) && array_key_exists( 'cdn', $value ) && $oldvalue['cdn'] !== $value['cdn'] )
|
||||
||
|
||||
( array_key_exists( 'cdn_cnames', $oldvalue ) && array_key_exists( 'cdn_cnames', $value ) && $oldvalue['cdn_cnames'] !== $value['cdn_cnames'] )
|
||||
) {
|
||||
rocket_clean_minify( 'js' );
|
||||
}
|
||||
|
||||
// Regenerate advanced-cache.php file.
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
if ( ! empty( $_POST ) && ( ( isset( $oldvalue['do_caching_mobile_files'] ) && ! isset( $value['do_caching_mobile_files'] ) ) || ( ! isset( $oldvalue['do_caching_mobile_files'] ) && isset( $value['do_caching_mobile_files'] ) ) || ( isset( $oldvalue['do_caching_mobile_files'], $value['do_caching_mobile_files'] ) ) && $oldvalue['do_caching_mobile_files'] !== $value['do_caching_mobile_files'] ) ) {
|
||||
rocket_generate_advanced_cache_file();
|
||||
}
|
||||
|
||||
// Update .htaccess file rules.
|
||||
flush_rocket_htaccess( ! rocket_valid_key() );
|
||||
|
||||
// Update config file.
|
||||
rocket_generate_config_file();
|
||||
|
||||
if ( isset( $oldvalue['analytics_enabled'], $value['analytics_enabled'] ) && $oldvalue['analytics_enabled'] !== $value['analytics_enabled'] && 1 === (int) $value['analytics_enabled'] ) {
|
||||
set_transient( 'rocket_analytics_optin', 1 );
|
||||
}
|
||||
}
|
||||
add_action( 'update_option_' . rocket_get_constant( 'WP_ROCKET_SLUG' ), 'rocket_after_save_options', 10, 2 );
|
||||
|
||||
/**
|
||||
* Perform actions when settings are saved.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param array $newvalue An array of submitted options values.
|
||||
* @param array $oldvalue An array of previous options values.
|
||||
* @return array Updated submitted options values.
|
||||
*/
|
||||
function rocket_pre_main_option( $newvalue, $oldvalue ) {
|
||||
$rocket_settings_errors = [];
|
||||
|
||||
// Make sure that fields that allow users to enter patterns are well formatted.
|
||||
$is_form_submit = filter_input( INPUT_POST, 'option_page', FILTER_SANITIZE_STRING );
|
||||
$is_form_submit = WP_ROCKET_PLUGIN_SLUG === $is_form_submit;
|
||||
$errors = [];
|
||||
$pattern_labels = [
|
||||
'exclude_css' => __( 'Excluded CSS Files', 'rocket' ),
|
||||
'exclude_inline_js' => __( 'Excluded Inline JavaScript', 'rocket' ),
|
||||
'exclude_js' => __( 'Excluded JavaScript Files', 'rocket' ),
|
||||
'cache_reject_uri' => __( 'Never Cache URL(s)', 'rocket' ),
|
||||
'cache_reject_ua' => __( 'Never Cache User Agent(s)', 'rocket' ),
|
||||
'cache_purge_pages' => __( 'Always Purge URL(s)', 'rocket' ),
|
||||
'cdn_reject_files' => __( 'Exclude files from CDN', 'rocket' ),
|
||||
];
|
||||
|
||||
foreach ( $pattern_labels as $pattern_field => $label ) {
|
||||
if ( empty( $newvalue[ $pattern_field ] ) ) {
|
||||
// The field is empty.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sanitize.
|
||||
$newvalue[ $pattern_field ] = rocket_sanitize_textarea_field( $pattern_field, $newvalue[ $pattern_field ] );
|
||||
|
||||
// Validate.
|
||||
$newvalue[ $pattern_field ] = array_filter(
|
||||
$newvalue[ $pattern_field ],
|
||||
function( $excluded ) use ( $pattern_field, $label, $is_form_submit, &$errors ) {
|
||||
if ( false === @preg_match( '#' . str_replace( '#', '\#', $excluded ) . '#', 'dummy-sample' ) && $is_form_submit ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||
/* translators: 1 and 2 can be anything. */
|
||||
$errors[ $pattern_field ] = sprintf( __( '%1$s: <em>%2$s</em>.', 'rocket' ), $label, esc_html( $excluded ) );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if ( $errors ) {
|
||||
$error_message = _n( 'The following pattern is invalid and has been removed:', 'The following patterns are invalid and have been removed:', count( $errors ), 'rocket' );
|
||||
$error_message .= '<ul><li>' . implode( '</li><li>', $errors ) . '</li></ul>';
|
||||
$errors = [];
|
||||
|
||||
$rocket_settings_errors[] = [
|
||||
'setting' => 'general',
|
||||
'code' => 'invalid_patterns',
|
||||
'message' => __( 'WP Rocket: ', 'rocket' ) . '</strong>' . $error_message . '<strong>',
|
||||
'type' => 'error',
|
||||
];
|
||||
}
|
||||
|
||||
// Clear WP Rocket database optimize cron if the setting has been modified.
|
||||
if ( ( isset( $newvalue['schedule_automatic_cleanup'], $oldvalue['schedule_automatic_cleanup'] ) && $newvalue['schedule_automatic_cleanup'] !== $oldvalue['schedule_automatic_cleanup'] ) || ( ( isset( $newvalue['automatic_cleanup_frequency'], $oldvalue['automatic_cleanup_frequency'] ) && $newvalue['automatic_cleanup_frequency'] !== $oldvalue['automatic_cleanup_frequency'] ) ) ) {
|
||||
if ( wp_next_scheduled( 'rocket_database_optimization_time_event' ) ) {
|
||||
wp_clear_scheduled_hook( 'rocket_database_optimization_time_event' );
|
||||
}
|
||||
}
|
||||
|
||||
// Regenerate the minify key if JS files have been modified.
|
||||
if ( ( isset( $newvalue['minify_js'], $oldvalue['minify_js'] ) && $newvalue['minify_js'] !== $oldvalue['minify_js'] )
|
||||
|| ( isset( $newvalue['exclude_js'], $oldvalue['exclude_js'] ) && $newvalue['exclude_js'] !== $oldvalue['exclude_js'] )
|
||||
|| ( isset( $oldvalue['cdn'] ) && ! isset( $newvalue['cdn'] ) || ! isset( $oldvalue['cdn'] ) && isset( $newvalue['cdn'] ) )
|
||||
) {
|
||||
$newvalue['minify_js_key'] = create_rocket_uniqid();
|
||||
}
|
||||
|
||||
// Checked the SSL option if the whole website is on SSL.
|
||||
if ( rocket_is_ssl_website() ) {
|
||||
$newvalue['cache_ssl'] = 1;
|
||||
}
|
||||
|
||||
if ( ! rocket_get_constant( 'WP_ROCKET_ADVANCED_CACHE' ) ) {
|
||||
rocket_generate_advanced_cache_file();
|
||||
}
|
||||
|
||||
$keys = get_transient( WP_ROCKET_SLUG );
|
||||
|
||||
if ( $keys ) {
|
||||
delete_transient( WP_ROCKET_SLUG );
|
||||
$newvalue = array_merge( $newvalue, $keys );
|
||||
}
|
||||
|
||||
if ( ! $rocket_settings_errors ) {
|
||||
return $newvalue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display an error notice.
|
||||
* The notices are stored directly in the transient instead of using `add_settings_error()`, to make sure they are displayed even if we’re outside an admin screen.
|
||||
*/
|
||||
$transient_errors = get_transient( 'settings_errors' );
|
||||
|
||||
if ( ! $transient_errors || ! is_array( $transient_errors ) ) {
|
||||
$transient_errors = [];
|
||||
}
|
||||
|
||||
$transient_errors = array_merge( $transient_errors, $rocket_settings_errors );
|
||||
|
||||
set_transient( 'settings_errors', $transient_errors, 30 );
|
||||
|
||||
return $newvalue;
|
||||
}
|
||||
add_filter( 'pre_update_option_' . rocket_get_constant( 'WP_ROCKET_SLUG' ), 'rocket_pre_main_option', 10, 2 );
|
||||
|
||||
/**
|
||||
* Auto-activate the SSL cache if the website URL is updated with https protocol
|
||||
*
|
||||
* @since 2.7
|
||||
*
|
||||
* @param array $old_value An array of previous options values.
|
||||
* @param array $value An array of submitted options values.
|
||||
*/
|
||||
function rocket_update_ssl_option_after_save_home_url( $old_value, $value ) {
|
||||
if ( $old_value === $value || get_rocket_option( 'cache_ssl' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$scheme = rocket_extract_url_component( $value, PHP_URL_SCHEME );
|
||||
|
||||
update_rocket_option( 'cache_ssl', 'https' === $scheme ? 1 : 0 );
|
||||
}
|
||||
add_action( 'update_option_home', 'rocket_update_ssl_option_after_save_home_url', 10, 2 );
|
103
wp-content/plugins/wp-rocket/inc/admin/ui/enqueue.php
Normal file
103
wp-content/plugins/wp-rocket/inc/admin/ui/enqueue.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add the CSS and JS files for WP Rocket options page
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function rocket_add_admin_css_js() {
|
||||
wp_enqueue_style( 'wpr-admin', WP_ROCKET_ASSETS_CSS_URL . 'wpr-admin.css', null, WP_ROCKET_VERSION );
|
||||
wp_enqueue_script( 'micromodal', WP_ROCKET_ASSETS_JS_URL . 'micromodal.min.js', null, '0.4.2', true );
|
||||
wp_enqueue_script( 'wpr-admin', WP_ROCKET_ASSETS_JS_URL . 'wpr-admin.js', [ 'micromodal' ], WP_ROCKET_VERSION, true );
|
||||
wp_localize_script(
|
||||
'wpr-admin',
|
||||
'rocket_ajax_data',
|
||||
/**
|
||||
* Filters the data passed to the localize script function for WP Rocket admin JS
|
||||
*
|
||||
* @since 3.7.4
|
||||
*
|
||||
* @param array $data Localize script data.
|
||||
*/
|
||||
apply_filters(
|
||||
'rocket_localize_admin_script',
|
||||
[
|
||||
'nonce' => wp_create_nonce( 'rocket-ajax' ),
|
||||
'origin_url' => untrailingslashit( rocket_get_constant( 'WP_ROCKET_WEB_MAIN' ) ),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_rtl() ) {
|
||||
wp_enqueue_style( 'wpr-admin-rtl', WP_ROCKET_ASSETS_CSS_URL . 'wpr-admin-rtl.css', null, WP_ROCKET_VERSION );
|
||||
}
|
||||
|
||||
}
|
||||
add_action( 'admin_print_styles-settings_page_' . WP_ROCKET_PLUGIN_SLUG, 'rocket_add_admin_css_js' );
|
||||
|
||||
/**
|
||||
* Add the CSS and JS files needed by WP Rocket everywhere on admin pages
|
||||
*
|
||||
* @since 2.1
|
||||
*
|
||||
* @param string $hook Current admin page.
|
||||
*/
|
||||
function rocket_add_admin_css_js_everywhere( $hook ) {
|
||||
wp_enqueue_script( 'wpr-admin-common', WP_ROCKET_ASSETS_JS_URL . 'wpr-admin-common.js', [ 'jquery' ], WP_ROCKET_VERSION, true );
|
||||
wp_enqueue_style( 'wpr-admin-common', WP_ROCKET_ASSETS_CSS_URL . 'wpr-admin-common.css', [], WP_ROCKET_VERSION );
|
||||
|
||||
if ( 'plugins.php' === $hook ) {
|
||||
wp_enqueue_style( 'wpr-modal', WP_ROCKET_ASSETS_CSS_URL . 'wpr-modal.css', null, WP_ROCKET_VERSION );
|
||||
wp_enqueue_script( 'wpr-modal', WP_ROCKET_ASSETS_JS_URL . 'wpr-modal.js', null, WP_ROCKET_VERSION, true );
|
||||
wp_localize_script( 'wpr-modal', 'rocket_ajax_data', [ 'nonce' => wp_create_nonce( 'rocket-ajax' ) ] );
|
||||
}
|
||||
}
|
||||
add_action( 'admin_enqueue_scripts', 'rocket_add_admin_css_js_everywhere', 11 );
|
||||
|
||||
/**
|
||||
* Adds mixpanel JS code in header when analytics data should be sent
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_add_mixpanel_code() {
|
||||
if ( rocket_send_analytics_data() ) {
|
||||
?>
|
||||
<!-- start Mixpanel --><script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
|
||||
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
|
||||
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
|
||||
mixpanel.init("a36067b00a263cce0299cfd960e26ecf", {
|
||||
'ip':false,
|
||||
'property_blacklist': ['$initial_referrer', '$current_url', '$initial_referring_domain', '$referrer', '$referring_domain']
|
||||
} );
|
||||
mixpanel.track( 'WP Rocket', <?php echo wp_json_encode( rocket_analytics_data() ); ?> );
|
||||
mixpanel.track( 'Settings Sidebar Display', localStorage.getItem('wpr-show-sidebar') );
|
||||
</script><!-- end Mixpanel -->
|
||||
<?php
|
||||
}
|
||||
}
|
||||
add_action( 'admin_print_scripts', 'rocket_add_mixpanel_code' );
|
||||
|
||||
/**
|
||||
* Add CSS & JS files for the Imagify installation call to action
|
||||
*
|
||||
* @since 2.7
|
||||
*/
|
||||
function rocket_enqueue_modal_plugin() {
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( defined( 'IMAGIFY_VERSION' ) || in_array( 'rocket_imagify_notice', (array) $boxes, true ) || 1 === get_option( 'wp_rocket_dismiss_imagify_notice' ) || ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'plugin-install' );
|
||||
|
||||
wp_enqueue_script( 'plugin-install' );
|
||||
wp_enqueue_script( 'updates' );
|
||||
add_thickbox();
|
||||
}
|
||||
add_action( 'admin_print_styles-media-new.php', 'rocket_enqueue_modal_plugin' );
|
||||
add_action( 'admin_print_styles-upload.php', 'rocket_enqueue_modal_plugin' );
|
||||
add_action( 'admin_print_styles-settings_page_' . WP_ROCKET_PLUGIN_SLUG, 'rocket_enqueue_modal_plugin' );
|
177
wp-content/plugins/wp-rocket/inc/admin/ui/meta-boxes.php
Normal file
177
wp-content/plugins/wp-rocket/inc/admin/ui/meta-boxes.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Add a link "Purge cache" in the post submit area
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_post_submitbox_start() {
|
||||
if ( current_user_can( 'rocket_purge_posts' ) ) {
|
||||
global $post;
|
||||
$url = wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=post-' . $post->ID ), 'purge_cache_post-' . $post->ID );
|
||||
printf( '<div id="purge-action"><a class="button-secondary" href="%s">%s</a></div>', esc_url( $url ), esc_html__( 'Clear cache', 'rocket' ) );
|
||||
}
|
||||
}
|
||||
add_action( 'post_submitbox_start', 'rocket_post_submitbox_start' );
|
||||
|
||||
/**
|
||||
* Add "Cache options" metabox
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
function rocket_cache_options_meta_boxes() {
|
||||
if ( current_user_can( 'rocket_manage_options' ) ) {
|
||||
$cpts = get_post_types(
|
||||
[
|
||||
'public' => true,
|
||||
],
|
||||
'objects'
|
||||
);
|
||||
unset( $cpts['attachment'] );
|
||||
|
||||
foreach ( $cpts as $cpt => $cpt_object ) {
|
||||
$label = $cpt_object->labels->singular_name;
|
||||
add_meta_box( 'rocket_post_exclude', sprintf( __( 'WP Rocket Options', 'rocket' ), $label ), 'rocket_display_cache_options_meta_boxes', $cpt, 'side', 'core' );
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'add_meta_boxes', 'rocket_cache_options_meta_boxes' );
|
||||
|
||||
/**
|
||||
* Displays some checkbox to de/activate some cache options
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
function rocket_display_cache_options_meta_boxes() {
|
||||
if ( current_user_can( 'rocket_manage_options' ) ) {
|
||||
global $post, $pagenow;
|
||||
wp_nonce_field( 'rocket_box_option', '_rocketnonce', false, true );
|
||||
?>
|
||||
|
||||
<div class="misc-pub-section">
|
||||
<?php
|
||||
$reject_current_uri = false;
|
||||
if ( 'post-new.php' !== $pagenow ) {
|
||||
$rejected_uris = array_flip( get_rocket_option( 'cache_reject_uri', [] ) );
|
||||
$path = rocket_clean_exclude_file( get_permalink( $post->ID ) );
|
||||
|
||||
if ( isset( $rejected_uris[ $path ] ) ) {
|
||||
$reject_current_uri = true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<input name="rocket_post_nocache" id="rocket_post_nocache" type="checkbox" title="<?php esc_html_e( 'Never cache this page', 'rocket' ); ?>" <?php checked( $reject_current_uri, true ); ?>><label for="rocket_post_nocache"><?php esc_html_e( 'Never cache this page', 'rocket' ); ?></label>
|
||||
</div>
|
||||
|
||||
<div class="misc-pub-section">
|
||||
<p><?php esc_html_e( 'Activate these options on this post:', 'rocket' ); ?></p>
|
||||
<?php
|
||||
$fields = [
|
||||
'lazyload' => __( 'LazyLoad for images', 'rocket' ),
|
||||
'lazyload_iframes' => __( 'LazyLoad for iframes/videos', 'rocket' ),
|
||||
'minify_css' => __( 'Minify/combine CSS', 'rocket' ),
|
||||
'minify_js' => __( 'Minify/combine JS', 'rocket' ),
|
||||
'cdn' => __( 'CDN', 'rocket' ),
|
||||
'async_css' => __( 'Optimize CSS Delivery', 'rocket' ),
|
||||
'defer_all_js' => __( 'Defer JS', 'rocket' ),
|
||||
'delay_js' => __( 'Delay JavaScript execution', 'rocket' ),
|
||||
];
|
||||
|
||||
foreach ( $fields as $field => $label ) {
|
||||
$disabled = disabled( ! get_rocket_option( $field ), true, false );
|
||||
// translators: %s is the name of the option.
|
||||
$title = $disabled ? ' title="' . esc_attr( sprintf( __( 'Activate first the %s option.', 'rocket' ), $label ) ) . '"' : '';
|
||||
$class = $disabled ? ' class="rkt-disabled"' : '';
|
||||
$checked = ! $disabled ? checked( ! get_post_meta( $post->ID, '_rocket_exclude_' . $field, true ), true, false ) : '';
|
||||
?>
|
||||
|
||||
<input name="rocket_post_exclude_hidden[<?php echo esc_attr( $field ); ?>]" type="hidden" value="on">
|
||||
<input name="rocket_post_exclude[<?php echo esc_attr( $field ); ?>]" id="rocket_post_exclude_<?php echo esc_attr( $field ); ?>" type="checkbox"<?php echo $title; ?><?php echo $checked; ?><?php echo $disabled; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view. ?>>
|
||||
<label for="rocket_post_exclude_<?php echo esc_attr( $field ); ?>"<?php echo $title; ?><?php echo $class; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view. ?>><?php echo esc_html( $label ); ?></label><br>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<p class="rkt-note">
|
||||
<?php
|
||||
// translators: %1$s = opening strong tag, %2$s = closing strong tag.
|
||||
printf( esc_html__( '%1$sNote:%2$s None of these options will be applied if this post has been excluded from cache in the global cache settings.', 'rocket' ), '<strong>', '</strong>' );
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Fires after WP Rocket’s metabox.
|
||||
*
|
||||
* @since 3.6
|
||||
*/
|
||||
do_action( 'rocket_after_options_metabox' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage the cache options from the metabox.
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
function rocket_save_metabox_options() {
|
||||
if ( current_user_can( 'rocket_manage_options' ) &&
|
||||
isset( $_POST['post_ID'], $_POST['rocket_post_exclude_hidden'], $_POST['_rocketnonce'] ) ) {
|
||||
|
||||
check_admin_referer( 'rocket_box_option', '_rocketnonce' );
|
||||
|
||||
// No cache field.
|
||||
if ( isset( $_POST['post_status'] ) && 'publish' === $_POST['post_status'] ) {
|
||||
$new_cache_reject_uri = $cache_reject_uri = get_rocket_option( 'cache_reject_uri' ); // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
|
||||
$rejected_uris = array_flip( $cache_reject_uri );
|
||||
$path = rocket_clean_exclude_file( get_permalink( (int) $_POST['post_ID'] ) );
|
||||
|
||||
if ( isset( $_POST['rocket_post_nocache'] ) ) {
|
||||
if ( ! isset( $rejected_uris[ $path ] ) ) {
|
||||
array_push( $new_cache_reject_uri, $path );
|
||||
}
|
||||
} else {
|
||||
if ( isset( $rejected_uris[ $path ] ) ) {
|
||||
unset( $new_cache_reject_uri[ $rejected_uris[ $path ] ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $new_cache_reject_uri !== $cache_reject_uri ) {
|
||||
// Update the "Never cache the following pages" option.
|
||||
update_rocket_option( 'cache_reject_uri', $new_cache_reject_uri );
|
||||
|
||||
// Update config file.
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
}
|
||||
|
||||
// Options fields.
|
||||
$fields = [
|
||||
'lazyload',
|
||||
'lazyload_iframes',
|
||||
'minify_css',
|
||||
'minify_js',
|
||||
'cdn',
|
||||
'async_css',
|
||||
'defer_all_js',
|
||||
'delay_js',
|
||||
];
|
||||
|
||||
foreach ( $fields as $field ) {
|
||||
if ( isset( $_POST['rocket_post_exclude_hidden'][ $field ] ) ) {
|
||||
if ( isset( $_POST['rocket_post_exclude'][ $field ] ) ) {
|
||||
delete_post_meta( (int) $_POST['post_ID'], '_rocket_exclude_' . $field );
|
||||
} else {
|
||||
if ( get_rocket_option( $field ) ) {
|
||||
update_post_meta( (int) $_POST['post_ID'], '_rocket_exclude_' . $field, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action( 'save_post', 'rocket_save_metabox_options' );
|
852
wp-content/plugins/wp-rocket/inc/admin/ui/notices.php
Normal file
852
wp-content/plugins/wp-rocket/inc/admin/ui/notices.php
Normal file
@@ -0,0 +1,852 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* This warnings are displayed when the plugin can not be deactivated correctly
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function rocket_bad_deactivations() {
|
||||
global $current_user;
|
||||
|
||||
$msgs = get_transient( $current_user->ID . '_donotdeactivaterocket' );
|
||||
if ( current_user_can( 'rocket_manage_options' ) && $msgs ) {
|
||||
|
||||
delete_transient( $current_user->ID . '_donotdeactivaterocket' );
|
||||
$errors = [];
|
||||
|
||||
foreach ( $msgs as $msg ) {
|
||||
switch ( $msg ) {
|
||||
case 'wpconfig':
|
||||
$errors['wpconfig'] = '<p>' . sprintf(
|
||||
// translators: %1$s WP Rocket plugin name; %2$s = file name.
|
||||
__(
|
||||
'<strong>%1$s</strong> has not been deactivated due to missing writing permissions.<br>
|
||||
Make <strong>%2$s</strong> writeable and retry deactivation, or force deactivation now:',
|
||||
'rocket'
|
||||
),
|
||||
WP_ROCKET_PLUGIN_NAME,
|
||||
'wp-config.php'
|
||||
) . '</p>';
|
||||
break;
|
||||
|
||||
case 'htaccess':
|
||||
$errors['htaccess'] = '<p>' . sprintf(
|
||||
// translators: %1$s WP Rocket plugin name; %2$s = file name.
|
||||
__(
|
||||
'<strong>%1$s</strong> has not been deactivated due to missing writing permissions.<br>
|
||||
Make <strong>%2$s</strong> writeable and retry deactivation, or force deactivation now:',
|
||||
'rocket'
|
||||
),
|
||||
WP_ROCKET_PLUGIN_NAME,
|
||||
'.htaccess'
|
||||
) . '</p>';
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the output messages for each bad deactivation attempt.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $errors Contains the error messages to be filtered
|
||||
* @param string $msg Contains the error type (wpconfig or htaccess)
|
||||
*/
|
||||
$errors = apply_filters( 'rocket_bad_deactivations', $errors, $msg );
|
||||
|
||||
}
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'dismissible' => '',
|
||||
'message' => implode( '', $errors ),
|
||||
'action' => 'force_deactivation',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_bad_deactivations' );
|
||||
|
||||
/**
|
||||
* This warning is displayed to inform the user that a plugin de/activation can be followed by a cache clear
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
function rocket_warning_plugin_modification() {
|
||||
if ( current_user_can( 'rocket_manage_options' ) && rocket_valid_key() ) {
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'dismissible' => '',
|
||||
// translators: %s is WP Rocket plugin name.
|
||||
'message' => sprintf( __( '<strong>%s</strong>: One or more plugins have been enabled or disabled, clear the cache if they affect the front end of your site.', 'rocket' ), WP_ROCKET_PLUGIN_NAME ),
|
||||
'action' => 'clear_cache',
|
||||
'dismiss_button' => __FUNCTION__,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_plugin_modification' );
|
||||
|
||||
/**
|
||||
* This warning is displayed when some plugins may conflict with WP Rocket
|
||||
*
|
||||
* @since 1.3.0
|
||||
*/
|
||||
function rocket_plugins_to_deactivate() {
|
||||
$plugins = [];
|
||||
$plugins_explanations = [];
|
||||
|
||||
// Deactivate all plugins who can cause conflicts with WP Rocket.
|
||||
$plugins = [
|
||||
'w3-total-cache' => 'w3-total-cache/w3-total-cache.php',
|
||||
'wp-super-cache' => 'wp-super-cache/wp-cache.php',
|
||||
'litespeed-cache' => 'litespeed-cache/litespeed-cache.php',
|
||||
'quick-cache' => 'quick-cache/quick-cache.php',
|
||||
'hyper-cache' => 'hyper-cache/plugin.php',
|
||||
'hyper-cache-extended' => 'hyper-cache-extended/plugin.php',
|
||||
'wp-fast-cache' => 'wp-fast-cache/wp-fast-cache.php',
|
||||
'flexicache' => 'flexicache/wp-plugin.php',
|
||||
'wp-fastest-cache' => 'wp-fastest-cache/wpFastestCache.php',
|
||||
'lite-cache' => 'lite-cache/plugin.php',
|
||||
'gator-cache' => 'gator-cache/gator-cache.php',
|
||||
'cache-enabler' => 'cache-enabler/cache-enabler.php',
|
||||
'swift-performance-lite' => 'swift-performance-lite/performance.php',
|
||||
'swift-performance' => 'swift-performance/performance.php',
|
||||
'speed-booster-pack' => 'speed-booster-pack/speed-booster-pack.php',
|
||||
'wp-http-compression' => 'wp-http-compression/wp-http-compression.php',
|
||||
'wordpress-gzip-compression' => 'wordpress-gzip-compression/ezgz.php',
|
||||
'gzip-ninja-speed-compression' => 'gzip-ninja-speed-compression/gzip-ninja-speed.php',
|
||||
'speed-booster-pack' => 'speed-booster-pack/speed-booster-pack.php',
|
||||
'wp-performance-score-booster' => 'wp-performance-score-booster/wp-performance-score-booster.php',
|
||||
'remove-query-strings-from-static-resources' => 'remove-query-strings-from-static-resources/remove-query-strings.php',
|
||||
'query-strings-remover' => 'query-strings-remover/query-strings-remover.php',
|
||||
'wp-ffpc' => 'wp-ffpc/wp-ffpc.php',
|
||||
'far-future-expiry-header' => 'far-future-expiry-header/far-future-expiration.php',
|
||||
'combine-css' => 'combine-css/combine-css.php',
|
||||
'super-static-cache' => 'super-static-cache/super-static-cache.php',
|
||||
'wpcompressor' => 'wpcompressor/wpcompressor.php',
|
||||
'check-and-enable-gzip-compression' => 'check-and-enable-gzip-compression/richards-toolbox.php',
|
||||
'leverage-browser-caching-ninjas' => 'leverage-browser-caching-ninjas/leverage-browser-caching-ninja.php',
|
||||
'force-gzip' => 'force-gzip/force-gzip.php',
|
||||
'enable-gzip-compression' => 'enable-gzip-compression/enable-gzip-compression.php',
|
||||
'leverage-browser-caching' => 'leverage-browser-caching/leverage-browser-caching.php',
|
||||
'add-expires-headers' => 'add-expires-headers/add-expires-headers.php',
|
||||
'page-optimize' => 'page-optimize/page-optimize.php',
|
||||
];
|
||||
|
||||
if ( get_rocket_option( 'lazyload' ) ) {
|
||||
$plugins['bj-lazy-load'] = 'bj-lazy-load/bj-lazy-load.php';
|
||||
$plugins['lazy-load'] = 'lazy-load/lazy-load.php';
|
||||
$plugins['jquery-image-lazy-loading'] = 'jquery-image-lazy-loading/jq_img_lazy_load.php';
|
||||
$plugins['advanced-lazy-load'] = 'advanced-lazy-load/advanced_lazyload.php';
|
||||
$plugins['crazy-lazy'] = 'crazy-lazy/crazy-lazy.php';
|
||||
$plugins['specify-image-dimensions'] = 'specify-image-dimensions/specify-image-dimensions.php';
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'lazyload_iframes' ) ) {
|
||||
$plugins['lazy-load-for-videos'] = 'lazy-load-for-videos/codeispoetry.php';
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'minify_css' ) || get_rocket_option( 'minify_js' ) ) {
|
||||
$plugins['wp-super-minify'] = 'wp-super-minify/wp-super-minify.php';
|
||||
$plugins['bwp-minify'] = 'bwp-minify/bwp-minify.php';
|
||||
$plugins['wp-minify'] = 'wp-minify/wp-minify.php';
|
||||
$plugins['scripts-gzip'] = 'scripts-gzip/scripts_gzip.php';
|
||||
$plugins['minqueue'] = 'minqueue/plugin.php';
|
||||
$plugins['dependency-minification'] = 'dependency-minification/dependency-minification.php';
|
||||
$plugins['fast-velocity-minify'] = 'fast-velocity-minify/fvm.php';
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'minify_css' ) || get_rocket_option( 'minify_js' ) ) {
|
||||
$plugins['async-js-and-css'] = 'async-js-and-css/asyncJSandCSS.php';
|
||||
$plugins['merge-minify-refresh'] = 'merge-minify-refresh/merge-minify-refresh.php';
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'minify_js' ) ) {
|
||||
$plugins['wp-js'] = 'wp-js/wp-js.php';
|
||||
$plugins['combine-js'] = 'combine-js/combine-js.php';
|
||||
$plugins['footer-javascript'] = 'footer-javascript/footer-javascript.php';
|
||||
$plugins['scripts-to-footerphp'] = 'scripts-to-footerphp/scripts-to-footer.php';
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'do_cloudflare' ) ) {
|
||||
$plugins['cloudflare'] = 'cloudflare/cloudflare.php';
|
||||
$plugins_explanations['cloudflare'] = __( 'WP Rocket Cloudflare Add-on provides similar functionalities. They can not be active at the same time.', 'rocket' );
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'control_heartbeat' ) ) {
|
||||
$plugins['heartbeat-control'] = 'heartbeat-control/heartbeat-control.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the recommended plugins to deactivate to prevent conflicts
|
||||
*
|
||||
* @since 2.6.4
|
||||
*
|
||||
* @param string $plugins List of recommended plugins to deactivate
|
||||
*/
|
||||
$plugins = apply_filters( 'rocket_plugins_to_deactivate', $plugins );
|
||||
|
||||
$plugins = array_filter( $plugins, 'is_plugin_active' );
|
||||
|
||||
if ( current_user_can( 'rocket_manage_options' )
|
||||
&& count( $plugins )
|
||||
&& rocket_valid_key()
|
||||
) {
|
||||
|
||||
// translators: %s is WP Rocket plugin name.
|
||||
$warning = '<p>' . sprintf( __( '<strong>%s</strong>: The following plugins are not compatible with this plugin and may cause unexpected results:', 'rocket' ), WP_ROCKET_PLUGIN_NAME ) . '</p>';
|
||||
|
||||
$warning .= '<ul class="rocket-plugins-error">';
|
||||
|
||||
foreach ( $plugins as $k => $plugin ) {
|
||||
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin );
|
||||
$warning .= '<li><b>' . $plugin_data['Name'] . '</b>' . ( isset( $plugins_explanations[ $k ] ) ? ' - ' . $plugins_explanations[ $k ] : '' ) . '</span> <a href="' . wp_nonce_url( admin_url( 'admin-post.php?action=deactivate_plugin&plugin=' . rawurlencode( $plugin ) ), 'deactivate_plugin' ) . '" class="button-secondary alignright">' . __( 'Deactivate', 'rocket' ) . '</a></li>';
|
||||
}
|
||||
|
||||
$warning .= '</ul>';
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'dismissible' => '',
|
||||
'message' => $warning,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_plugins_to_deactivate' );
|
||||
|
||||
/**
|
||||
* Displays a warning if Rocket Footer JS plugin is active
|
||||
*
|
||||
* @since 3.2.3
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function rocket_warning_footer_js_plugin() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_plugin_active( 'rocket-footer-js/rocket-footer-js.php' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'message' => __( 'WP Rocket Footer JS is not an official add-on. It prevents some options in WP Rocket from working correctly. Please deactivate it if you have problems.', 'rocket' ),
|
||||
'dismiss_button' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_footer_js_plugin' );
|
||||
|
||||
/**
|
||||
* Display a warning if Endurance Cache is not disabled
|
||||
*
|
||||
* @since 3.3.7
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function rocket_warning_endurance_cache() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
// This filter is documented in inc/admin-bar.php.
|
||||
if ( ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Endurance_Page_Cache' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 0 === (int) get_option( 'endurance_cache_level' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'message' => sprintf(
|
||||
// translators: %1$s = opening link tag, %2$s = closing link tag.
|
||||
__( 'Endurance Cache is currently enabled, which will conflict with WP Rocket Cache. Please set the Endurance Cache cache level to Off (Level 0) on the %1$sSettings > General%2$s page to prevent any issues.', 'rocket' ),
|
||||
'<a href="' . admin_url( 'options-general.php#epc_settings' ) . '">',
|
||||
'</a>'
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_endurance_cache' );
|
||||
|
||||
/**
|
||||
* This warning is displayed when there is no permalink structure in the configuration.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_warning_using_permalinks() {
|
||||
if ( current_user_can( 'rocket_manage_options' )
|
||||
&& ! $GLOBALS['wp_rewrite']->using_permalinks()
|
||||
&& rocket_valid_key()
|
||||
) {
|
||||
$message = sprintf(
|
||||
/* translators: %1$s WP Rocket plugin name; %2$s = opening link; %3$s = closing link */
|
||||
__( '%1$s: A custom permalink structure is required for the plugin to work properly. %2$sGo to permalinks settings%3$s', 'rocket' ),
|
||||
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>',
|
||||
'<a href="' . admin_url( 'options-permalink.php' ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_using_permalinks' );
|
||||
|
||||
/**
|
||||
* This warning is displayed when the .htaccess file doesn't exist or isn't writeable
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_warning_htaccess_permissions() {
|
||||
global $is_apache;
|
||||
$htaccess_file = get_home_path() . '.htaccess';
|
||||
|
||||
if ( ! current_user_can( 'rocket_manage_options' )
|
||||
|| ( rocket_direct_filesystem()->is_writable( $htaccess_file ) )
|
||||
|| ! $is_apache
|
||||
// This filter is documented in inc/functions/htaccess.php.
|
||||
|| apply_filters( 'rocket_disable_htaccess', false )
|
||||
|| ! rocket_valid_key() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( rocket_check_htaccess_rules() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
// translators: %s = plugin name.
|
||||
__( '%s could not modify the .htaccess file due to missing writing permissions.', 'rocket' ),
|
||||
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>'
|
||||
);
|
||||
|
||||
$message .= '<br>' . sprintf(
|
||||
/* translators: This is a doc title! %1$s = opening link; %2$s = closing link */
|
||||
__( 'Troubleshoot: %1$sHow to make system files writeable%2$s', 'rocket' ),
|
||||
/* translators: Documentation exists in EN, DE, FR, ES, IT; use loaclised URL if applicable */
|
||||
'<a href="' . __( 'https://docs.wp-rocket.me/article/626-how-to-make-system-files-htaccess-wp-config-writeable/?utm_source=wp_plugin&utm_medium=wp_rocket', 'rocket' ) . '" target="_blank">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 42 );
|
||||
|
||||
$message .= '<p>' . __( 'Don’t worry, WP Rocket’s page caching and settings will still function correctly.', 'rocket' ) . '<br>' . __( 'For optimal performance, adding the following lines into your .htaccess is recommended (not required):', 'rocket' ) . '<br><textarea readonly="readonly" id="rocket_htaccess_rules" name="rocket_htaccess_rules" class="large-text readonly" rows="6">' . esc_textarea( get_rocket_htaccess_marker() ) . '</textarea></p>';
|
||||
|
||||
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 42 );
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'warning',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
'dismiss_button' => __FUNCTION__,
|
||||
]
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_htaccess_permissions' );
|
||||
|
||||
/**
|
||||
* This warning is displayed when the config dir isn't writeable
|
||||
*
|
||||
* @since 2.0.2
|
||||
*/
|
||||
function rocket_warning_config_dir_permissions() {
|
||||
if ( current_user_can( 'rocket_manage_options' )
|
||||
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_CONFIG_PATH ) )
|
||||
&& rocket_valid_key() ) {
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_CONFIG_PATH ), '/' ) );
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_config_dir_permissions' );
|
||||
|
||||
/**
|
||||
* This warning is displayed when the cache dir isn't writeable
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_warning_cache_dir_permissions() {
|
||||
if ( current_user_can( 'rocket_manage_options' )
|
||||
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_CACHE_PATH ) )
|
||||
&& rocket_valid_key() ) {
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_CACHE_PATH ), '/' ) );
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_cache_dir_permissions' );
|
||||
|
||||
/**
|
||||
* This warning is displayed when the minify cache dir isn't writeable
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
function rocket_warning_minify_cache_dir_permissions() {
|
||||
if ( current_user_can( 'rocket_manage_options' )
|
||||
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_MINIFY_CACHE_PATH ) )
|
||||
&& ( get_rocket_option( 'minify_css', false ) || get_rocket_option( 'minify_js', false ) )
|
||||
&& rocket_valid_key() ) {
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_MINIFY_CACHE_PATH ), '/' ) );
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_minify_cache_dir_permissions' );
|
||||
|
||||
/**
|
||||
* This warning is displayed when the busting cache dir isn't writeable
|
||||
*
|
||||
* @since 2.9
|
||||
*/
|
||||
function rocket_warning_busting_cache_dir_permissions() {
|
||||
if ( current_user_can( 'rocket_manage_options' )
|
||||
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_CACHE_BUSTING_PATH ) )
|
||||
&& rocket_valid_key() ) {
|
||||
|
||||
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
|
||||
|
||||
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_CACHE_BUSTING_PATH ), '/' ) );
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'error',
|
||||
'dismissible' => '',
|
||||
'message' => $message,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_warning_busting_cache_dir_permissions' );
|
||||
|
||||
/**
|
||||
* Confirming notice when the site has been added
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
function rocket_thank_you_license() {
|
||||
if ( '1' === get_rocket_option( 'license' ) ) {
|
||||
$options = get_option( WP_ROCKET_SLUG );
|
||||
$options['license'] = time();
|
||||
$options['ignore'] = true;
|
||||
update_option( WP_ROCKET_SLUG, $options );
|
||||
|
||||
$message = sprintf(
|
||||
/* translators: %1$s = plugin name, %2$s + %3$s = opening links, %4$s = closing link */
|
||||
__( '%1$s is good to go! %2$sTest your load time%4$s, or visit your %3$ssettings%4$s.', 'rocket' ),
|
||||
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>',
|
||||
'<a href="https://wp-rocket.me/blog/correctly-measure-websites-page-load-time/?utm_source=wp_plugin&utm_medium=wp_rocket" target="_blank">',
|
||||
'<a href="' . admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
rocket_notice_html( [ 'message' => $message ] );
|
||||
}
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_thank_you_license' );
|
||||
|
||||
/**
|
||||
* This notice is displayed after purging OPcache
|
||||
*
|
||||
* @since 3.4.1
|
||||
* @author Soponar Cristina
|
||||
*/
|
||||
function rocket_opcache_purge_result() {
|
||||
if ( ! current_user_can( 'rocket_purge_opcache' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$notice = get_transient( $user_id . '_opcache_purge_result' );
|
||||
if ( ! $notice ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_transient( $user_id . '_opcache_purge_result' );
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => $notice['result'],
|
||||
'message' => $notice['message'],
|
||||
]
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_opcache_purge_result' );
|
||||
|
||||
/**
|
||||
* Displays a notice for analytics opt-in
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_analytics_optin_notice() {
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 1 === (int) get_option( 'rocket_analytics_notice_displayed' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( get_rocket_option( 'analytics_enabled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$analytics_notice = sprintf(
|
||||
// Opening <p> provided by rocket_notice_html().
|
||||
'<strong>%1$s</strong><br>%2$s</p>',
|
||||
__( 'Would you allow WP Rocket to collect non-sensitive diagnostic data from this website?', 'rocket' ),
|
||||
__( 'This would help us to improve WP Rocket for you in the future.', 'rocket' )
|
||||
);
|
||||
|
||||
$analytics_notice .= sprintf(
|
||||
'<p><button class="hide-if-no-js button-rocket-reveal rocket-preview-analytics-data">%s</button></p>',
|
||||
/* translators: button text, click will expand data collection preview */
|
||||
__( 'What info will we collect?', 'rocket' )
|
||||
);
|
||||
|
||||
$analytics_notice .= sprintf(
|
||||
'<div class="rocket-analytics-data-container"><p class="description">%1$s</p>%2$s</div>',
|
||||
__( 'Below is a detailed view of all data WP Rocket will collect if granted permission. WP Rocket will never transmit any domain names or email addresses (except for license validation), IP addresses, or third-party API keys.', 'rocket' ),
|
||||
rocket_data_collection_preview_table()
|
||||
);
|
||||
|
||||
$analytics_notice .= sprintf(
|
||||
'<p><a href="%1$s" class="button button-primary">%2$s</a> <a href="%3$s" class="button button-secondary">%4$s</a>',
|
||||
// Closing </p> provided by rocket_notice_html().
|
||||
wp_nonce_url( admin_url( 'admin-post.php?action=rocket_analytics_optin&value=yes' ), 'analytics_optin' ),
|
||||
/* translators: button text for data collection opt-in */
|
||||
__( 'Yes, allow', 'rocket' ),
|
||||
wp_nonce_url( admin_url( 'admin-post.php?action=rocket_analytics_optin&value=no' ), 'analytics_optin' ),
|
||||
/* translators: button text for data collection opt-in */
|
||||
__( 'No, thanks', 'rocket' )
|
||||
);
|
||||
|
||||
// Status should be as neutral as possible; nothing has happened yet.
|
||||
rocket_notice_html(
|
||||
[
|
||||
'status' => 'info',
|
||||
'message' => $analytics_notice,
|
||||
]
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_analytics_optin_notice' );
|
||||
|
||||
/**
|
||||
* Displays a notice after analytics opt-in
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_analytics_optin_thankyou_notice() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! current_user_can( 'rocket_manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'settings_page_wprocket' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$analytics_optin = get_transient( 'rocket_analytics_optin' );
|
||||
|
||||
if ( ! $analytics_optin ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$thankyou_message = sprintf(
|
||||
// Opening <p> provided by rocket_notice_html().
|
||||
'<strong>%s</strong></p>',
|
||||
__( 'Thank you!', 'rocket' )
|
||||
);
|
||||
|
||||
$thankyou_message .= sprintf(
|
||||
'<p>%1$s</p><div>%2$s</div>',
|
||||
__( 'WP Rocket now collects these metrics from your website:', 'rocket' ),
|
||||
rocket_data_collection_preview_table()
|
||||
);
|
||||
|
||||
// Closing </p> provided by rocket_notice_html().
|
||||
$thankyou_message .= '<p>';
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'message' => $thankyou_message,
|
||||
]
|
||||
);
|
||||
|
||||
delete_transient( 'rocket_analytics_optin' );
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_analytics_optin_thankyou_notice' );
|
||||
|
||||
/**
|
||||
* Displays a notice after clearing the cache
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*/
|
||||
function rocket_clear_cache_notice() {
|
||||
$cleared_cache = get_transient( 'rocket_clear_cache' );
|
||||
|
||||
if ( ! $cleared_cache ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_transient( 'rocket_clear_cache' );
|
||||
|
||||
$notice = '';
|
||||
|
||||
switch ( $cleared_cache ) {
|
||||
case 'all':
|
||||
if ( current_user_can( 'rocket_purge_cache' ) ) {
|
||||
// translators: %s = plugin name.
|
||||
$notice = sprintf( __( '%s: Cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
|
||||
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
|
||||
}
|
||||
break;
|
||||
case 'post':
|
||||
if ( current_user_can( 'rocket_purge_posts' ) ) {
|
||||
// translators: %s = plugin name.
|
||||
$notice = sprintf( __( '%s: Post cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
|
||||
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
|
||||
}
|
||||
break;
|
||||
case 'term':
|
||||
if ( current_user_can( 'rocket_purge_terms' ) ) {
|
||||
// translators: %s = plugin name.
|
||||
$notice = sprintf( __( '%s: Term cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
|
||||
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
|
||||
}
|
||||
break;
|
||||
case 'user':
|
||||
if ( current_user_can( 'rocket_purge_users' ) ) {
|
||||
// translators: %s = plugin name).
|
||||
$notice = sprintf( __( '%s: User cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
|
||||
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( empty( $notice ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_notice_html(
|
||||
[
|
||||
'message' => $notice,
|
||||
]
|
||||
);
|
||||
}
|
||||
add_action( 'admin_notices', 'rocket_clear_cache_notice' );
|
||||
|
||||
/**
|
||||
* Outputs notice HTML
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Remy Perona
|
||||
*
|
||||
* @param array $args An array of arguments used to determine the notice output.
|
||||
* @return void
|
||||
*/
|
||||
function rocket_notice_html( $args ) {
|
||||
$defaults = [
|
||||
'status' => 'success',
|
||||
'dismissible' => 'is-dismissible',
|
||||
'message' => '',
|
||||
'action' => '',
|
||||
'dismiss_button' => false,
|
||||
'readonly_content' => '',
|
||||
];
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
switch ( $args['action'] ) {
|
||||
case 'clear_cache':
|
||||
$args['action'] = '<a class="wp-core-ui button" href="' . wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=all' ), 'purge_cache_all' ) . '">' . __( 'Clear cache', 'rocket' ) . '</a>';
|
||||
break;
|
||||
case 'stop_preload':
|
||||
$args['action'] = '<a class="wp-core-ui button" href="' . wp_nonce_url( admin_url( 'admin-post.php?action=rocket_stop_preload&type=all' ), 'rocket_stop_preload' ) . '">' . __( 'Stop Preload', 'rocket' ) . '</a>';
|
||||
break;
|
||||
case 'force_deactivation':
|
||||
/**
|
||||
* Allow a "force deactivation" link to be printed, use at your own risks
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param bool $permit_force_deactivation true will print the link.
|
||||
*/
|
||||
$permit_force_deactivation = apply_filters( 'rocket_permit_force_deactivation', true );
|
||||
|
||||
// We add a link to permit "force deactivation", use at your own risks.
|
||||
if ( $permit_force_deactivation ) {
|
||||
global $status, $page, $s;
|
||||
$plugin_file = 'wp-rocket/wp-rocket.php';
|
||||
$rocket_nonce = wp_create_nonce( 'force_deactivation' );
|
||||
|
||||
$args['action'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&rocket_nonce=' . $rocket_nonce . '&plugin=' . $plugin_file . '&plugin_status=' . $status . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '">' . __( 'Force deactivation ', 'rocket' ) . '</a>';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="notice notice-<?php echo esc_attr( $args['status'] ); ?> <?php echo esc_attr( $args['dismissible'] ); ?>">
|
||||
<?php
|
||||
$tag = 0 !== strpos( $args['message'], '<p' ) && 0 !== strpos( $args['message'], '<ul' );
|
||||
|
||||
echo ( $tag ? '<p>' : '' ) . $args['message'] . ( $tag ? '</p>' : '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
|
||||
?>
|
||||
<?php if ( ! empty( $args['readonly_content'] ) ) : ?>
|
||||
<p><?php esc_html_e( 'The following code should have been written to this file:', 'rocket' ); ?>
|
||||
<br><textarea readonly="readonly" id="rules" name="rules" class="large-text readonly" rows="6"><?php echo esc_textarea( $args['readonly_content'] ); ?></textarea>
|
||||
</p>
|
||||
<?php
|
||||
endif;
|
||||
if ( $args['action'] || $args['dismiss_button'] ) :
|
||||
?>
|
||||
<p>
|
||||
<?php echo $args['action']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php if ( $args['dismiss_button'] ) : ?>
|
||||
<a class="rocket-dismiss" href="<?php echo wp_nonce_url( admin_url( 'admin-post.php?action=rocket_ignore&box=' . $args['dismiss_button'] ), 'rocket_ignore_' . $args['dismiss_button'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"><?php esc_html_e( 'Dismiss this notice.', 'rocket' ); ?></a>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs formatted notice about issues with writing permissions
|
||||
*
|
||||
* @since 2.11
|
||||
* @author Caspar Hübinger
|
||||
*
|
||||
* @param string $file File or folder name.
|
||||
* @return string Message HTML
|
||||
*/
|
||||
function rocket_notice_writing_permissions( $file ) {
|
||||
|
||||
$message = sprintf(
|
||||
// translators: %s = plugin name.
|
||||
__( '%s cannot configure itself due to missing writing permissions.', 'rocket' ),
|
||||
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>'
|
||||
);
|
||||
|
||||
$message .= '<br>' . sprintf(
|
||||
/* translators: %s = file/folder name */
|
||||
__( 'Affected file/folder: %s', 'rocket' ),
|
||||
'<code>' . $file . '</code>'
|
||||
);
|
||||
|
||||
$message .= '<br>' . sprintf(
|
||||
/* translators: This is a doc title! %1$s = opening link; %2$s = closing link */
|
||||
__( 'Troubleshoot: %1$sHow to make system files writeable%2$s', 'rocket' ),
|
||||
/* translators: Documentation exists in EN, DE, FR, ES, IT; use loaclised URL if applicable */
|
||||
'<a href="' . __( 'https://docs.wp-rocket.me/article/626-how-to-make-system-files-htaccess-wp-config-writeable/?utm_source=wp_plugin&utm_medium=wp_rocket', 'rocket' ) . '" target="_blank">',
|
||||
'</a>'
|
||||
);
|
||||
|
||||
return $message;
|
||||
}
|
375
wp-content/plugins/wp-rocket/inc/admin/upgrader.php
Normal file
375
wp-content/plugins/wp-rocket/inc/admin/upgrader.php
Normal file
@@ -0,0 +1,375 @@
|
||||
<?php
|
||||
use WP_Rocket\Logger\Logger;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Tell WP what to do when admin is loaded aka upgrader
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_upgrader() {
|
||||
// Grab some infos.
|
||||
$actual_version = get_rocket_option( 'version' );
|
||||
// You can hook the upgrader to trigger any action when WP Rocket is upgraded.
|
||||
// first install.
|
||||
if ( ! $actual_version ) {
|
||||
do_action( 'wp_rocket_first_install' );
|
||||
}
|
||||
// already installed but got updated.
|
||||
elseif ( WP_ROCKET_VERSION !== $actual_version ) {
|
||||
do_action( 'wp_rocket_upgrade', WP_ROCKET_VERSION, $actual_version );
|
||||
}
|
||||
|
||||
// If any upgrade has been done, we flush and update version number.
|
||||
if ( did_action( 'wp_rocket_first_install' ) || did_action( 'wp_rocket_upgrade' ) ) {
|
||||
flush_rocket_htaccess();
|
||||
|
||||
rocket_renew_all_boxes( 0, [ 'rocket_warning_plugin_modification' ] );
|
||||
|
||||
$options = get_option( WP_ROCKET_SLUG ); // do not use get_rocket_option() here.
|
||||
$options['version'] = WP_ROCKET_VERSION;
|
||||
|
||||
$keys = rocket_check_key();
|
||||
if ( is_array( $keys ) ) {
|
||||
$options = array_merge( $keys, $options );
|
||||
}
|
||||
|
||||
update_option( WP_ROCKET_SLUG, $options );
|
||||
}
|
||||
|
||||
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
||||
|
||||
if ( ! rocket_valid_key() && current_user_can( 'rocket_manage_options' ) && 'wprocket' === $page ) {
|
||||
add_action( 'admin_notices', 'rocket_need_api_key' );
|
||||
}
|
||||
}
|
||||
add_action( 'admin_init', 'rocket_upgrader' );
|
||||
|
||||
/**
|
||||
* Maybe reset opcache after WP Rocket update.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $wp_upgrader Plugin_Upgrader instance.
|
||||
* @param array $hook_extra {
|
||||
* Array of bulk item update data.
|
||||
*
|
||||
* @type string $action Type of action. Default 'update'.
|
||||
* @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'.
|
||||
* @type bool $bulk Whether the update process is a bulk update. Default true.
|
||||
* @type array $plugins Array of the basename paths of the plugins' main files.
|
||||
* }
|
||||
*/
|
||||
function rocket_maybe_reset_opcache( $wp_upgrader, $hook_extra ) {
|
||||
static $rocket_path;
|
||||
|
||||
if ( ! isset( $hook_extra['action'], $hook_extra['type'], $hook_extra['plugins'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'update' !== $hook_extra['action'] || 'plugin' !== $hook_extra['type'] || ! is_array( $hook_extra['plugins'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$plugins = array_flip( $hook_extra['plugins'] );
|
||||
|
||||
if ( ! isset( $rocket_path ) ) {
|
||||
$rocket_path = plugin_basename( WP_ROCKET_FILE );
|
||||
}
|
||||
|
||||
if ( ! isset( $plugins[ $rocket_path ] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocket_reset_opcache();
|
||||
}
|
||||
add_action( 'upgrader_process_complete', 'rocket_maybe_reset_opcache', 20, 2 );
|
||||
|
||||
/**
|
||||
* Reset PHP opcache.
|
||||
*
|
||||
* @since 3.1
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
function rocket_reset_opcache() {
|
||||
static $can_reset;
|
||||
|
||||
/**
|
||||
* Triggers before WP Rocket tries to reset OPCache
|
||||
*
|
||||
* @since 3.2.5
|
||||
* @author Remy Perona
|
||||
*/
|
||||
do_action( 'rocket_before_reset_opcache' );
|
||||
|
||||
if ( ! isset( $can_reset ) ) {
|
||||
if ( ! function_exists( 'opcache_reset' ) ) {
|
||||
$can_reset = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$restrict_api = ini_get( 'opcache.restrict_api' );
|
||||
|
||||
if ( $restrict_api && strpos( __FILE__, $restrict_api ) !== 0 ) {
|
||||
$can_reset = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$can_reset = true;
|
||||
}
|
||||
|
||||
if ( ! $can_reset ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$opcache_reset = opcache_reset();
|
||||
|
||||
/**
|
||||
* Triggers after WP Rocket tries to reset OPCache
|
||||
*
|
||||
* @since 3.2.5
|
||||
* @author Remy Perona
|
||||
*/
|
||||
do_action( 'rocket_after_reset_opcache' );
|
||||
|
||||
return $opcache_reset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keeps this function up to date at each version
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
function rocket_first_install() {
|
||||
// Generate an random key for cache dir of user.
|
||||
$secret_cache_key = create_rocket_uniqid();
|
||||
|
||||
// Generate an random key for minify md5 filename.
|
||||
$minify_css_key = create_rocket_uniqid();
|
||||
$minify_js_key = create_rocket_uniqid();
|
||||
|
||||
// Create Option.
|
||||
add_option(
|
||||
rocket_get_constant( 'WP_ROCKET_SLUG' ),
|
||||
/**
|
||||
* Filters the default rocket options array
|
||||
*
|
||||
* @since 2.8
|
||||
*
|
||||
* @param array Array of default rocket options
|
||||
*/
|
||||
apply_filters(
|
||||
'rocket_first_install_options',
|
||||
[
|
||||
'secret_cache_key' => $secret_cache_key,
|
||||
'cache_mobile' => 1,
|
||||
'do_caching_mobile_files' => 0,
|
||||
'cache_webp' => 0,
|
||||
'cache_logged_user' => 0,
|
||||
'cache_ssl' => 1,
|
||||
'emoji' => 1,
|
||||
'embeds' => 0,
|
||||
'cache_reject_uri' => [],
|
||||
'cache_reject_cookies' => [],
|
||||
'cache_reject_ua' => [],
|
||||
'cache_query_strings' => [],
|
||||
'cache_purge_pages' => [],
|
||||
'purge_cron_interval' => 10,
|
||||
'purge_cron_unit' => 'HOUR_IN_SECONDS',
|
||||
'exclude_css' => [],
|
||||
'exclude_js' => [],
|
||||
'exclude_inline_js' => [],
|
||||
'defer_all_js' => 0,
|
||||
'defer_all_js_safe' => 1,
|
||||
'async_css' => 0,
|
||||
'critical_css' => '',
|
||||
'lazyload' => 0,
|
||||
'lazyload_iframes' => 0,
|
||||
'lazyload_youtube' => 0,
|
||||
'minify_css' => 0,
|
||||
'minify_css_key' => $minify_css_key,
|
||||
'minify_concatenate_css' => 0,
|
||||
'minify_js' => 0,
|
||||
'minify_js_key' => $minify_js_key,
|
||||
'minify_concatenate_js' => 0,
|
||||
'minify_google_fonts' => 1,
|
||||
'manual_preload' => 1,
|
||||
'sitemap_preload' => 0,
|
||||
'sitemap_preload_url_crawl' => '500000',
|
||||
'sitemaps' => [],
|
||||
'dns_prefetch' => 0,
|
||||
'preload_fonts' => [],
|
||||
'database_revisions' => 0,
|
||||
'database_auto_drafts' => 0,
|
||||
'database_trashed_posts' => 0,
|
||||
'database_spam_comments' => 0,
|
||||
'database_trashed_comments' => 0,
|
||||
'database_expired_transients' => 0,
|
||||
'database_all_transients' => 0,
|
||||
'database_optimize_tables' => 0,
|
||||
'schedule_automatic_cleanup' => 0,
|
||||
'automatic_cleanup_frequency' => 'daily',
|
||||
'cdn' => 0,
|
||||
'cdn_cnames' => [],
|
||||
'cdn_zone' => [],
|
||||
'cdn_reject_files' => [],
|
||||
'do_cloudflare' => 0,
|
||||
'cloudflare_email' => '',
|
||||
'cloudflare_api_key' => '',
|
||||
'cloudflare_zone_id' => '',
|
||||
'cloudflare_devmode' => 0,
|
||||
'cloudflare_protocol_rewrite' => 0,
|
||||
'cloudflare_auto_settings' => 0,
|
||||
'cloudflare_old_settings' => '',
|
||||
'control_heartbeat' => 0,
|
||||
'heartbeat_site_behavior' => 'reduce_periodicity',
|
||||
'heartbeat_admin_behavior' => 'reduce_periodicity',
|
||||
'heartbeat_editor_behavior' => 'reduce_periodicity',
|
||||
'varnish_auto_purge' => 0,
|
||||
'do_beta' => 0,
|
||||
'analytics_enabled' => 0,
|
||||
'google_analytics_cache' => 0,
|
||||
'facebook_pixel_cache' => 0,
|
||||
'sucury_waf_cache_sync' => 0,
|
||||
'sucury_waf_api_key' => '',
|
||||
]
|
||||
)
|
||||
);
|
||||
rocket_dismiss_box( 'rocket_warning_plugin_modification' );
|
||||
}
|
||||
add_action( 'wp_rocket_first_install', 'rocket_first_install' );
|
||||
|
||||
/**
|
||||
* What to do when Rocket is updated, depending on versions
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @param string $wp_rocket_version Latest WP Rocket version.
|
||||
* @param string $actual_version Installed WP Rocket version.
|
||||
*/
|
||||
function rocket_new_upgrade( $wp_rocket_version, $actual_version ) {
|
||||
if ( version_compare( $actual_version, '2.4.1', '<' ) ) {
|
||||
delete_transient( 'rocket_ask_for_update' );
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '2.8', '<' ) ) {
|
||||
$options = get_option( WP_ROCKET_SLUG );
|
||||
$options['manual_preload'] = 1;
|
||||
$options['automatic_preload'] = 1;
|
||||
$options['sitemap_preload_url_crawl'] = '500000';
|
||||
|
||||
update_option( WP_ROCKET_SLUG, $options );
|
||||
}
|
||||
|
||||
// Deactivate CloudFlare completely if PHP Version is lower than 5.4.
|
||||
if ( version_compare( $actual_version, '2.8.16', '<' ) ) {
|
||||
$options = get_option( WP_ROCKET_SLUG );
|
||||
$options['do_cloudflare'] = 0;
|
||||
$options['cloudflare_email'] = '';
|
||||
$options['cloudflare_api_key'] = '';
|
||||
$options['cloudflare_devmode'] = 0;
|
||||
$options['cloudflare_protocol_rewrite'] = 0;
|
||||
$options['cloudflare_auto_settings'] = 0;
|
||||
$options['cloudflare_old_settings'] = '';
|
||||
|
||||
update_option( WP_ROCKET_SLUG, $options );
|
||||
}
|
||||
|
||||
// Disable minification options if they're active in Autoptimize.
|
||||
if ( version_compare( $actual_version, '2.9.5', '<' ) ) {
|
||||
if ( is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
|
||||
if ( 'on' === get_option( 'autoptimize_css' ) ) {
|
||||
update_rocket_option( 'minify_css', 0 );
|
||||
}
|
||||
|
||||
if ( 'on' === get_option( 'autoptimize_js' ) ) {
|
||||
update_rocket_option( 'minify_js', 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete old transients.
|
||||
if ( version_compare( $actual_version, '2.9.7', '<' ) ) {
|
||||
delete_transient( 'rocket_check_licence_30' );
|
||||
delete_transient( 'rocket_check_licence_1' );
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '2.11', '<' ) ) {
|
||||
rocket_clean_minify();
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '3.2', '<' ) ) {
|
||||
// Default Heartbeat settings.
|
||||
$options = get_option( WP_ROCKET_SLUG, [] );
|
||||
$options['heartbeat_site_behavior'] = 'reduce_periodicity';
|
||||
$options['heartbeat_admin_behavior'] = 'reduce_periodicity';
|
||||
$options['heartbeat_editor_behavior'] = 'reduce_periodicity';
|
||||
|
||||
if ( ! empty( $options['automatic_preload'] ) || ! empty( $options['sitemap_preload'] ) ) {
|
||||
$options['manual_preload'] = 1;
|
||||
}
|
||||
|
||||
update_option( WP_ROCKET_SLUG, $options );
|
||||
rocket_generate_config_file();
|
||||
|
||||
// Create a .htaccess file in the log folder.
|
||||
$handler = Logger::get_stream_handler();
|
||||
|
||||
if ( method_exists( $handler, 'create_htaccess_file' ) ) {
|
||||
try {
|
||||
$success = $handler->create_htaccess_file();
|
||||
} catch ( \Exception $e ) {
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if ( ! $success ) {
|
||||
Logger::delete_log_file();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '3.2.0.1', '<' ) ) {
|
||||
wp_safe_remote_get( esc_url( home_url() ) );
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '3.3.6', '<' ) ) {
|
||||
delete_site_transient( 'update_wprocket' );
|
||||
delete_site_transient( 'update_wprocket_response' );
|
||||
|
||||
if ( get_rocket_option( 'do_cloudflare' ) && get_rocket_option( 'cloudflare_auto_settings' ) ) {
|
||||
if ( function_exists( 'set_rocket_cloudflare_browser_cache_ttl' ) ) {
|
||||
set_rocket_cloudflare_browser_cache_ttl( '31536000' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( rocket_is_ssl_website() ) {
|
||||
if ( 1 !== (int) get_rocket_option( 'cache_ssl' ) ) {
|
||||
update_rocket_option( 'cache_ssl', 1 );
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '3.4', '<' ) ) {
|
||||
wp_clear_scheduled_hook( 'rocket_purge_time_event' );
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '3.6', '<' ) ) {
|
||||
rocket_clean_cache_busting();
|
||||
rocket_clean_domain();
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '3.6.1', '<' ) ) {
|
||||
rocket_generate_config_file();
|
||||
}
|
||||
|
||||
if ( version_compare( $actual_version, '3.7', '<' ) ) {
|
||||
rocket_clean_minify( 'css' );
|
||||
rocket_generate_advanced_cache_file();
|
||||
}
|
||||
}
|
||||
add_action( 'wp_rocket_upgrade', 'rocket_new_upgrade', 10, 2 );
|
Reference in New Issue
Block a user