path => descriptor. */ public static function full_site() { $targets = array(); $add = function ( $url, $kind = 'page' ) use ( &$targets ) { if ( ! $url ) { return; } $path = self::path_for_url_path( (string) wp_parse_url( $url, PHP_URL_PATH ) ); if ( '' === $path ) { return; } $targets[ $path ] = array( 'url' => $url, 'kind' => $kind, ); }; $add( home_url( '/' ) ); // Every published thing with a public permalink. $types = get_post_types( array( 'public' => true ), 'names' ); unset( $types['attachment'] ); $posts = get_posts( array( 'post_type' => array_values( $types ), 'post_status' => 'publish', 'numberposts' => -1, 'fields' => 'ids', 'suppress_filters' => false, ) ); foreach ( $posts as $post_id ) { $add( get_permalink( $post_id ) ); } // Archives people actually navigate through. Date archives are left // out by default: on a long-running blog they multiply into hundreds // of near-identical pages that nothing links to. foreach ( get_taxonomies( array( 'public' => true ), 'names' ) as $taxonomy ) { $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => true, ) ); if ( is_wp_error( $terms ) ) { continue; } foreach ( $terms as $term ) { $link = get_term_link( $term ); if ( ! is_wp_error( $link ) ) { $add( $link, 'archive' ); } } } if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) { $add( get_permalink( (int) get_option( 'page_for_posts' ) ), 'archive' ); } /** * Filters the full list of export targets. * * @param array $targets path => {url, kind}. */ return apply_filters( 'sirius_press_export_targets', $targets ); } /** * The paths that go stale when one post changes. * * A post edit does not only change the post: it changes the home page, the * archives it belongs to, and the posts either side of it if the theme * shows previous/next links. Being generous here costs a few uploads; * being stingy leaves a reader looking at a stale index. * * @return array */ public static function affected_by_post( $post ) { $post = get_post( $post ); $targets = array(); if ( ! $post ) { return $targets; } $add = function ( $url, $kind = 'page' ) use ( &$targets ) { if ( ! $url || is_wp_error( $url ) ) { return; } $path = SPE_Mapper::path_for_url_path( (string) wp_parse_url( $url, PHP_URL_PATH ) ); if ( '' !== $path ) { $targets[ $path ] = array( 'url' => $url, 'kind' => $kind, ); } }; if ( 'publish' === $post->post_status ) { $add( get_permalink( $post ) ); } $add( home_url( '/' ) ); if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) { $add( get_permalink( (int) get_option( 'page_for_posts' ) ), 'archive' ); } foreach ( get_object_taxonomies( $post->post_type, 'names' ) as $taxonomy ) { $tax = get_taxonomy( $taxonomy ); if ( ! $tax || ! $tax->public ) { continue; } foreach ( (array) get_the_terms( $post, $taxonomy ) as $term ) { if ( $term instanceof WP_Term ) { $add( get_term_link( $term ), 'archive' ); } } } /** * Filters which paths a post change invalidates. * * @param array $targets * @param WP_Post $post */ return apply_filters( 'sirius_press_affected_paths', $targets, $post ); } }