38 'parent' => 'menu_item_parent', |
38 'parent' => 'menu_item_parent', |
39 'id' => 'db_id', |
39 'id' => 'db_id', |
40 ); |
40 ); |
41 |
41 |
42 /** |
42 /** |
|
43 * The URL to the privacy policy page. |
|
44 * |
|
45 * @since 6.8.0 |
|
46 * @var string |
|
47 */ |
|
48 private $privacy_policy_url; |
|
49 |
|
50 /** |
|
51 * Constructor. |
|
52 * |
|
53 * @since 6.8.0 |
|
54 */ |
|
55 public function __construct() { |
|
56 $this->privacy_policy_url = get_privacy_policy_url(); |
|
57 } |
|
58 |
|
59 /** |
43 * Starts the list before the elements are added. |
60 * Starts the list before the elements are added. |
44 * |
61 * |
45 * @since 3.0.0 |
62 * @since 3.0.0 |
46 * |
63 * |
47 * @see Walker::start_lvl() |
64 * @see Walker::start_lvl() |
124 * |
141 * |
125 * @since 3.0.0 |
142 * @since 3.0.0 |
126 * @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added. |
143 * @since 4.4.0 The {@see 'nav_menu_item_args'} filter was added. |
127 * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id` |
144 * @since 5.9.0 Renamed `$item` to `$data_object` and `$id` to `$current_object_id` |
128 * to match parent class for PHP 8 named parameter support. |
145 * to match parent class for PHP 8 named parameter support. |
|
146 * @since 6.7.0 Removed redundant title attributes. |
129 * |
147 * |
130 * @see Walker::start_el() |
148 * @see Walker::start_el() |
131 * |
149 * |
132 * @param string $output Used to append additional content (passed by reference). |
150 * @param string $output Used to append additional content (passed by reference). |
133 * @param WP_Post $data_object Menu item data object. |
151 * @param WP_Post $data_object Menu item data object. |
210 $li_atts = apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ); |
228 $li_atts = apply_filters( 'nav_menu_item_attributes', $li_atts, $menu_item, $args, $depth ); |
211 $li_attributes = $this->build_atts( $li_atts ); |
229 $li_attributes = $this->build_atts( $li_atts ); |
212 |
230 |
213 $output .= $indent . '<li' . $li_attributes . '>'; |
231 $output .= $indent . '<li' . $li_attributes . '>'; |
214 |
232 |
|
233 /** This filter is documented in wp-includes/post-template.php */ |
|
234 $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID ); |
|
235 |
|
236 // Save filtered value before filtering again. |
|
237 $the_title_filtered = $title; |
|
238 |
|
239 /** |
|
240 * Filters a menu item's title. |
|
241 * |
|
242 * @since 4.4.0 |
|
243 * |
|
244 * @param string $title The menu item's title. |
|
245 * @param WP_Post $menu_item The current menu item object. |
|
246 * @param stdClass $args An object of wp_nav_menu() arguments. |
|
247 * @param int $depth Depth of menu item. Used for padding. |
|
248 */ |
|
249 $title = apply_filters( 'nav_menu_item_title', $title, $menu_item, $args, $depth ); |
|
250 |
215 $atts = array(); |
251 $atts = array(); |
216 $atts['title'] = ! empty( $menu_item->attr_title ) ? $menu_item->attr_title : ''; |
|
217 $atts['target'] = ! empty( $menu_item->target ) ? $menu_item->target : ''; |
252 $atts['target'] = ! empty( $menu_item->target ) ? $menu_item->target : ''; |
218 if ( '_blank' === $menu_item->target && empty( $menu_item->xfn ) ) { |
253 $atts['rel'] = ! empty( $menu_item->xfn ) ? $menu_item->xfn : ''; |
219 $atts['rel'] = 'noopener'; |
|
220 } else { |
|
221 $atts['rel'] = $menu_item->xfn; |
|
222 } |
|
223 |
254 |
224 if ( ! empty( $menu_item->url ) ) { |
255 if ( ! empty( $menu_item->url ) ) { |
225 if ( get_privacy_policy_url() === $menu_item->url ) { |
256 if ( $this->privacy_policy_url === $menu_item->url ) { |
226 $atts['rel'] = empty( $atts['rel'] ) ? 'privacy-policy' : $atts['rel'] . ' privacy-policy'; |
257 $atts['rel'] = empty( $atts['rel'] ) ? 'privacy-policy' : $atts['rel'] . ' privacy-policy'; |
227 } |
258 } |
228 |
259 |
229 $atts['href'] = $menu_item->url; |
260 $atts['href'] = $menu_item->url; |
230 } else { |
261 } else { |
231 $atts['href'] = ''; |
262 $atts['href'] = ''; |
232 } |
263 } |
233 |
264 |
234 $atts['aria-current'] = $menu_item->current ? 'page' : ''; |
265 $atts['aria-current'] = $menu_item->current ? 'page' : ''; |
|
266 |
|
267 // Add title attribute only if it does not match the link text (before or after filtering). |
|
268 if ( ! empty( $menu_item->attr_title ) |
|
269 && trim( strtolower( $menu_item->attr_title ) ) !== trim( strtolower( $menu_item->title ) ) |
|
270 && trim( strtolower( $menu_item->attr_title ) ) !== trim( strtolower( $the_title_filtered ) ) |
|
271 && trim( strtolower( $menu_item->attr_title ) ) !== trim( strtolower( $title ) ) |
|
272 ) { |
|
273 $atts['title'] = $menu_item->attr_title; |
|
274 } else { |
|
275 $atts['title'] = ''; |
|
276 } |
235 |
277 |
236 /** |
278 /** |
237 * Filters the HTML attributes applied to a menu item's anchor element. |
279 * Filters the HTML attributes applied to a menu item's anchor element. |
238 * |
280 * |
239 * @since 3.6.0 |
281 * @since 3.6.0 |
253 * @param int $depth Depth of menu item. Used for padding. |
295 * @param int $depth Depth of menu item. Used for padding. |
254 */ |
296 */ |
255 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $menu_item, $args, $depth ); |
297 $atts = apply_filters( 'nav_menu_link_attributes', $atts, $menu_item, $args, $depth ); |
256 $attributes = $this->build_atts( $atts ); |
298 $attributes = $this->build_atts( $atts ); |
257 |
299 |
258 /** This filter is documented in wp-includes/post-template.php */ |
|
259 $title = apply_filters( 'the_title', $menu_item->title, $menu_item->ID ); |
|
260 |
|
261 /** |
|
262 * Filters a menu item's title. |
|
263 * |
|
264 * @since 4.4.0 |
|
265 * |
|
266 * @param string $title The menu item's title. |
|
267 * @param WP_Post $menu_item The current menu item object. |
|
268 * @param stdClass $args An object of wp_nav_menu() arguments. |
|
269 * @param int $depth Depth of menu item. Used for padding. |
|
270 */ |
|
271 $title = apply_filters( 'nav_menu_item_title', $title, $menu_item, $args, $depth ); |
|
272 |
|
273 $item_output = $args->before; |
300 $item_output = $args->before; |
274 $item_output .= '<a' . $attributes . '>'; |
301 $item_output .= '<a' . $attributes . '>'; |
275 $item_output .= $args->link_before . $title . $args->link_after; |
302 $item_output .= $args->link_before . $title . $args->link_after; |
276 $item_output .= '</a>'; |
303 $item_output .= '</a>'; |
277 $item_output .= $args->after; |
304 $item_output .= $args->after; |