diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/class-wp-rewrite.php --- a/wp/wp-includes/class-wp-rewrite.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/class-wp-rewrite.php Tue Dec 15 13:49:49 2020 +0100 @@ -442,7 +442,7 @@ $page_attachment_uris = array(); foreach ( $posts as $id => $post ) { - // URL => page name + // URL => page name. $uri = get_page_uri( $id ); $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ) ); if ( ! empty( $attachments ) ) { @@ -463,7 +463,7 @@ * * @since 1.5.0 * - * @return array Page rewrite rules. + * @return string[] Page rewrite rules. */ public function page_rewrite_rules() { // The extra .? at the beginning prevents clashes with other regular expressions in the rules array. @@ -489,7 +489,7 @@ * * @since 1.5.0 * - * @return string|false False on no permalink structure. Date permalink structure. + * @return string|false Date permalink structure on success, false on failure. */ public function get_date_permastruct() { if ( isset( $this->date_structure ) ) { @@ -526,7 +526,7 @@ preg_match_all( '/%.+?%/', $this->permalink_structure, $tokens ); $tok_index = 1; foreach ( (array) $tokens[0] as $token ) { - if ( '%post_id%' == $token && ( $tok_index <= 3 ) ) { + if ( '%post_id%' === $token && ( $tok_index <= 3 ) ) { $front = $front . 'date/'; break; } @@ -546,7 +546,7 @@ * * @since 1.5.0 * - * @return false|string False on failure. Year structure on success. + * @return string|false Year permalink structure on success, false on failure. */ public function get_year_permastruct() { $structure = $this->get_date_permastruct(); @@ -570,7 +570,7 @@ * * @since 1.5.0 * - * @return false|string False on failure. Year/Month structure on success. + * @return string|false Year/Month permalink structure on success, false on failure. */ public function get_month_permastruct() { $structure = $this->get_date_permastruct(); @@ -592,7 +592,7 @@ * * @since 1.5.0 * - * @return string|false False on failure. Year/Month/Day structure on success. + * @return string|false Year/Month/Day permalink structure on success, false on failure. */ public function get_day_permastruct() { return $this->get_date_permastruct(); @@ -608,7 +608,7 @@ * * @since 1.5.0 * - * @return string|false False on failure. Category permalink structure. + * @return string|false Category permalink structure on success, false on failure. */ public function get_category_permastruct() { return $this->get_extra_permastruct( 'category' ); @@ -624,7 +624,7 @@ * * @since 2.3.0 * - * @return string|false False on failure. Tag permalink structure. + * @return string|false Tag permalink structure on success, false on failure. */ public function get_tag_permastruct() { return $this->get_extra_permastruct( 'post_tag' ); @@ -636,7 +636,7 @@ * @since 2.5.0 * * @param string $name Permalink structure name. - * @return string|false False if not found. Permalink structure string. + * @return string|false Permalink structure string on success, false on failure. */ public function get_extra_permastruct( $name ) { if ( empty( $this->permalink_structure ) ) { @@ -659,7 +659,7 @@ * * @since 1.5.0 * - * @return string|false False if not found. Permalink structure string. + * @return string|false Author permalink structure on success, false on failure. */ public function get_author_permastruct() { if ( isset( $this->author_structure ) ) { @@ -685,7 +685,7 @@ * * @since 1.5.0 * - * @return string|false False if not found. Permalink structure string. + * @return string|false Search permalink structure on success, false on failure. */ public function get_search_permastruct() { if ( isset( $this->search_structure ) ) { @@ -711,7 +711,7 @@ * * @since 1.5.0 * - * @return string|false False if not found. Permalink structure string. + * @return string|false Page permalink structure on success, false on failure. */ public function get_page_permastruct() { if ( isset( $this->page_structure ) ) { @@ -737,7 +737,7 @@ * * @since 1.5.0 * - * @return string|false False if not found. Permalink structure string. + * @return string|false Feed permalink structure on success, false on failure. */ public function get_feed_permastruct() { if ( isset( $this->feed_structure ) ) { @@ -763,7 +763,7 @@ * * @since 1.5.0 * - * @return string|false False if not found. Permalink structure string. + * @return string|false Comment feed permalink structure on success, false on failure. */ public function get_comment_feed_permastruct() { if ( isset( $this->comment_feed_structure ) ) { @@ -797,7 +797,7 @@ * @param string $query String to append to the rewritten query. Must end in '='. */ public function add_rewrite_tag( $tag, $regex, $query ) { - $position = array_search( $tag, $this->rewritecode ); + $position = array_search( $tag, $this->rewritecode, true ); if ( false !== $position && null !== $position ) { $this->rewritereplace[ $position ] = $regex; $this->queryreplace[ $position ] = $query; @@ -821,7 +821,7 @@ * @param string $tag Name of the rewrite tag to remove. */ public function remove_rewrite_tag( $tag ) { - $position = array_search( $tag, $this->rewritecode ); + $position = array_search( $tag, $this->rewritecode, true ); if ( false !== $position && null !== $position ) { unset( $this->rewritecode[ $position ] ); unset( $this->rewritereplace[ $position ] ); @@ -854,7 +854,7 @@ * over and rewrite rules built for each in-turn. Default true. * @param bool $endpoints Optional. Whether endpoints should be applied to the generated rewrite rules. * Default true. - * @return array Rewrite rule list. + * @return string[] Array of rewrite rules keyed by their regex pattern. */ public function generate_rewrite_rules( $permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true ) { // Build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/? @@ -897,7 +897,7 @@ $num_tokens = count( $tokens[0] ); - $index = $this->index; //probably 'index.php' + $index = $this->index; // Probably 'index.php'. $feedindex = $index; $trackbackindex = $index; $embedindex = $index; @@ -920,7 +920,7 @@ // Get the structure, minus any cruft (stuff that isn't tags) at the front. $structure = $permalink_structure; - if ( $front != '/' ) { + if ( '/' !== $front ) { $structure = str_replace( $front, '', $structure ); } @@ -1003,7 +1003,7 @@ // Start creating the array of rewrites for this dir. $rewrite = array(); - // ...adding on /feed/ regexes => queries + // ...adding on /feed/ regexes => queries. if ( $feed ) { $rewrite = array( $feedmatch => $feedquery, @@ -1012,7 +1012,7 @@ ); } - //...and /page/xx ones + // ...and /page/xx ones. if ( $paged ) { $rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) ); } @@ -1228,7 +1228,8 @@ * @see WP_Rewrite::generate_rewrite_rules() See for long description and rest of parameters. * * @param string $permalink_structure The permalink structure to generate rules. - * @param bool $walk_dirs Optional, default is false. Whether to create list of directories to walk over. + * @param bool $walk_dirs Optional. Whether to create list of directories to walk over. + * Default false. * @return array */ public function generate_rewrite_rule( $permalink_structure, $walk_dirs = false ) { @@ -1250,7 +1251,7 @@ * * @since 1.5.0 * - * @return array An associate array of matches and queries. + * @return string[] An associative array of matches and queries. */ public function rewrite_rules() { $rewrite = array(); @@ -1259,9 +1260,12 @@ return $rewrite; } - // robots.txt -only if installed at the root + // robots.txt -- only if installed at the root. $home_path = parse_url( home_url() ); - $robots_rewrite = ( empty( $home_path['path'] ) || '/' == $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array(); + $robots_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array(); + + // favicon.ico -- only if installed at the root. + $favicon_rewrite = ( empty( $home_path['path'] ) || '/' === $home_path['path'] ) ? array( 'favicon\.ico$' => $this->index . '?favicon=1' ) : array(); // Old feed and service files. $deprecated_files = array( @@ -1287,7 +1291,7 @@ * * @since 1.5.0 * - * @param array $post_rewrite The rewrite rules for posts. + * @param string[] $post_rewrite Array of rewrite rules for posts, keyed by their regex pattern. */ $post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite ); @@ -1301,7 +1305,7 @@ * * @since 1.5.0 * - * @param array $date_rewrite The rewrite rules for date archives. + * @param string[] $date_rewrite Array of rewrite rules for date archives, keyed by their regex pattern. */ $date_rewrite = apply_filters( 'date_rewrite_rules', $date_rewrite ); @@ -1316,7 +1320,7 @@ * * @since 1.5.0 * - * @param array $root_rewrite The root-level rewrite rules. + * @param string[] $root_rewrite Array of root-level rewrite rules, keyed by their regex pattern. */ $root_rewrite = apply_filters( 'root_rewrite_rules', $root_rewrite ); @@ -1330,7 +1334,7 @@ * * @since 1.5.0 * - * @param array $comments_rewrite The rewrite rules for the site-wide comments feeds. + * @param string[] $comments_rewrite Array of rewrite rules for the site-wide comments feeds, keyed by their regex pattern. */ $comments_rewrite = apply_filters( 'comments_rewrite_rules', $comments_rewrite ); @@ -1346,7 +1350,7 @@ * * @since 1.5.0 * - * @param array $search_rewrite The rewrite rules for search queries. + * @param string[] $search_rewrite Array of rewrite rules for search queries, keyed by their regex pattern. */ $search_rewrite = apply_filters( 'search_rewrite_rules', $search_rewrite ); @@ -1361,7 +1365,7 @@ * * @since 1.5.0 * - * @param array $author_rewrite The rewrite rules for author archives. + * @param string[] $author_rewrite Array of rewrite rules for author archives, keyed by their regex pattern. */ $author_rewrite = apply_filters( 'author_rewrite_rules', $author_rewrite ); @@ -1373,7 +1377,7 @@ * * @since 1.5.0 * - * @param array $page_rewrite The rewrite rules for the "page" post type. + * @param string[] $page_rewrite Array of rewrite rules for the "page" post type, keyed by their regex pattern. */ $page_rewrite = apply_filters( 'page_rewrite_rules', $page_rewrite ); @@ -1398,20 +1402,21 @@ * * @since 3.1.0 * - * @param array $rules The rewrite rules generated for the current permastruct. + * @param string[] $rules Array of rewrite rules generated for the current permastruct, keyed by their regex pattern. */ $rules = apply_filters( "{$permastructname}_rewrite_rules", $rules ); - if ( 'post_tag' == $permastructname ) { + + if ( 'post_tag' === $permastructname ) { /** * Filters rewrite rules used specifically for Tags. * * @since 2.3.0 - * @deprecated 3.1.0 Use 'post_tag_rewrite_rules' instead + * @deprecated 3.1.0 Use {@see 'post_tag_rewrite_rules'} instead. * - * @param array $rules The rewrite rules generated for tags. + * @param string[] $rules Array of rewrite rules generated for tags, keyed by their regex pattern. */ - $rules = apply_filters( 'tag_rewrite_rules', $rules ); + $rules = apply_filters_deprecated( 'tag_rewrite_rules', array( $rules ), '3.1.0', 'post_tag_rewrite_rules' ); } $this->extra_rules_top = array_merge( $this->extra_rules_top, $rules ); @@ -1419,9 +1424,9 @@ // Put them together. if ( $this->use_verbose_page_rules ) { - $this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules ); + $this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules ); } else { - $this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules ); + $this->rules = array_merge( $this->extra_rules_top, $robots_rewrite, $favicon_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules ); } /** @@ -1438,7 +1443,7 @@ * * @since 1.5.0 * - * @param array $this->rules The compiled array of rewrite rules. + * @param string[] $rules The compiled array of rewrite rules, keyed by their regex pattern. */ $this->rules = apply_filters( 'rewrite_rules_array', $this->rules ); @@ -1455,7 +1460,7 @@ * * @since 1.5.0 * - * @return array Rewrite rules. + * @return string[] Array of rewrite rules keyed by their regex pattern. */ public function wp_rewrite_rules() { $this->rules = get_option( 'rewrite_rules' ); @@ -1556,11 +1561,11 @@ * Filters the list of rewrite rules formatted for output to an .htaccess file. * * @since 1.5.0 - * @deprecated 1.5.0 Use the mod_rewrite_rules filter instead. + * @deprecated 1.5.0 Use the {@see 'mod_rewrite_rules'} filter instead. * * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess. */ - return apply_filters( 'rewrite_rules', $rules ); + return apply_filters_deprecated( 'rewrite_rules', array( $rules ), '1.5.0', 'mod_rewrite_rules' ); } /** @@ -1644,7 +1649,7 @@ if ( $external ) { $this->add_external_rule( $regex, $query ); } else { - if ( 'bottom' == $after ) { + if ( 'bottom' === $after ) { $this->extra_rules = array_merge( $this->extra_rules, array( $regex => $query ) ); } else { $this->extra_rules_top = array_merge( $this->extra_rules_top, array( $regex => $query ) ); @@ -1672,7 +1677,7 @@ * @since 4.3.0 Added support for skipping query var registration by passing `false` to `$query_var`. * * @see add_rewrite_endpoint() for full documentation. - * @global WP $wp + * @global WP $wp Current WordPress environment instance. * * @param string $name Name of the endpoint. * @param int $places Endpoint mask describing the places the endpoint should be added. @@ -1684,7 +1689,7 @@ global $wp; // For backward compatibility, if null has explicitly been passed as `$query_var`, assume `true`. - if ( true === $query_var || null === func_get_arg( 2 ) ) { + if ( true === $query_var || null === $query_var ) { $query_var = $name; } $this->endpoints[] = array( $places, $name, $query_var ); @@ -1782,8 +1787,6 @@ * * @since 2.0.1 * - * @staticvar bool $do_hard_later - * * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard). */ public function flush_rules( $hard = true ) { @@ -1834,7 +1837,9 @@ * @since 1.5.0 */ public function init() { - $this->extra_rules = $this->non_wp_rules = $this->endpoints = array(); + $this->extra_rules = array(); + $this->non_wp_rules = array(); + $this->endpoints = array(); $this->permalink_structure = get_option( 'permalink_structure' ); $this->front = substr( $this->permalink_structure, 0, strpos( $this->permalink_structure, '%' ) ); $this->root = ''; @@ -1849,7 +1854,8 @@ unset( $this->search_structure ); unset( $this->feed_structure ); unset( $this->comment_feed_structure ); - $this->use_trailing_slashes = ( '/' == substr( $this->permalink_structure, -1, 1 ) ); + + $this->use_trailing_slashes = ( '/' === substr( $this->permalink_structure, -1, 1 ) ); // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. if ( preg_match( '/^[^%]*%(?:postname|category|tag|author)%/', $this->permalink_structure ) ) { @@ -1904,7 +1910,7 @@ * @param string $category_base Category permalink structure base. */ public function set_category_base( $category_base ) { - if ( $category_base != get_option( 'category_base' ) ) { + if ( get_option( 'category_base' ) !== $category_base ) { update_option( 'category_base', $category_base ); $this->init(); } @@ -1922,7 +1928,7 @@ * @param string $tag_base Tag permalink structure base. */ public function set_tag_base( $tag_base ) { - if ( $tag_base != get_option( 'tag_base' ) ) { + if ( get_option( 'tag_base' ) !== $tag_base ) { update_option( 'tag_base', $tag_base ); $this->init(); }