WordPress.org

Make WordPress Core

Ticket #47398: 47398.6.diff

File 47398.6.diff, 11.4 KB (added by SergeyBiryukov, 2 years ago)
  • src/wp-includes/canonical.php

     
    1919 *
    2020 * Prevents redirection for feeds, trackbacks, searches, and
    2121 * admin URLs. Does not redirect on non-pretty-permalink-supporting IIS 7+,
    22  * page/post previews, WP admin, Trackbacks, robots.txt, searches, or on POST
    23  * requests.
     22 * page/post previews, WP admin, Trackbacks, robots.txt, favicon.ico, searches,
     23 * or on POST requests.
    2424 *
    2525 * Will also attempt to find the correct link when a user enters a URL that does
    2626 * not exist based on exact WordPress query. Will instead try to parse the URL
     
    5656                }
    5757        }
    5858
    59         if ( is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || ( $is_IIS && ! iis7_supports_permalinks() ) ) {
     59        if ( is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || is_favicon() || ( $is_IIS && ! iis7_supports_permalinks() ) ) {
    6060                return;
    6161        }
    6262
  • src/wp-includes/class-wp-query.php

     
    391391        public $is_robots = false;
    392392
    393393        /**
     394         * Signifies whether the current query is for the favicon.ico file.
     395         *
     396         * @since 5.4.0
     397         * @var bool
     398         */
     399        public $is_favicon = false;
     400
     401        /**
    394402         * Signifies whether the current query is for the page_for_posts page.
    395403         *
    396404         * Basically, the homepage if the option isn't set for the static homepage.
     
    478486                $this->is_attachment        = false;
    479487                $this->is_singular          = false;
    480488                $this->is_robots            = false;
     489                $this->is_favicon           = false;
    481490                $this->is_posts_page        = false;
    482491                $this->is_post_type_archive = false;
    483492        }
     
    744753
    745754                if ( ! empty( $qv['robots'] ) ) {
    746755                        $this->is_robots = true;
     756                } elseif ( ! empty( $qv['favicon'] ) ) {
     757                        $this->is_favicon = true;
    747758                }
    748759
    749760                if ( ! is_scalar( $qv['p'] ) || $qv['p'] < 0 ) {
     
    957968                        $this->is_comment_feed = true;
    958969                }
    959970
    960                 if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots ) ) {
     971                if ( ! ( $this->is_singular || $this->is_archive || $this->is_search || $this->is_feed
     972                                || ( defined( 'REST_REQUEST' ) && REST_REQUEST )
     973                                || $this->is_trackback || $this->is_404 || $this->is_admin || $this->is_robots || $this->is_favicon ) ) {
    961974                        $this->is_home = true;
    962975                }
    963976
     
    40074020        }
    40084021
    40094022        /**
    4010          * Is the query for the robots file?
     4023         * Is the query for the robots.txt file?
    40114024         *
    40124025         * @since 3.1.0
    40134026         *
     
    40184031        }
    40194032
    40204033        /**
     4034         * Is the query for the favicon.ico file?
     4035         *
     4036         * @since 5.4.0
     4037         *
     4038         * @return bool
     4039         */
     4040        public function is_favicon() {
     4041                return (bool) $this->is_favicon;
     4042        }
     4043
     4044        /**
    40214045         * Is the query for a search?
    40224046         *
    40234047         * @since 3.1.0
  • src/wp-includes/class-wp-rewrite.php

     
    12591259                        return $rewrite;
    12601260                }
    12611261
    1262                 // robots.txt -only if installed at the root
     1262                // robots.txt -- only if installed at the root
    12631263                $home_path      = parse_url( home_url() );
    12641264                $robots_rewrite = ( empty( $home_path['path'] ) || '/' == $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array();
    12651265
     1266                // favicon.ico -- only if installed at the root
     1267                $favicon_rewrite = ( empty( $home_path['path'] ) || '/' == $home_path['path'] ) ? array( 'favicon\.ico$' => $this->index . '?favicon=1' ) : array();
     1268
    12661269                // Old feed and service files.
    12671270                $deprecated_files = array(
    12681271                        '.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old',
     
    14191422
    14201423                // Put them together.
    14211424                if ( $this->use_verbose_page_rules ) {
    1422                         $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 );
     1425                        $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 );
    14231426                } else {
    1424                         $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 );
     1427                        $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 );
    14251428                }
    14261429
    14271430                /**
  • src/wp-includes/class-wp.php

     
    1414         * @since 2.0.0
    1515         * @var string[]
    1616         */
    17         public $public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );
     17        public $public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'favicon', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );
    1818
    1919        /**
    2020         * Private query variables.
     
    659659                        return;
    660660                }
    661661
    662                 // Never 404 for the admin, robots, or if we found posts.
    663                 if ( is_admin() || is_robots() || $wp_query->posts ) {
     662                // Never 404 for the admin, robots, favicon, or if we found posts.
     663                if ( is_admin() || is_robots() || is_favicon() || $wp_query->posts ) {
    664664
    665665                        $success = true;
    666666                        if ( is_singular() ) {
  • src/wp-includes/default-filters.php

     
    338338add_action( 'do_feed_atom', 'do_feed_atom', 10, 1 );
    339339add_action( 'do_pings', 'do_all_pings', 10, 0 );
    340340add_action( 'do_robots', 'do_robots' );
     341add_action( 'do_favicon', 'do_favicon' );
    341342add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 3 );
    342343add_action( 'sanitize_comment_cookies', 'sanitize_comment_cookies' );
    343344add_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  • src/wp-includes/functions.php

     
    16371637}
    16381638
    16391639/**
     1640 * Display the favicon.ico file content.
     1641 *
     1642 * @since 5.4.0
     1643 */
     1644function do_favicon() {
     1645        /**
     1646         * Fires when serving the favicon.ico file.
     1647         *
     1648         * @since 5.4.0
     1649         */
     1650        do_action( 'do_faviconico' );
     1651
     1652        wp_redirect( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) );
     1653        exit;
     1654}
     1655
     1656/**
    16401657 * Determines whether WordPress is already installed.
    16411658 *
    16421659 * The cache will be checked first. If you have a cache plugin, which saves
  • src/wp-includes/load.php

     
    160160 * Instead, send the headers for a zero-length favicon and bail.
    161161 *
    162162 * @since 3.0.0
     163 * @deprecated 5.4.0 Deprecated in favor of do_favicon().
    163164 */
    164165function wp_favicon_request() {
    165166        if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) {
  • src/wp-includes/query.php

     
    623623}
    624624
    625625/**
    626  * Is the query for the robots file?
     626 * Is the query for the robots.txt file?
    627627 *
    628628 * @since 2.1.0
    629629 *
     
    643643}
    644644
    645645/**
     646 * Is the query for the favicon.ico file?
     647 *
     648 * @since 5.4.0
     649 *
     650 * @global WP_Query $wp_query WordPress Query object.
     651 *
     652 * @return bool
     653 */
     654function is_favicon() {
     655        global $wp_query;
     656
     657        if ( ! isset( $wp_query ) ) {
     658                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
     659                return false;
     660        }
     661
     662        return $wp_query->is_favicon();
     663}
     664
     665/**
    646666 * Determines whether the query is for a search.
    647667 *
    648668 * For more information on this and similar theme functions, check out
  • src/wp-includes/template-loader.php

     
    3636         */
    3737        do_action( 'do_robots' );
    3838        return;
     39} elseif ( is_favicon() ) {
     40        /**
     41         * Fired when the template loader determines a favicon.ico request.
     42         *
     43         * @since 5.4.0
     44         */
     45        do_action( 'do_favicon' );
     46        return;
    3947} elseif ( is_feed() ) {
    4048        do_feed();
    4149        return;
  • src/wp-includes/version.php

     
    2020 *
    2121 * @global int $wp_db_version
    2222 */
    23 $wp_db_version = 45805;
     23$wp_db_version = 47018;
    2424
    2525/**
    2626 * Holds the TinyMCE version
  • src/wp-settings.php

     
    6363// Standardize $_SERVER variables across setups.
    6464wp_fix_server_vars();
    6565
    66 // Check if we have received a request due to missing favicon.ico
    67 wp_favicon_request();
    68 
    6966// Check if we're in maintenance mode.
    7067wp_maintenance();
    7168
  • tests/phpunit/includes/abstract-testcase.php

     
    962962                        'is_posts_page',
    963963                        'is_preview',
    964964                        'is_robots',
     965                        'is_favicon',
    965966                        'is_search',
    966967                        'is_single',
    967968                        'is_singular',
  • tests/phpunit/tests/query/vars.php

     
    6060                                'subpost_id',
    6161                                'preview',
    6262                                'robots',
     63                                'favicon',
    6364                                'taxonomy',
    6465                                'term',
    6566                                'cpage',