$url, 'kind' => $kind, 'post_id' => (int) $post_id, ); }; $add( home_url( '/' ), 'home' ); if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) { $add( get_permalink( (int) get_option( 'page_for_posts' ) ), 'archive' ); } $add( add_query_arg( 's', 'accessibility', home_url( '/' ) ), 'search' ); $add( home_url( '/a11ymate-404-check/' ), '404' ); // Archives. $sample = (int) $config['sample_archives']; if ( $sample > 0 ) { foreach ( get_taxonomies( array( 'public' => true ), 'names' ) as $tax ) { if ( 'post_format' === $tax ) { continue; } $terms = get_terms( array( 'taxonomy' => $tax, 'number' => $sample, 'orderby' => 'count', 'order' => 'DESC', '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' ); } } } $authors = get_users( array( 'number' => min( 3, $sample ), 'has_published_posts' => true, 'fields' => array( 'ID' ), ) ); foreach ( $authors as $u ) { $add( get_author_posts_url( (int) $u->ID ), 'author' ); } } // Content, round-robin over post types so a cap never drops a whole type. $types = array_values( array_intersect( (array) $config['post_types'], array_keys( get_post_types( array( 'public' => true ) ) ) ) ); $per = array(); foreach ( $types as $type ) { if ( 'attachment' === $type ) { continue; } $per[ $type ] = get_posts( array( 'post_type' => $type, 'post_status' => 'publish', 'posts_per_page' => $max > 0 ? $max : -1, 'orderby' => 'modified', 'order' => 'DESC', 'has_password' => false, 'fields' => 'ids', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, ) ); } $i = 0; $count_urls = static function () use ( &$list ) { return count( $list ); }; do { $any = false; foreach ( $per as $type => $ids ) { if ( isset( $ids[ $i ] ) ) { $any = true; $link = get_permalink( $ids[ $i ] ); if ( $link ) { $add( $link, $type, $ids[ $i ] ); } } } ++$i; } while ( $any && ( 0 === $max || $count_urls() < $max * 2 ) ); /** * Filter the list of URLs to scan. Add or remove entries. * * @param array[] $list Each: url, kind, post_id. * @param array $config Scan config. */ $list = apply_filters( 'a11ymate_scan_urls', $list, $config ); $list = self::exclude( $list, (string) $config['exclude_paths'] ); $list = array_values( $list ); return $max > 0 ? array_slice( $list, 0, $max ) : $list; } /** * Apply exclusion patterns (one per line, * is a wildcard, matched against the path). * * @param array[] $urls URLs. * @param string $pattern Patterns. * @return array[] */ public static function exclude( array $urls, $pattern ) { $rules = array_filter( array_map( 'trim', preg_split( '/\R/', $pattern ) ) ); if ( ! $rules ) { return $urls; } $regexes = array(); foreach ( $rules as $rule ) { $regexes[] = '#' . str_replace( '\*', '.*', preg_quote( $rule, '#' ) ) . '#i'; } return array_filter( $urls, static function ( $row ) use ( $regexes ) { $path = (string) wp_parse_url( $row['url'], PHP_URL_PATH ) . ( wp_parse_url( $row['url'], PHP_URL_QUERY ) ? '?' . wp_parse_url( $row['url'], PHP_URL_QUERY ) : '' ); foreach ( $regexes as $re ) { if ( preg_match( $re, $path ) ) { return false; } } return true; } ); } }