Advertisement
Guest User

Admin Menu Post List - WordPress plugin (dev)

a guest
Oct 16th, 2013
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.57 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Admin Menu Post List
  4. Plugin URI:
  5. Description: Display a simple post list in admin menu for easy access
  6. Version: 0.2
  7. Author: Eliot Akira
  8. Author URI:
  9. License: GPL2
  10. */
  11.  
  12.  
  13. /*
  14.  * Load CSS in header
  15.  */
  16.  
  17. function custom_post_list_view_css() { ?>
  18.  
  19.     <style>
  20.         .post_list_view_headline {
  21.             padding-left: 10px !important;
  22.             padding-right: 10px !important;
  23.         }
  24.         .post_list_view_post {
  25.             margin-left:12px;
  26.         }
  27.         .post_current a {
  28.             color:white !important;
  29.         }
  30.     </style>
  31.  
  32. <?php }
  33. add_action( 'admin_head', 'custom_post_list_view_css' );
  34.  
  35.  
  36. /*
  37.  * Admin Menu Post List
  38.  */
  39.  
  40.  
  41. add_action('admin_menu', 'custom_post_list_view');
  42. function custom_post_list_view() {
  43.  
  44.     /*** Get options ***/
  45.  
  46.     $post_types = array( 'post', 'page' );
  47.  
  48.     $current_post_ID = $_GET['post']; /* Get current post ID on admin screen */
  49.  
  50.     foreach ($post_types as $post_type) {
  51.  
  52.         $custom_menu_slug = $post_type;
  53.         $output = '';
  54.  
  55.         $args = array(
  56.             "post_type" => $post_type,
  57.             "parent" => "0",
  58.             "post_parent" => "0",
  59.             "numberposts" => "-1",
  60.             "orderby" => "menu_order",
  61.             "order" => "ASC",
  62.             "post_status" => "any",
  63.             "suppress_filters" => 0
  64.         );
  65.  
  66.         $posts = get_posts($args);
  67.  
  68.         if($posts) {
  69.  
  70.             $output .= '</a>';
  71.  
  72.             $output .= '<div class="list_view_' . $post_type . '">'
  73.                         . '<div class="post_list_view_headline">' . '<hr>' . '</div>';
  74.             foreach ($posts as $post) {
  75.                 $edit_link = get_edit_post_link($post->ID);
  76.                 $title = get_the_title($post->ID);
  77.                 $title = esc_html($title);
  78.                 $output .= '<div class="post_list_view_post';
  79.                 if($current_post_ID == ($post->ID)) {
  80.                     $output .= ' post_current';
  81.                 }
  82.                 $output .= '">'
  83.                     . '<a href="'
  84.                     . $edit_link    . '">'
  85.                     . $title . '</a></div>';
  86.  
  87.                 /*** Search for children? ***/
  88.  
  89.             }
  90.             $output .= '</div>';
  91.  
  92.             $output .= '<a>';
  93.  
  94.             if($post_type == 'post') {
  95.                 add_posts_page( "Title", $output, "edit_posts", $custom_menu_slug, "custom_post_list_view_page");
  96.             } else {
  97.                  if ($post_type == 'page') {
  98.                     add_pages_page( "Title", $output, "edit_pages", $custom_menu_slug, "custom_post_list_view_page");
  99.                 } else {
  100.                     if($post_type == 'attachment') {
  101.                          add_media_page("Title", $output, "edit_posts", $custom_menu_slug, "custom_post_list_view_page");
  102.                     } else {
  103.                         add_submenu_page(('edit.php?post_type=' . $post_type), "Title", $output, "edit_posts", ('edit.php?post_type=' . $post_type), "custom_post_list_view_page");
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.     } // End foreach post type
  109. }
  110.  
  111. function custom_post_list_view_page() { /* Empty */ }
  112.  
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement