reload. $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 ) { $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|false */ 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 array $regexes regexes containing excluded uris. * @return array */ public function exclude_private_post_uri( $regexes ) : array { static $private_urls; if ( ! is_array( $regexes ) ) { $regexes = (array) $regexes; } if ( isset( $private_urls ) ) { return $private_urls; } $arg = [ 'post_type' => 'any', 'post_status' => 'private', 'posts_per_page' => -1, ]; $query = new \WP_Query( $arg ); if ( ! $query->have_posts() ) { return $regexes; } $private_post_urls = []; foreach ( $query->posts as $post ) { // Temporarily cast publish status to get pretty url. $post->post_status = 'publish'; $private_post_urls[] = get_permalink( $post ); } $private_urls = array_merge( $regexes, $private_post_urls ); return $private_urls; } }