defaults = array( 'title' => esc_attr__( 'Navigation', 'essential-widgets' ), 'menu' => '', 'container' => 'div', 'container_id' => '', 'container_class' => '', 'menu_id' => '', 'menu_class' => 'nav-menu', 'depth' => 0, 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'fallback_cb' => 'wp_page_menu', ); $widget_ops = array( 'classname' => 'essential-widgets ew-menus ewmenus widget_nav_menu', 'description' => esc_html__( 'Displays a list of menus.', 'essential-widgets' ), ); $control_ops = array( 'id_base' => 'ew-menus', ); parent::__construct( 'ew-menus', // Base ID esc_html__( 'EW: Menus', 'essential-widgets' ), // Name $widget_ops, $control_ops ); } /** * Displays the widget control options in the Widgets admin screen. * * @since 1.0.0 * @access public * @param array $instance * @param void */ public function form( $instance ) { // Merge the user-selected arguments with the defaults. $instance = wp_parse_args( (array) $instance, $this->defaults ); $container = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core WordPress hook, not plugin-defined. ?>

 
defaults ); // Escape widget wrapper attributes. echo wp_kses_post( $args['before_widget'] ); // If a title was input by the user, display it safely. if ( ! empty( $instance['title'] ) ) { echo wp_kses_post( $args['before_title'] ); // Apply filters to title, then escape it for output $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); echo esc_html( $title ); echo wp_kses_post( $args['after_title'] ); } // Output the main content of the widget (shortcode output) echo wp_kses_post( $this->shortcode( $instance ) ); // Close the widget wrapper safely. echo wp_kses_post( $args['after_widget'] ); } public function shortcode( $atts ) { // Overwrite the $echo argument and set it to false. $atts['echo'] = false; $ew_menu = ''; // Only show this title in block element and not on widget. if ( isset( $atts['is_block'] ) && true === $atts['is_block'] && !empty( $atts['title'] ) ) { $ew_menu .= '

' . esc_html( $atts['title'] ) . '

'; } // Output the nav menu. $ew_menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_nav_menu( $atts ) ); return $ew_menu; } } endif; if ( ! function_exists( 'ew_menu_register' ) ) : /** * Intiate Menu_Widget Class. * * @since 1.0.0 */ function ew_menu_register() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- ew_ is this plugin's abbreviated prefix. register_widget( 'EW_Menus' ); } add_action( 'widgets_init', 'ew_menu_register' ); endif;