saved_notice = false; } /*======================================================================== * * Admin frontend * *=======================================================================*/ /*======================================================================== * * Build each item * *=======================================================================*/ function build_post_list_item($post_id, $post_type, $is_child, $child_query) { if( !isset($_GET['post']) ) $current_post_ID = -1; else $current_post_ID = $_GET['post']; /* Get current post ID on admin screen */ $edit_link = get_edit_post_link($post_id); $title = get_the_title($post_id); $title = esc_html($title); // Limit title length if (($this->max_trim_length>0) && ( strlen($title)>($this->max_trim_length) ) ) { $orig_title = $title; if( function_exists( 'mb_substr' ) ) { $title = mb_substr($title, 0, $this->max_trim_length); } else { $title = substr($title, 0, $this->max_trim_length); } if ($title != $orig_title) $title.='..'; } $output = '
'; $output .= ''; /*======================================================================== * * Indent child posts * *=======================================================================*/ if ($is_child == 'child') { if ($this->current_indent_level>0) { $output .= '
'; for ($i=0; $i < $this->current_indent_level; $i++) { $output .= '–'; } $output .= '
'; $output .= ' '; } } /*======================================================================== * * Post status * *=======================================================================*/ switch(get_post_status($post_id)) { case 'draft': case 'pending': case 'future' : $output .= ''; break; } if($current_post_ID == ($post_id)) $output .= ''; $output .= $title; if($current_post_ID == ($post_id)) $output .= ''; switch(get_post_status($post_id)) { case 'draft': case 'pending': case 'future' : $output .= ''; break; } $output .= '
'; /*======================================================================== * * Search for children * *=======================================================================*/ $children = get_posts(array( 'post_parent' => $post_id, 'post_type' => $post_type, "orderby" => $child_query['orderby'], "order" => $child_query['order'], 'post_status' => $child_query['post_status'], 'posts_per_page' => -1, )); // Dropdown for children? $dropdown = false; if ( (($is_child == 'parent') && ($children) && ($this->drop_down_enabled)) && (($this->max_list_count==0) || ($this->current_list_count < $this->max_list_count)) ) { $this->current_drop_down_count++; $output .= '
+
'; $dropdown = true; } // Output child posts recursively if($children) { if ($dropdown) { $output .= '
'; } $this->current_indent_level++; foreach($children as $child) { // Count children? if (!$dropdown) $this->current_list_count++; if (($this->max_list_count==0) || ($this->current_list_count <= $this->max_list_count)) { $output .= $this->build_post_list_item($child->ID,$post_type,'child',$post_status); } else { break; } } $this->current_indent_level--; if ($dropdown) $output .= '
'; } $output .= '
'; return $output; } // End: function build_post_list_item /*======================================================================== * * Add post list to all enabled post types * *=======================================================================*/ function add_post_list_view() { // Get settings $settings = get_option( 'ampl_settings' ); $this->max_trim_length = isset($settings['max_trim']) ? $settings['max_trim'] : 0; $this->drop_down_enabled = isset($settings['child_dropdown']) ? ($settings['child_dropdown']=="on") : false; $this->current_drop_down_count = 0; // Get all post types $post_types = get_post_types(); foreach ($post_types as $post_type) { $post_types_setting = isset($settings['post_types'][$post_type]) ? $settings['post_types'][$post_type] : 'off'; // If enabled if($post_types_setting == 'on' ) { /*======================================================================== * * Get display options * *=======================================================================*/ $this->max_list_count = isset($settings['max_limit'][$post_type]) ? $settings['max_limit'][$post_type] : 0; $post_orderby = isset($settings['orderby'][$post_type]) ? $settings['orderby'][$post_type] : 'date'; $post_order = isset($settings['order'][$post_type]) ? $settings['order'][$post_type] : 'ASC'; $post_exclude = isset($settings['exclude_status'][$post_type]) ? $settings['exclude_status'][$post_type] : 'off'; if ($post_exclude=='on') $post_exclude = 'publish'; else $post_exclude = 'any'; $custom_menu_slug = $post_type; $output = ''; if ($this->max_list_count==0) { $max_numberposts = 999; } else { $max_numberposts = $this->max_list_count; } $args = array( "post_type" => $post_type, "parent" => "0", "post_parent" => "0", "numberposts" => $max_numberposts, "orderby" => $post_orderby, "order" => $post_order, "post_status" => $post_exclude, "suppress_filters" => 0 ); $child_query = array( "orderby" => $post_orderby, "order" => $post_order, "post_status" => $post_exclude, ); $posts = get_posts($args); if($posts) { $output .= ''; $output .= '
' . '
' . '
' . '
'; $this->current_list_count = 0; foreach ($posts as $post) { $this->current_indent_level = 0; // Start all parents at 0 $this->current_list_count++; if ( (($this->max_list_count==0) || ($this->current_list_count<=$this->max_list_count)) ) { $output .= $this->build_post_list_item($post->ID, $post_type, 'parent', $child_query); } else { break; } } $output .= '
'; $output .= ''; if($post_type == 'post') { add_posts_page( "Title", $output, "edit_posts", $custom_menu_slug, array($this, "empty_page")); } else { if ($post_type == 'page') { add_pages_page( "Title", $output, "edit_pages", $custom_menu_slug, array($this, "empty_page")); } else { if($post_type == 'attachment') { add_media_page("Title", $output, "edit_posts", $custom_menu_slug, array($this, "empty_page")); } else { add_submenu_page(('edit.php?post_type=' . $post_type), "Title", $output, "edit_posts", $custom_menu_slug, array($this, "empty_page")); } } } } // if post } // if enabled for a post type } // for each post type } // End: function add_post_list_view function empty_page() { /* Empty */ } /*======================================================================== * * Post list CSS * *=======================================================================*/ function post_list_css() { ?> current_drop_down_count>0) || ($this->is_plugin_page())) { ?> ' . __( 'Settings', 'admin_menu_post_list_settings_page' ) . ''; array_unshift( $links, $settings_link ); } return $links; } function register_settings() { register_setting( 'ampl_settings_field', 'ampl_settings', array($this,'settings_field_validate')); add_settings_section('ampl_settings_section', '', array($this,'empty_page'), 'ampl_settings_section_page_name'); add_settings_field('ampl_settings_field_string', '', array($this,'settings_field_input'), 'ampl_settings_section_page_name', 'ampl_settings_section'); } function settings_field_validate($input) { return $input; } function ampl_settings_page() { ?>

Admin Menu Post List

saved_notice) echo '
Settings saved.
'; ?>
Post type Max items (0=all) Order by Order Show only published true)); $exclude_types = array('attachment'); ksort($all_post_types); // Global settings if(isset( $settings['max_trim'] ) ) $max_trim = $settings['max_trim']; else $max_trim = '20'; if(isset( $settings['child_dropdown'] ) ) $child_dropdown = $settings['child_dropdown']; else $child_dropdown = 'off'; // Post type specific settings foreach ($all_post_types as $key) { if(!in_array($key, $exclude_types)) { $post_types = isset( $settings['post_types'][ $key ] ) ? esc_attr( $settings['post_types'][ $key ] ) : ''; $post_type_object = get_post_type_object( $key ); $post_type_label = $post_type_object->labels->name; if(isset( $settings['max_limit'][ $key ] ) ) $max_number = $settings['max_limit'][ $key ]; else $max_number = '0'; if(isset( $settings['orderby'][ $key ] ) ) $post_orderby = $settings['orderby'][ $key ]; else $post_orderby = 'date'; if(isset( $settings['order'][ $key ] ) ) $post_order = $settings['order'][ $key ]; else $post_order = 'DESC'; if(isset( $settings['exclude_status'][ $key ] ) ) $post_exclude = $settings['exclude_status'][ $key ]; else $post_exclude = 'off'; ?> /> /> '; ?> /> '; ?> /> /> '; ?> /> /> Limit title length Child posts in dropdown? /> is_plugin_page()) { if ( (isset($_GET['updated']) && $_GET['updated'] == 'true') || (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') ) { //this will clear the update message "Settings Saved" totally unset($_GET['settings-updated']); $this->saved_notice = true; } } } } new AdminMenuPostList;