'widget_mfn_menu', 'description' => __( 'Use this widget on pages to display aside menu with children or siblings of the current page', 'mfn-opts' ) ); parent::__construct( 'widget_mfn_menu', __( 'Muffin Menu', 'mfn-opts' ), $widget_ops ); $this->alt_option_name = 'widget_mfn_menu'; } /* --------------------------------------------------------------------------- * Outputs the HTML for this widget. * --------------------------------------------------------------------------- */ function widget( $args, $instance ) { if ( ! isset( $args['widget_id'] ) ) $args['widget_id'] = null; extract( $args, EXTR_SKIP ); $title = ""; if( $instance['use_page_title'] ){ $title = wp_title( '', false ); } elseif( $instance['title'] ) { $title = $instance['title']; } $title = apply_filters( 'widget_title', $title, $instance, $this->id_base); echo $before_widget; if( $title ) echo $before_title . $title . $after_title; if( ! $instance['nav_menu'] ){ // Pages Menu ------------------------------------------- $parentID = false; if( $instance['use_page_sibling']==1 ){ // sibling ------------------------------- $aPost = get_post( get_the_ID() ); if( is_array($aPost->ancestors) && key_exists(0, $aPost->ancestors) ) $parentID = $aPost->ancestors[0]; } else { // children ------------------------------ $parentID = get_the_ID(); } $aPages_attr = array( 'title_li' => '', 'depth' => $instance['depth'] ? intval($instance['depth']) : 1, 'child_of' => $parentID, 'link_before' => '', 'echo' => 0, ); $aPages = wp_list_pages( $aPages_attr ); // if there is no children -------------------- if( ( ! $aPages ) && ( $instance['use_page_sibling'] == 2 ) ){ $aPost = get_post( get_the_ID() ); $parentID = false; if( is_array($aPost->ancestors) && key_exists(0, $aPost->ancestors) ) $parentID = $aPost->ancestors[0]; $aPages_attr['child_of'] = $parentID; $aPages = wp_list_pages( $aPages_attr ); } // echo --------------------------------------- if( $aPages ){ echo '
'; } } else { // Custom Menu ------------------------------------------- $submenu = isset( $instance['submenus'] ) ? $instance['submenus'] : 'show'; $args = array( 'menu_class' => 'menu submenus-'. $submenu, 'menu' => $instance['nav_menu'], 'depth' => $instance['depth'] ? intval($instance['depth']) : 1, ); wp_nav_menu( $args ); } echo $after_widget; } /* --------------------------------------------------------------------------- * Deals with the settings when they are saved by the admin. * --------------------------------------------------------------------------- */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['nav_menu'] = (int) $new_instance['nav_menu']; $instance['depth'] = (int) $new_instance['depth']; $instance['submenus'] = strip_tags( $new_instance['submenus'] ); $instance['use_page_title'] = (int) $new_instance['use_page_title']; $instance['use_page_sibling'] = (int) $new_instance['use_page_sibling']; return $instance; } /* --------------------------------------------------------------------------- * Displays the form for this widget on the Widgets page of the WP Admin area. * --------------------------------------------------------------------------- */ function form( $instance ) { $title = isset( $instance['title']) ? esc_attr( $instance['title'] ) : ''; $nav_menu = isset( $instance['nav_menu'] ) ? absint( $instance['nav_menu'] ) : 0; $depth = isset( $instance['depth'] ) ? absint( $instance['depth'] ) : 1; $submenus = isset( $instance['submenus'] ) ? esc_attr( $instance['submenus'] ) : ''; $use_page_title = isset( $instance['use_page_title'] ) ? absint( $instance['use_page_title'] ) : 0; $use_page_sibling = isset( $instance['use_page_sibling'] ) ? absint( $instance['use_page_sibling'] ) : 2; // Get menus $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) ); ?>
" />
" />
" />
" />