wppaste
WordPress

Walker_Nav_Menu

Since
3.0.0
Source
wp-includes/class-walker-nav-menu.php:17
Core class used to implement an HTML list of nav menu items.

Compatibility

WordPress
since 3.0.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 10

Every hook that fires from inside Walker_Nav_Menu, in the order it appears in the class, grouped by the method that fires it.

Properties · 3

$tree_typestringpublic
What the class handles.
$db_fieldsstring[]public
Database fields to use.
$privacy_policy_urlstringprivate
The URL to the privacy policy page.

Methods · 6

Source code

class Walker_Nav_Menu extends Walker {	/**	 * What the class handles.	 *	 * @since 3.0.0	 * @var string	 *	 * @see Walker::$tree_type	 */	public $tree_type = array( 'post_type', 'taxonomy', 'custom' ); 	/**	 * Database fields to use.	 *	 * @since 3.0.0	 * @todo Decouple this.	 * @var string[]	 *	 * @see Walker::$db_fields	 */	public $db_fields = array(		'parent' => 'menu_item_parent',		'id'     => 'db_id',	); 	/**	 * The URL to the privacy policy page.	 *	 * @since 6.8.0	 * @var string	 */	private $privacy_policy_url; 	/**	 * Constructor.	 *	 * @since 6.8.0	 */	public function __construct() {		$this->privacy_policy_url = get_privacy_policy_url();	} 	/**	 * Starts the list before the elements are added.	 *	 * @since 3.0.0	 *	 * @see Walker::start_lvl()	 *	 * @param string   $output Used to append additional content (passed by reference).	 * @param int      $depth  Depth of menu item. Used for padding.	 * @param stdClass $args   An object of wp_nav_menu() arguments.	 */	public function start_lvl( &$output, $depth = 0, $args = null ) {		if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {			$t = '';			$n = '';		} else {			$t = "\t";			$n = "\n";		}		$indent = str_repeat( $t, $depth ); 		// Default class.		$classes = array( 'sub-menu' ); 		/**		 * Filters the CSS class(es) applied to a menu list element.		 *		 * @since 4.8.0		 *		 * @param string[] $classes Array of the CSS classes that are applied to the menu `<ul>` element.		 * @param stdClass $args    An object of `wp_nav_menu()` arguments.		 * @param int      $depth   Depth of menu item. Used for padding.		 */		$class_names = implode( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) ); 		$atts          = array();		$atts['class'] = ! empty( $class_names ) ? $class_names : '';

Changelog

Introduced in 3.0.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.8.8
Method __construct() added.verified against source
3.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-walker-nav-menu.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.