* that doesn't halt page loading. * * @author Vova Feldman (@svovaf) * @since 1.1.7.3 * @since 2.0.0 Consolidate all the data sync into the sam8�`Ace optimizat�c�Aof API reque�c�Anumber of un d�A */ۅAync_cron() {Hd�A_logger->ent�tA $this->exepd�Array( &$this�d�A' ) ); �d�A * The�������������������������������������������������������������|�1��^*U�����.W�|���*U��xp��ܚ��,U * @param int|null $current_blog_id @since 2.2.3. This is passed from the `execute_cron` method and used by the * ��������H�+Ue` m T*Uthe ��+U  updates for a single site in case `execute_cron` has switched to a different blog. */ function _sync_cron_method( array $blog_ids, $current_blog_id = null ) { if ( ���������������������������������������������K ��w��+U@�����g�/<�r� +U�������|��T*U�2j��������+U����V.�|� U*U������{S� W*U�������ee!����;Ur premium plugin updates. ��������� +Uhis-true ); } } else { // Sync install(s) (only if something changed locally). if ( 1 < count( $blog_ids ) ) { $this->sync_installs(); } else { ������������������������������������������������@�����g�/<�r� +U`������"_�����+U������{S�`Y*U@����V.�|��Y*Uuted in the last $period of seconds. * * @author Vova Feldman (@svovaf) * @since 1.1.7.3 * ����������������������������������������������������@�����K ��w�8+U`��"_�����+U������{S��.*U@����V.�|�`P*U$this->is_cron_executed( 'sync', $period ); } /** * @author Vova Feldman (@svovaf) * @since ����������������������������������������������������@����V.�|�M)U����� i�|�@M)U�����H<2���w���(U � ���w�H�(Uo Fajardo (@leorw) * @since 2.5.0 */ private function maybe_schedule_sync_cron() { $next_�����������������������������������������EU ����n����}k�0�vA8�EU ����=����@�����A��V ����VPAN�w���rA��V �����0\j6�w�p�rA�{W ����Z� ��w���rA({W �����Lun��Ә�rA $this->schedule_sync_cron(); �Rl��U�)=Yl��U�P)A6Dl��UP)�2l��UP`)G�.l��U�`)H Dl��U``)A)`l��U)<\ l��UP����*>miAx�eA0��A��A������������������������������������������������������������������o.q�b&U9.1 */ private function maybe_schedule_install_sync_cron( $except_blog_id = 0 ) { if ( ! $this->is_user_in_admin() ) { return; } if ( $this->is_clone() ) �����������������������������������������������������i&U�����K ��w�i&U@�(U����V.�|���(UHh&U�����g�/<�r�j&U is_numeric( $this->next_install_sync() ) ) { return; } $this->schedule_cron( 'install_sync', 'install_sync����������������������������������������������������de_urls' => [ [ 'add_preload_excluded_uri' ], [ 'add_cache_reject_uri_to_excluded' ], ], 'rocket_rucss_after_clearing_failed_url' => [ 'clean_urls', 20 ], 'rocket_atf_after_clearing_failed_url' => [ 'clean_urls', 20 ], 'transition_post_status' => [ 'remove_private_post', 10, 3 ], 'rocket_preload_exclude' => [ 'exclude_private_url', 10, 2 ], ]; } /** * Load first tasks from preload when preload option is enabled. * * @param array $old_value old configuration values. * @param array $value new configuration values. * @return void */ public function maybe_load_initial_sitemap( $old_value, $value ) { if ( ! isset( $value['manual_preload'], $old_value['manual_preload'] ) ) { return; } if ( $value['manual_preload'] === $old_value['manual_preload'] ) { return; } if ( ! $value['manual_preload'] ) { return; } rocket_renew_box( 'preload_notice' ); $this->controller->load_initial_sitemap(); } /** * Cancel preload when configuration from sitemap changed. * * @param array $old_value old configuration values. * @param array $value new configuration values. * @return void */ public function maybe_cancel_preload( $old_value, $value ) { if ( ! isset( $value['manual_preload'], $old_value['manual_preload'] ) ) { return; } if ( $value['manual_preload'] === $old_value['manual_preload'] ) { return; } if ( $value['manual_preload'] ) { return; } $this->controller->cancel_preload(); } /** * Create or update the cache row after processing the buffer * * @return void */ public function update_cache_row() { global $wp; if ( is_user_logged_in() ) { return; } if ( (bool) ! $this->options->get( 'manual_preload', true ) ) { return; // Bail out if preload is disabled. } $url = home_url( add_query_arg( [], $wp->request ) ); $detected = $this->mobile_detect->isMobile() && ! $this->mobile_detect->isTablet() ? 'mobile' : 'desktop'; /** * Fires when the preload from an URL is completed. * * @param string $url URL preladed. * @param string $device Device from the cache. */ do_action( 'rocket_preload_completed', $url, $detected ); if ( ! empty( (array) $_GET ) || ( $this->query->is_pending( $url ) && $this->options->get( 'do_caching_mobile_files', false ) ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } if ( $this->is_excluded_by_filter( $url ) ) { $this->query->delete_by_url( $url ); return; } $this->query->create_or_update( [ 'url' => $url, 'status' => 'completed', 'last_accessed' => true, ] ); } /** * Delete url from the Preload when a 404 is risen. * * @return void */ public function delete_url_on_not_found() { global $wp; $url = home_url( $wp->request ); $this->query->delete_by_url( $url ); } /** * Preload on permalink changed. * * @return void */ public function on_permalink_changed() { $this->query->remove_all(); $this->queue->cancel_pending_jobs(); if ( ! $this->options->get( 'manual_preload', false ) ) { return; } $this->queue->add_job_preload_job_load_initial_sitemap_async(); } /** * Disable cron and jobs on update. * * @param string $new_version new version from the plugin. * @param string $old_version old version from the plugin. * @return void */ public function on_update( $new_version, $old_version ) { $this->activation->clean_on_update( $new_version, $old_version ); if ( ! $this->options->get( 'manual_preload', false ) ) { return; } $this->activation->refresh_on_update( $new_version, $old_version ); } /** * Clear preload on deactivation. * * @return void */ public function on_deactivation() { $this->activation->deactivation(); } /** * Clean the url. * * @param string $url url. * @return void */ public function clean_url( string $url ) { if ( ! $this->options->get( 'manual_preload', 0 ) ) { return; } $this->clear_cache->partial_clean( [ $url ] ); } /** * Preload after clearing full cache. * * @return void */ public function clean_full_cache() { if ( ! $this->options->get( 'manual_preload', 0 ) ) { return; } set_transient( 'wpr_preload_running', true ); $this->queue->add_job_preload_job_check_finished_async(); $this->clear_cache->full_clean(); } /** * Preload after clearing some cache. * * @param object $object object modified. * @param array $urls urls cleaned. * @param string $lang lang from the website. * @return void */ public function clean_partial_cache( $object, array $urls, $lang ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound if ( ! $this->options->get( 'manual_preload', false ) ) { return; } // Add Homepage URL to $purge_urls for preload. $urls[] = get_rocket_i18n_home_url( $lang ); $urls = array_filter( $urls ); $this->clear_cache->partial_clean( $urls ); } /** * Clean the list of urls. * * @param array $urls urls. * @return void */ public function clean_urls( array $urls ) { if ( ! $this->options->get( 'manual_preload', 0 ) ) { return; } $this->clear_cache->partial_clean( $urls ); } /** * Delete URL from a post from the preload. * * @param int $post_id ID from the post. * @return void */ public function delete_post_preload_cache( $post_id ) { if ( ! $this->options->get( 'manual_preload', 0 ) ) { return; } $url = get_permalink( $post_id ); if ( empty( $url ) ) { return; } $this->clear_cache->delete_url( $url ); } /** * Delete URL from a term from the preload. * * @param int $term_id ID from the term. * @return void */ public function delete_term_preload_cache( $term_id ) { if ( ! $this->options->get( 'manual_preload', 0 ) ) { return; } $url = get_term_link( (int) $term_id ); if ( empty( $url ) ) { return; } $this->clear_cache->delete_url( $url ); } /** * Pushes URLs to preload to the queue after cache directories are purged. * * @since 3.4 * * @param array $deleted { * An array of arrays, described like: {. * @type string $home_url The home URL. * @type string $home_path Path to home. * @type bool $logged_in True if the home path corresponds to a logged in user’s folder. * @type array $files A list of paths of files that have been deleted. * } * } */ public function preload_after_automatic_cache_purge( $deleted ) { if ( ! $deleted || ! $this->options->get( 'manual_preload' ) ) { return; } foreach ( $deleted as $data ) { if ( $data['logged_in'] ) { // Logged in user: no need to preload those since we would need the corresponding cookies. continue; } foreach ( $data['files'] as $file_path ) { if ( strpos( $file_path, '#' ) ) { // URL with query string. $file_path = preg_replace( '/#/', '?', $file_path, 1 ); } else { $file_path = untrailingslashit( $file_path ); $data['home_path'] = untrailingslashit( $data['home_path'] ); $data['home_url'] = untrailingslashit( $data['home_url'] ); if ( '/' === substr( get_option( 'permalink_structure' ), -1 ) ) { $file_path .= '/'; $data['home_path'] .= '/'; $data['home_url'] .= '/'; } } $this->clear_cache->partial_clean( [ str_replace( $data['home_path'], $data['home_url'], $file_path ) ] ); } } } /** * Remove index from url. * * @param string $url url to reformat. * * @return string */ public function format_preload_url( string $url ) { return preg_replace( '/(index(-https)?\.html$)|(index(-https)?\.html_gzip$)/', '', $url ); } /** * Lock a URL. * * @param string $url URL to lock. * * @return void */ public function lock_url( string $url ) { $this->query->lock( $url ); } /** * Unlock all URL. * * @return void */ public function unlock_all_urls() { $this->query->unlock_all(); } /** * Unlock a URL. * * @param string $url URL to unlock. * * @return void */ public function unlock_url( string $url ) { $this->query->unlock( $url ); } /** * Add the excluded uri from the preload to the filter. * * @param array $regexes regexes containing excluded uris. * @return array */ public function add_preload_excluded_uri( $regexes ): array { $preload_excluded_uri = (array) $this->options->get( 'preload_excluded_uri', [] ); if ( empty( $preload_excluded_uri ) ) { return $regexes; } return array_merge( $regexes, $preload_excluded_uri ); } /** * Remove private post from cache. * * @param string $new_status New post status. * @param string $old_status Old post status. * @param WP_Post $post Wp post object. * @return void */ public function remove_private_post( string $new_status, string $old_status, $post ) { if ( $new_status === $old_status ) { return; } if ( 'private' !== $new_status ) { return; } $this->delete_post_preload_cache( $post->ID ); } /** * Exclude private urls. * * @param bool $excluded In case we want to exclude that url. * @param string $url Current URL to test. * * @return bool Tells if it's excluded or not. */ public function exclude_private_url( $excluded, string $url ): bool { if ( $excluded ) { return true; } $is_private = ! empty( rocket_url_to_postid( $url, [ 'private' ] ) ); if ( $is_private ) { $this->logger::debug( "Private URL excluded from preload: {$url}", [ 'method' => __METHOD__, ] ); } return $is_private; } }