Make WordPress Core

Ticket #62818: 62818.patch

File 62818.patch, 5.0 KB (added by arzola, 3 months ago)
  • src/wp-includes/class-walker-nav-menu.php

    diff --git a/src/wp-includes/class-walker-nav-menu.php b/src/wp-includes/class-walker-nav-menu.php
    index 2b06d54b44..612020f74c 100644
    a b class Walker_Nav_Menu extends Walker { 
    3939                'id'     => 'db_id',
    4040        );
    4141
     42        /**
     43         * The URL to the privacy policy page.
     44         *
     45         * @since 6.2.0
     46         * @var string
     47         */
     48        private $privacy_policy_url = null;
     49
     50        /**
     51         * Constructor.
     52         */
     53        public function __construct() {
     54                $this->privacy_policy_url = get_privacy_policy_url();
     55        }
     56
    4257        /**
    4358         * Starts the list before the elements are added.
    4459         *
    class Walker_Nav_Menu extends Walker { 
    236251                $atts['rel']    = ! empty( $menu_item->xfn ) ? $menu_item->xfn : '';
    237252
    238253                if ( ! empty( $menu_item->url ) ) {
    239                         if ( get_privacy_policy_url() === $menu_item->url ) {
     254                        if ( $this->privacy_policy_url === $menu_item->url ) {
    240255                                $atts['rel'] = empty( $atts['rel'] ) ? 'privacy-policy' : $atts['rel'] . ' privacy-policy';
    241256                        }
    242257
  • tests/phpunit/tests/menu/walker-nav-menu.php

    diff --git a/tests/phpunit/tests/menu/walker-nav-menu.php b/tests/phpunit/tests/menu/walker-nav-menu.php
    index 053ab71548..3ff725cbb0 100644
    a b class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { 
    1717         */
    1818        private $orig_wp_nav_menu_max_depth;
    1919
     20        /**
     21         * The ID of the privacy policy page.
     22         *
     23         * @var int
     24         */
     25        private $privacy_policy_id;
     26
    2027        /**
    2128         * Setup.
    2229         */
    class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { 
    2734
    2835                /** Walker_Nav_Menu class */
    2936                require_once ABSPATH . 'wp-includes/class-walker-nav-menu.php';
     37
     38                $post_id = self::factory()->post->create(
     39                        array(
     40                                'post_type'   => 'page',
     41                                'post_title'  => 'Test Privacy Policy',
     42                                'post_status' => 'publish',
     43                        )
     44                );
     45
     46                // Set the privacy policy page.
     47                update_option( 'wp_page_for_privacy_policy', $post_id );
     48                $this->privacy_policy_id = (int) get_option( 'wp_page_for_privacy_policy' );
     49
    3050                $this->walker = new Walker_Nav_Menu();
    3151
    3252                $this->orig_wp_nav_menu_max_depth = $_wp_nav_menu_max_depth;
    class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { 
    3959                global $_wp_nav_menu_max_depth;
    4060
    4161                $_wp_nav_menu_max_depth = $this->orig_wp_nav_menu_max_depth;
     62                delete_option( 'wp_page_for_privacy_policy' );
    4263                parent::tear_down();
    4364        }
    4465
    class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { 
    136157         * @param string $target   Optional. The target value. Default empty string.
    137158         */
    138159        public function test_walker_nav_menu_start_el_should_add_rel_privacy_policy_to_privacy_policy_url( $expected, $xfn = '', $target = '' ) {
    139                 $post_id = self::factory()->post->create(
    140                         array(
    141                                 'post_type'   => 'page',
    142                                 'post_title'  => 'Test Privacy Policy',
    143                                 'post_status' => 'publish',
    144                         )
    145                 );
    146 
    147                 // Set the privacy policy page.
    148                 update_option( 'wp_page_for_privacy_policy', $post_id );
    149                 $privacy_policy_id = (int) get_option( 'wp_page_for_privacy_policy' );
    150160
    151161                $output = '';
    152162
    153163                $item = array(
    154                         'ID'        => $privacy_policy_id,
    155                         'object_id' => $privacy_policy_id,
     164                        'ID'        => $this->privacy_policy_id,
     165                        'object_id' => $this->privacy_policy_id,
    156166                        'title'     => 'Privacy Policy',
    157167                        'target'    => $target,
    158168                        'xfn'       => $xfn,
    class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { 
    251261         * @covers Walker_Nav_Menu::start_el
    252262         */
    253263        public function test_walker_nav_menu_start_el_should_not_add_rel_privacy_policy_when_no_url_is_passed() {
    254                 $post_id = self::factory()->post->create(
    255                         array(
    256                                 'post_type'   => 'page',
    257                                 'post_title'  => 'Test Privacy Policy',
    258                                 'post_status' => 'publish',
    259                         )
    260                 );
    261 
    262                 // Set the privacy policy page.
    263                 update_option( 'wp_page_for_privacy_policy', $post_id );
    264                 $privacy_policy_id = (int) get_option( 'wp_page_for_privacy_policy' );
    265264
    266265                $output = '';
    267266
    268267                $item = array(
    269                         'ID'        => $privacy_policy_id,
    270                         'object_id' => $privacy_policy_id,
     268                        'ID'        => $this->privacy_policy_id,
     269                        'object_id' => $this->privacy_policy_id,
    271270                        'title'     => 'Privacy Policy',
    272271                        'target'    => '',
    273272                        'xfn'       => '',
    class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { 
    296295         * @covers Walker_Nav_Menu::start_el
    297296         */
    298297        public function test_walker_nav_menu_start_el_should_add_rel_privacy_policy_when_id_does_not_match_but_url_does() {
    299                 $post_id = self::factory()->post->create(
    300                         array(
    301                                 'post_type'   => 'page',
    302                                 'post_title'  => 'Test Privacy Policy',
    303                                 'post_status' => 'publish',
    304                         )
    305                 );
    306 
    307                 // Set the privacy policy page.
    308                 update_option( 'wp_page_for_privacy_policy', $post_id );
    309                 $privacy_policy_id = (int) get_option( 'wp_page_for_privacy_policy' );
    310298
    311299                $output = '';
    312300
    313301                // Ensure the ID does not match the privacy policy.
    314                 $not_privacy_policy_id = $privacy_policy_id - 1;
     302                $not_privacy_policy_id = $this->privacy_policy_id - 1;
    315303
    316304                $item = array(
    317305                        'ID'        => $not_privacy_policy_id,