wppaste
WordPress

WP_Nav_Menu_Widget

Since
3.0.0
Source
wp-includes/widgets/class-wp-nav-menu-widget.php:17
Core class used to implement the Navigation Menu widget.

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 · 3

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

Methods · 4

  • __construct()Sets up a new Navigation Menu widget instance.
  • widget()Outputs the content for the current Navigation Menu widget instance.
  • update()Handles updating settings for the current Navigation Menu widget instance.
  • form()Outputs the settings form for the Navigation Menu widget.

Source code

class WP_Nav_Menu_Widget extends WP_Widget { 	/**	 * Sets up a new Navigation Menu widget instance.	 *	 * @since 3.0.0	 */	public function __construct() {		$widget_ops = array(			'description'                 => __( 'Add a navigation menu to your sidebar.' ),			'customize_selective_refresh' => true,			'show_instance_in_rest'       => true,		);		parent::__construct( 'nav_menu', __( 'Navigation Menu' ), $widget_ops );	} 	/**	 * Outputs the content for the current Navigation Menu widget instance.	 *	 * @since 3.0.0	 *	 * @param array $args     Display arguments including 'before_title', 'after_title',	 *                        'before_widget', and 'after_widget'.	 * @param array $instance Settings for the current Navigation Menu widget instance.	 */	public function widget( $args, $instance ) {		// Get menu.		$nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; 		if ( ! $nav_menu ) {			return;		} 		$default_title = __( 'Menu' );		$title         = ! empty( $instance['title'] ) ? $instance['title'] : ''; 		/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 		echo $args['before_widget']; 		if ( $title ) {			echo $args['before_title'] . $title . $args['after_title'];		} 		$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; 		/**		 * Filters the HTML format of widgets with navigation links.		 *		 * @since 5.5.0		 *		 * @param string $format The type of markup to use in widgets with navigation links.		 *                       Accepts 'html5', 'xhtml'.		 */		$format = apply_filters( 'navigation_widgets_format', $format ); 		if ( 'html5' === $format ) {			// The title may be filtered: Strip out HTML and make sure the aria-label is never empty.			$title      = trim( strip_tags( $title ) );			$aria_label = $title ? $title : $default_title; 			$nav_menu_args = array(				'fallback_cb'          => '',				'menu'                 => $nav_menu,				'container'            => 'nav',				'container_aria_label' => $aria_label,				'items_wrap'           => '<ul id="%1$s" class="%2$s">%3$s</ul>',			);		} else {			$nav_menu_args = array(				'fallback_cb' => '',				'menu'        => $nav_menu,			);		} 		/**		 * Filters the arguments for the Navigation Menu widget.		 *		 * @since 4.2.0

Changelog

Introduced in 3.0.0. Unchanged from 6.7.7 through 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.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/widgets/class-wp-nav-menu-widget.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.