false, 'include_parent' => false, 'include_childless_parent' => false, 'order_by' => 'menu_order', 'css' => false, 'exclude' => false, 'legacy_mode' => false, 'display_all' => false, 'levels' => 1 ); /** * Build the widget like a BOSS * * @since 4.5.13 * */ function __construct() { /* Widget settings. */ $widget_ops = array( 'classname' => 'advanced-sidebar-menu', 'description' => 'Creates a menu of all the pages using the child/parent relationship' ); $control_ops = array( 'width' => 290 ); /* Create the widget. */ $this->WP_Widget( 'advanced_sidebar_menu', 'Advanced Sidebar Pages Menu', $widget_ops, $control_ops); } /** * Output a simple widget Form * Not of ton of options here but who need them * Most of the magic happens automatically * * @filters do_action('advanced_sidebar_menu_page_widget_form', $instance, $this->get_field_name('parent_only'), $this->get_field_id('parent_only')); * * @since 8.1.13 */ function form( $instance ) { $instance = wp_parse_args($instance, $this->defaults); ?>
Title
Include Parent Page: />
Include Parent Even With No Children: />
Order By:
Use this Plugin's Styling: />
Pages to Exclude, Comma Separated:
Legacy Mode: (use pre 4.0 structure and css) />
Always Display Child Pages: />
'; do_action('advanced_sidebar_menu_page_widget_form', $instance, $this->get_field_name('parent_only'), $this->get_field_id('parent_only') ); } /** * Handles the saving of the widget * * @filters apply_filters('advanced_sidebar_menu_page_widget_update', $newInstance, $oldInstance ); * * @since 4.26.13 */ function update( $newInstance, $oldInstance ) { $newInstance['exclude'] = strip_tags($newInstance['exclude']); $newInstance = apply_filters('advanced_sidebar_menu_page_widget_update', $newInstance, $oldInstance ); return $newInstance; } #--------------------------------------------------------------------------------------------------------------------------- /** * Outputs the page list * @see WP_Widget::widget() * * @uses for custom post types send the type to the filter titled 'advanced_sidebar_menu_post_type' * @uses change the top parent manually with the filter 'advanced_sidebar_menu_top_parent' * @uses change the order of the 2nd level pages with 'advanced_sidebar_menu_order_by' filter * * @filter apply_filters('advanced_sidebar_menu_page_widget_output',$content, $args, $instance ); * apply_filters('advanced_sidebar_menu_order_by', 'menu_order', $post, $args, $instance ); * apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post, $args, $instance ); * apply_filters('advanced_sidebar_menu_post_type', 'page', $args, $instance ); * * * @since 9.24.13 * * @see Geansai - pointed out a notice level error. Thanks Geansai!! */ function widget($args, $instance) { global $wpdb, $post, $table_prefix; $asm = new advancedSidebarMenu(); $asm->instance = $instance; $asm->args = $args; //The excluded pages $exclude = apply_filters( 'advanced_sidebar_menu_excluded_pages', explode(',', $instance['exclude']), $post, $args, $instance, $asm ); $asm->exclude = $exclude; extract($args); //Filter this one with a 'single' for a custom post type will default to working for pages only $post_type = apply_filters('advanced_sidebar_menu_post_type', 'page', $args, $instance, $asm ); $asm->post_type = $post_type; //Add a has_children class to appropriate pages add_filter('page_css_class', array( $asm, 'hasChildrenClass'), 2, 2 ); //Add the default classes to pages from a custom post type if( $asm->post_type != 'page' ){ add_filter('page_css_class', array( $asm, 'custom_post_type_css'), 2, 4 ); } $proper_single = !(is_single() || is_page() ) || (get_post_type() != $post_type); //Filter the single post check if try to display the menu somewhere else like a category page if( apply_filters('advanced_sidebar_menu_proper_single', $proper_single, $args, $instance, $asm) ) return; //Get the Top Parent Id if($post->ancestors){ $ancestors = $post->ancestors; $top_parent = end( $ancestors ); } else { $top_parent = $post->ID; } //Filter for specifying the top parent $top_parent = apply_filters('advanced_sidebar_menu_top_parent', $top_parent, $post, $args, $instance, $asm ); $asm->top_id = $top_parent; //Bail if the parent page does not belong in this menu if( get_post_type( $asm->top_id ) != $asm->post_type ) return; //Filter for specifiying the order by $order_by = apply_filters('advanced_sidebar_menu_order_by', $instance['order_by'], $post, $args, $instance, $asm ); $asm->order_by = $order_by; /** * Must be done this way to prevent doubling up of pages */ $child_pages = $wpdb->get_results( "SELECT ID FROM ". $wpdb->posts ." WHERE post_parent = $top_parent AND post_status='publish' AND post_type='$post_type' Order by $order_by" ); //for depreciation $p = $top_parent; $result = $child_pages = apply_filters( 'advanced_sidebar_menu_child_pages', $child_pages, $post, $args, $instance, $asm ); #---- if there are no children do not display the parent unless it is check to do so if( (!empty($child_pages)) || $asm->checked('include_childless_parent') && (!in_array($top_parent, $exclude) ) ){ $legacy = $asm->checked('legacy_mode'); if( $asm->checked('css') ){ echo ''; } //Start the menu echo $before_widget; #-- Bring in the require( $asm->file_hyercy( 'page_list.php', $legacy ) ); echo apply_filters('advanced_sidebar_menu_page_widget_output',$content, $args, $instance ); echo $after_widget; } } #== /widget() } #== /Clas