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 { |
| 39 | 39 | 'id' => 'db_id', |
| 40 | 40 | ); |
| 41 | 41 | |
| | 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 | |
| 42 | 57 | /** |
| 43 | 58 | * Starts the list before the elements are added. |
| 44 | 59 | * |
| … |
… |
class Walker_Nav_Menu extends Walker { |
| 236 | 251 | $atts['rel'] = ! empty( $menu_item->xfn ) ? $menu_item->xfn : ''; |
| 237 | 252 | |
| 238 | 253 | if ( ! empty( $menu_item->url ) ) { |
| 239 | | if ( get_privacy_policy_url() === $menu_item->url ) { |
| | 254 | if ( $this->privacy_policy_url === $menu_item->url ) { |
| 240 | 255 | $atts['rel'] = empty( $atts['rel'] ) ? 'privacy-policy' : $atts['rel'] . ' privacy-policy'; |
| 241 | 256 | } |
| 242 | 257 | |
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 { |
| 17 | 17 | */ |
| 18 | 18 | private $orig_wp_nav_menu_max_depth; |
| 19 | 19 | |
| | 20 | /** |
| | 21 | * The ID of the privacy policy page. |
| | 22 | * |
| | 23 | * @var int |
| | 24 | */ |
| | 25 | private $privacy_policy_id; |
| | 26 | |
| 20 | 27 | /** |
| 21 | 28 | * Setup. |
| 22 | 29 | */ |
| … |
… |
class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { |
| 27 | 34 | |
| 28 | 35 | /** Walker_Nav_Menu class */ |
| 29 | 36 | 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 | |
| 30 | 50 | $this->walker = new Walker_Nav_Menu(); |
| 31 | 51 | |
| 32 | 52 | $this->orig_wp_nav_menu_max_depth = $_wp_nav_menu_max_depth; |
| … |
… |
class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { |
| 39 | 59 | global $_wp_nav_menu_max_depth; |
| 40 | 60 | |
| 41 | 61 | $_wp_nav_menu_max_depth = $this->orig_wp_nav_menu_max_depth; |
| | 62 | delete_option( 'wp_page_for_privacy_policy' ); |
| 42 | 63 | parent::tear_down(); |
| 43 | 64 | } |
| 44 | 65 | |
| … |
… |
class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { |
| 136 | 157 | * @param string $target Optional. The target value. Default empty string. |
| 137 | 158 | */ |
| 138 | 159 | 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' ); |
| 150 | 160 | |
| 151 | 161 | $output = ''; |
| 152 | 162 | |
| 153 | 163 | $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, |
| 156 | 166 | 'title' => 'Privacy Policy', |
| 157 | 167 | 'target' => $target, |
| 158 | 168 | 'xfn' => $xfn, |
| … |
… |
class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { |
| 251 | 261 | * @covers Walker_Nav_Menu::start_el |
| 252 | 262 | */ |
| 253 | 263 | 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' ); |
| 265 | 264 | |
| 266 | 265 | $output = ''; |
| 267 | 266 | |
| 268 | 267 | $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, |
| 271 | 270 | 'title' => 'Privacy Policy', |
| 272 | 271 | 'target' => '', |
| 273 | 272 | 'xfn' => '', |
| … |
… |
class Tests_Menu_Walker_Nav_Menu extends WP_UnitTestCase { |
| 296 | 295 | * @covers Walker_Nav_Menu::start_el |
| 297 | 296 | */ |
| 298 | 297 | 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' ); |
| 310 | 298 | |
| 311 | 299 | $output = ''; |
| 312 | 300 | |
| 313 | 301 | // 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; |
| 315 | 303 | |
| 316 | 304 | $item = array( |
| 317 | 305 | 'ID' => $not_privacy_policy_id, |