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' ) ); ?>

 
defaults ); // Output the sidebar's $before_widget wrapper. echo $args['before_widget']; // If a title was input by the user, display it. if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; } echo $this->shortcode( $instance ); // Close the sidebar's widget wrapper. echo $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 .= '

' . $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() { register_widget( 'EW_Menus' ); } add_action( 'widgets_init', 'ew_menu_register' ); endif;