, '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, 'analytics_enabled' => true, 'sucury_waf_cache_sync' => true, 'sucury_waf_api_key' => true, ]; // Create 2 arrays to compare. $old_value_diff = array_diff_key( $old_value, $ignored_options ); $value_diff = array_diff_key( $value, $ignored_options ); // If it's different, preload. if ( md5( wp_json_encode( $old_value_diff ) ) === md5( wp_json_encode( $value_diff ) ) ) { return; } if ( isset( $value['manual_preload'] ) && 1 === (int) $value['manual_preload'] ) { $this->preload(); } } /** * After automatically preloading the homepage (after purging the cache), also preload the homepage for mobile. * * @since 3.5 * @author Grégory Viguier * * @param string $home_url URL to the homepage being preloaded. * @param string $lang The lang of the homepage. * @param array $args Arguments used for the preload request. */ public function maybe_preload_mobile_homepage( $home_url, $lang, $args ) { if ( ! $this->homepage_preloader->is_mobile_preload_enabled() ) { return; } if ( empty( $args['user-agent'] ) ) { $args['user-agent'] = 'WP Rocket/Homepage_Preload_After_Purge_Cache'; } $args['user-agent'] = $this->homepage_preloader->get_mobile_user_agent_prefix() . ' ' . $args['user-agent']; wp_safe_remote_get( $home_url, $args ); } /** * This notice is displayed when the preload is triggered from a different page than WP Rocket settings page * * @since 3.2 * @author Remy Perona */ public function notice_preload_triggered() { if ( ! current_user_can( 'rocket_preload_cache' ) ) { return; } $screen = get_current_screen(); if ( 'settings_page_wprocket' === $screen->id ) { return; } if ( false === get_transient( 'rocket_preload_triggered' ) ) { return; } delete_transient( 'rocket_preload_triggered' ); $message = __( 'Preload: WP Rocket has started preloading your website.', 'rocket' ); if ( current_user_can( 'rocket_manage_options' ) ) { $message .= ' ' . sprintf( // Translators: %1$s = opening link tag, %2$s = closing link tag. __( 'Go to the %1$sWP Rocket settings%2$s page to track progress.', 'rocket' ), '', '' ); } \rocket_notice_html( [ 'status' => 'info', 'message' => $message, ] ); } /** * This notice is displayed when the preload is running * * @since 3.2 * @author Remy Perona */ public function notice_preload_running() { if ( ! current_user_can( 'rocket_preload_cache' ) ) { return; } $screen = get_current_screen(); if ( 'settings_page_wprocket' !== $screen->id ) { return; } $homepage_count = get_transient( 'rocket_homepage_preload_running' ); $sitemap_count = get_transient( 'rocket_sitemap_preload_running' ); if ( false === $homepage_count && false === $sitemap_count ) { return; } $running = $homepage_count + $sitemap_count; $status = 'info'; // translators: %1$s = Number of pages preloaded. $message = '

' . sprintf( _n( 'Preload: %1$s uncached page has now been preloaded. (refresh to see progress)', 'Preload: %1$s uncached pages have now been preloaded. (refresh to see progress)', $running, 'rocket' ), number_format_i18n( $running ) ); $message .= ' - (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ')

'; if ( defined( 'WP_ROCKET_DEBUG' ) && WP_ROCKET_DEBUG ) { $errors = get_transient( 'rocket_preload_errors' ); if ( false !== $errors ) { $status = 'warning'; $message .= '

' . _n( 'The following error happened during gathering of the URLs to preload:', 'The following errors happened during gathering of the URLs to preload:', count( $errors['errors'] ), 'rocket' ) . '

'; foreach ( $errors['errors'] as $error ) { $message .= '

' . $error . '

'; } } } \rocket_notice_html( [ 'status' => $status, 'message' => $message, 'dismissible' => 'notice-preload-running', 'action' => 'stop_preload', ] ); } /** * This notice is displayed after the sitemap preload is complete * * @since 3.2 * @author Remy Perona */ public function notice_preload_complete() { if ( ! current_user_can( 'rocket_preload_cache' ) ) { return; } $screen = get_current_screen(); if ( 'settings_page_wprocket' !== $screen->id ) { return; } $result = get_transient( 'rocket_preload_complete' ); if ( false === $result ) { return; } $result_timestamp = get_transient( 'rocket_preload_complete_time' ); if ( false === $result_timestamp ) { return; } delete_transient( 'rocket_preload_complete' ); delete_transient( 'rocket_preload_errors' ); delete_transient( 'rocket_preload_complete_time' ); // translators: %d is the number of pages preloaded. $notice_message = sprintf( __( 'Preload complete: %d pages have been cached.', 'rocket' ), $result ); $notice_message .= ' (' . $result_timestamp . ') '; \rocket_notice_html( [ 'message' => $notice_message, ] ); } /** * Stops currently running preload from the notice action button * * @since 3.2 * @author Remy Perona */ public function do_admin_post_stop_preload() { if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'rocket_stop_preload' ) ) { wp_nonce_ays( '' ); } if ( ! current_user_can( 'rocket_preload_cache' ) ) { wp_safe_redirect( wp_get_referer() ); die(); } $this->homepage_preloader->cancel_preload(); wp_safe_redirect( wp_get_referer() ); die(); } }