[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> class-wp-posts-list-table.php (source)

   1  <?php
   2  /**
   3   * Posts List Table class.
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   * @access private
   9   */
  10  class WP_Posts_List_Table extends WP_List_Table {
  11  
  12      /**
  13       * Whether the items should be displayed hierarchically or linearly
  14       *
  15       * @since 3.1.0
  16       * @var bool
  17       * @access protected
  18       */
  19      var $hierarchical_display;
  20  
  21      /**
  22       * Holds the number of pending comments for each post
  23       *
  24       * @since 3.1.0
  25       * @var int
  26       * @access protected
  27       */
  28      var $comment_pending_count;
  29  
  30      /**
  31       * Holds the number of posts for this user
  32       *
  33       * @since 3.1.0
  34       * @var int
  35       * @access private
  36       */
  37      var $user_posts_count;
  38  
  39      /**
  40       * Holds the number of posts which are sticky.
  41       *
  42       * @since 3.1.0
  43       * @var int
  44       * @access private
  45       */
  46      var $sticky_posts_count = 0;
  47  
  48  	function __construct() {
  49          global $post_type_object, $wpdb;
  50  
  51          $post_type = get_current_screen()->post_type;
  52          $post_type_object = get_post_type_object( $post_type );
  53  
  54          if ( !current_user_can( $post_type_object->cap->edit_others_posts ) ) {
  55              $this->user_posts_count = $wpdb->get_var( $wpdb->prepare( "
  56                  SELECT COUNT( 1 ) FROM $wpdb->posts
  57                  WHERE post_type = %s AND post_status NOT IN ( 'trash', 'auto-draft' )
  58                  AND post_author = %d
  59              ", $post_type, get_current_user_id() ) );
  60  
  61              if ( $this->user_posts_count && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) )
  62                  $_GET['author'] = get_current_user_id();
  63          }
  64  
  65          if ( 'post' == $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
  66              $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
  67              $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status != 'trash' AND ID IN ($sticky_posts)", $post_type ) );
  68          }
  69  
  70          parent::__construct( array(
  71              'plural' => 'posts',
  72          ) );
  73      }
  74  
  75  	function ajax_user_can() {
  76          global $post_type_object;
  77  
  78          return current_user_can( $post_type_object->cap->edit_posts );
  79      }
  80  
  81  	function prepare_items() {
  82          global $post_type_object, $avail_post_stati, $wp_query, $per_page, $mode;
  83  
  84          $avail_post_stati = wp_edit_posts_query();
  85  
  86          $this->hierarchical_display = ( $post_type_object->hierarchical && 'menu_order title' == $wp_query->query['orderby'] );
  87  
  88          $total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
  89  
  90          $post_type = $post_type_object->name;
  91          $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
  92           $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
  93  
  94          if ( $this->hierarchical_display )
  95              $total_pages = ceil( $total_items / $per_page );
  96          else
  97              $total_pages = $wp_query->max_num_pages;
  98  
  99          $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
 100  
 101          $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash';
 102  
 103          $this->set_pagination_args( array(
 104              'total_items' => $total_items,
 105              'total_pages' => $total_pages,
 106              'per_page' => $per_page
 107          ) );
 108      }
 109  
 110  	function has_items() {
 111          return have_posts();
 112      }
 113  
 114  	function no_items() {
 115          global $post_type_object;
 116  
 117          if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
 118              echo $post_type_object->labels->not_found_in_trash;
 119          else
 120              echo $post_type_object->labels->not_found;
 121      }
 122  
 123  	function get_views() {
 124          global $post_type_object, $locked_post_status, $avail_post_stati;
 125  
 126          $post_type = $post_type_object->name;
 127  
 128          if ( !empty($locked_post_status) )
 129              return array();
 130  
 131          $status_links = array();
 132          $num_posts = wp_count_posts( $post_type, 'readable' );
 133          $class = '';
 134          $allposts = '';
 135  
 136          $current_user_id = get_current_user_id();
 137  
 138          if ( $this->user_posts_count ) {
 139              if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
 140                  $class = ' class="current"';
 141              $status_links['mine'] = "<a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>';
 142              $allposts = '&all_posts=1';
 143          }
 144  
 145          $total_posts = array_sum( (array) $num_posts );
 146  
 147          // Subtract post types that are not included in the admin all list.
 148          foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
 149              $total_posts -= $num_posts->$state;
 150  
 151          $class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
 152          $status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
 153  
 154          foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
 155              $class = '';
 156  
 157              $status_name = $status->name;
 158  
 159              if ( !in_array( $status_name, $avail_post_stati ) )
 160                  continue;
 161  
 162              if ( empty( $num_posts->$status_name ) )
 163                  continue;
 164  
 165              if ( isset($_REQUEST['post_status']) && $status_name == $_REQUEST['post_status'] )
 166                  $class = ' class="current"';
 167  
 168              $status_links[$status_name] = "<a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( translate_nooped_plural( $status->label_count, $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>';
 169          }
 170  
 171          if ( ! empty( $this->sticky_posts_count ) ) {
 172              $class = ! empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
 173  
 174              $sticky_link = array( 'sticky' => "<a href='edit.php?post_type=$post_type&amp;show_sticky=1'$class>" . sprintf( _nx( 'Sticky <span class="count">(%s)</span>', 'Sticky <span class="count">(%s)</span>', $this->sticky_posts_count, 'posts' ), number_format_i18n( $this->sticky_posts_count ) ) . '</a>' );
 175  
 176              // Sticky comes after Publish, or if not listed, after All.
 177              $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
 178              $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
 179          }
 180  
 181          return $status_links;
 182      }
 183  
 184  	function get_bulk_actions() {
 185          $actions = array();
 186  
 187          if ( $this->is_trash )
 188              $actions['untrash'] = __( 'Restore' );
 189          else
 190              $actions['edit'] = __( 'Edit' );
 191  
 192          if ( $this->is_trash || !EMPTY_TRASH_DAYS )
 193              $actions['delete'] = __( 'Delete Permanently' );
 194          else
 195              $actions['trash'] = __( 'Move to Trash' );
 196  
 197          return $actions;
 198      }
 199  
 200  	function extra_tablenav( $which ) {
 201          global $post_type_object, $cat;
 202  ?>
 203          <div class="alignleft actions">
 204  <?php
 205          if ( 'top' == $which && !is_singular() ) {
 206  
 207              $this->months_dropdown( $post_type_object->name );
 208  
 209              if ( is_object_in_taxonomy( $post_type_object->name, 'category' ) ) {
 210                  $dropdown_options = array(
 211                      'show_option_all' => __( 'View all categories' ),
 212                      'hide_empty' => 0,
 213                      'hierarchical' => 1,
 214                      'show_count' => 0,
 215                      'orderby' => 'name',
 216                      'selected' => $cat
 217                  );
 218                  wp_dropdown_categories( $dropdown_options );
 219              }
 220              do_action( 'restrict_manage_posts' );
 221              submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) );
 222          }
 223  
 224          if ( $this->is_trash && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
 225              submit_button( __( 'Empty Trash' ), 'button-secondary apply', 'delete_all', false );
 226          }
 227  ?>
 228          </div>
 229  <?php
 230      }
 231  
 232  	function current_action() {
 233          if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
 234              return 'delete_all';
 235  
 236          return parent::current_action();
 237      }
 238  
 239  	function pagination( $which ) {
 240          global $post_type_object, $mode;
 241  
 242          parent::pagination( $which );
 243  
 244          if ( 'top' == $which && !$post_type_object->hierarchical )
 245              $this->view_switcher( $mode );
 246      }
 247  
 248  	function get_table_classes() {
 249          global $post_type_object;
 250  
 251          return array( 'widefat', 'fixed', $post_type_object->hierarchical ? 'pages' : 'posts' );
 252      }
 253  
 254  	function get_columns() {
 255          $screen = get_current_screen();
 256  
 257          if ( empty( $screen ) )
 258              $post_type = 'post';
 259          else
 260              $post_type = $screen->post_type;
 261  
 262          $posts_columns = array();
 263  
 264          $posts_columns['cb'] = '<input type="checkbox" />';
 265  
 266          /* translators: manage posts column name */
 267          $posts_columns['title'] = _x( 'Title', 'column name' );
 268  
 269          if ( post_type_supports( $post_type, 'author' ) )
 270              $posts_columns['author'] = __( 'Author' );
 271  
 272          if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'category' ) )
 273              $posts_columns['categories'] = __( 'Categories' );
 274  
 275          if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'post_tag' ) )
 276              $posts_columns['tags'] = __( 'Tags' );
 277  
 278          $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
 279          if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
 280              $posts_columns['comments'] = '<span class="vers"><img alt="' . esc_attr__( 'Comments' ) . '" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></span>';
 281  
 282          $posts_columns['date'] = __( 'Date' );
 283  
 284          if ( 'page' == $post_type )
 285              $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
 286          else
 287              $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
 288          $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
 289  
 290          return $posts_columns;
 291      }
 292  
 293  	function get_sortable_columns() {
 294          return array(
 295              'title'    => 'title',
 296              'author'   => 'author',
 297              'parent'   => 'parent',
 298              'comments' => 'comment_count',
 299              'date'     => array( 'date', true )
 300          );
 301      }
 302  
 303  	function display_rows( $posts = array() ) {
 304          global $wp_query, $post_type_object, $per_page;
 305  
 306          if ( empty( $posts ) )
 307              $posts = $wp_query->posts;
 308  
 309          add_filter( 'the_title', 'esc_html' );
 310  
 311          if ( $this->hierarchical_display ) {
 312              $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
 313          } else {
 314              $this->_display_rows( $posts );
 315          }
 316      }
 317  
 318  	function _display_rows( $posts ) {
 319          global $post, $mode;
 320  
 321          // Create array of post IDs.
 322          $post_ids = array();
 323  
 324          foreach ( $posts as $a_post )
 325              $post_ids[] = $a_post->ID;
 326  
 327          $this->comment_pending_count = get_pending_comments_num( $post_ids );
 328  
 329          foreach ( $posts as $post )
 330              $this->single_row( $post );
 331      }
 332  
 333  	function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
 334          global $wpdb;
 335  
 336          $level = 0;
 337  
 338          if ( ! $pages ) {
 339              $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
 340  
 341              if ( ! $pages )
 342                  return false;
 343          }
 344  
 345          /*
 346           * arrange pages into two parts: top level pages and children_pages
 347           * children_pages is two dimensional array, eg.
 348           * children_pages[10][] contains all sub-pages whose parent is 10.
 349           * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
 350           * If searching, ignore hierarchy and treat everything as top level
 351           */
 352          if ( empty( $_REQUEST['s'] ) ) {
 353  
 354              $top_level_pages = array();
 355              $children_pages = array();
 356  
 357              foreach ( $pages as $page ) {
 358  
 359                  // catch and repair bad pages
 360                  if ( $page->post_parent == $page->ID ) {
 361                      $page->post_parent = 0;
 362                      $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
 363                      clean_post_cache( $page );
 364                  }
 365  
 366                  if ( 0 == $page->post_parent )
 367                      $top_level_pages[] = $page;
 368                  else
 369                      $children_pages[ $page->post_parent ][] = $page;
 370              }
 371  
 372              $pages = &$top_level_pages;
 373          }
 374  
 375          $count = 0;
 376          $start = ( $pagenum - 1 ) * $per_page;
 377          $end = $start + $per_page;
 378  
 379          foreach ( $pages as $page ) {
 380              if ( $count >= $end )
 381                  break;
 382  
 383              if ( $count >= $start )
 384                  echo "\t" . $this->single_row( $page, $level );
 385  
 386              $count++;
 387  
 388              if ( isset( $children_pages ) )
 389                  $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
 390          }
 391  
 392          // if it is the last pagenum and there are orphaned pages, display them with paging as well
 393          if ( isset( $children_pages ) && $count < $end ){
 394              foreach ( $children_pages as $orphans ){
 395                  foreach ( $orphans as $op ) {
 396                      if ( $count >= $end )
 397                          break;
 398                      if ( $count >= $start )
 399                          echo "\t" . $this->single_row( $op, 0 );
 400                      $count++;
 401                  }
 402              }
 403          }
 404      }
 405  
 406      /**
 407       * Given a top level page ID, display the nested hierarchy of sub-pages
 408       * together with paging support
 409       *
 410       * @since 3.1.0 (Standalone function exists since 2.6.0)
 411       *
 412       * @param unknown_type $children_pages
 413       * @param unknown_type $count
 414       * @param unknown_type $parent
 415       * @param unknown_type $level
 416       * @param unknown_type $pagenum
 417       * @param unknown_type $per_page
 418       */
 419  	function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {
 420  
 421          if ( ! isset( $children_pages[$parent] ) )
 422              return;
 423  
 424          $start = ( $pagenum - 1 ) * $per_page;
 425          $end = $start + $per_page;
 426  
 427          foreach ( $children_pages[$parent] as $page ) {
 428  
 429              if ( $count >= $end )
 430                  break;
 431  
 432              // If the page starts in a subtree, print the parents.
 433              if ( $count == $start && $page->post_parent > 0 ) {
 434                  $my_parents = array();
 435                  $my_parent = $page->post_parent;
 436                  while ( $my_parent ) {
 437                      $my_parent = get_post( $my_parent );
 438                      $my_parents[] = $my_parent;
 439                      if ( !$my_parent->post_parent )
 440                          break;
 441                      $my_parent = $my_parent->post_parent;
 442                  }
 443                  $num_parents = count( $my_parents );
 444                  while ( $my_parent = array_pop( $my_parents ) ) {
 445                      echo "\t" . $this->single_row( $my_parent, $level - $num_parents );
 446                      $num_parents--;
 447                  }
 448              }
 449  
 450              if ( $count >= $start )
 451                  echo "\t" . $this->single_row( $page, $level );
 452  
 453              $count++;
 454  
 455              $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
 456          }
 457  
 458          unset( $children_pages[$parent] ); //required in order to keep track of orphans
 459      }
 460  
 461  	function single_row( $a_post, $level = 0 ) {
 462          global $post, $mode;
 463          static $alternate;
 464  
 465          $global_post = $post;
 466          $post = $a_post;
 467          setup_postdata( $post );
 468  
 469          $edit_link = get_edit_post_link( $post->ID );
 470          $title = _draft_or_post_title();
 471          $post_type_object = get_post_type_object( $post->post_type );
 472          $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
 473  
 474          $alternate = 'alternate' == $alternate ? '' : 'alternate';
 475          $classes = $alternate . ' iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
 476      ?>
 477          <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>" valign="top">
 478      <?php
 479  
 480          list( $columns, $hidden ) = $this->get_column_info();
 481  
 482          foreach ( $columns as $column_name => $column_display_name ) {
 483              $class = "class=\"$column_name column-$column_name\"";
 484  
 485              $style = '';
 486              if ( in_array( $column_name, $hidden ) )
 487                  $style = ' style="display:none;"';
 488  
 489              $attributes = "$class$style";
 490  
 491              switch ( $column_name ) {
 492  
 493              case 'cb':
 494              ?>
 495              <th scope="row" class="check-column"><?php if ( $can_edit_post ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
 496              <?php
 497              break;
 498  
 499              case 'title':
 500                  if ( $this->hierarchical_display ) {
 501                      $attributes = 'class="post-title page-title column-title"' . $style;
 502  
 503                      if ( 0 == $level && (int) $post->post_parent > 0 ) {
 504                          //sent level 0 by accident, by default, or because we don't know the actual level
 505                          $find_main_page = (int) $post->post_parent;
 506                          while ( $find_main_page > 0 ) {
 507                              $parent = get_page( $find_main_page );
 508  
 509                              if ( is_null( $parent ) )
 510                                  break;
 511  
 512                              $level++;
 513                              $find_main_page = (int) $parent->post_parent;
 514  
 515                              if ( !isset( $parent_name ) )
 516                                  $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
 517                          }
 518                      }
 519  
 520                      $pad = str_repeat( '&#8212; ', $level );
 521  ?>
 522              <td <?php echo $attributes ?>><strong><?php if ( $can_edit_post && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states( $post ); echo isset( $parent_name ) ? ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ) : ''; ?></strong>
 523  <?php
 524                  }
 525                  else {
 526                      $attributes = 'class="post-title page-title column-title"' . $style;
 527  ?>
 528              <td <?php echo $attributes ?>><strong><?php if ( $can_edit_post && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ); ?>"><?php echo $title ?></a><?php } else { echo $title; }; _post_states( $post ); ?></strong>
 529  <?php
 530                      if ( 'excerpt' == $mode ) {
 531                          the_excerpt();
 532                      }
 533                  }
 534  
 535                  $actions = array();
 536                  if ( $can_edit_post && 'trash' != $post->post_status ) {
 537                      $actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
 538                      $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
 539                  }
 540                  if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
 541                      if ( 'trash' == $post->post_status )
 542                          $actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
 543                      elseif ( EMPTY_TRASH_DAYS )
 544                          $actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
 545                      if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
 546                          $actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
 547                  }
 548                  if ( $post_type_object->public ) {
 549                      if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
 550                          if ( $can_edit_post )
 551                              $actions['view'] = '<a href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
 552                      } elseif ( 'trash' != $post->post_status ) {
 553                          $actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
 554                      }
 555                  }
 556  
 557                  $actions = apply_filters( is_post_type_hierarchical( $post->post_type ) ? 'page_row_actions' : 'post_row_actions', $actions, $post );
 558                  echo $this->row_actions( $actions );
 559  
 560                  get_inline_data( $post );
 561                  echo '</td>';
 562              break;
 563  
 564              case 'date':
 565                  if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
 566                      $t_time = $h_time = __( 'Unpublished' );
 567                      $time_diff = 0;
 568                  } else {
 569                      $t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
 570                      $m_time = $post->post_date;
 571                      $time = get_post_time( 'G', true, $post );
 572  
 573                      $time_diff = time() - $time;
 574  
 575                      if ( $time_diff > 0 && $time_diff < 24*60*60 )
 576                          $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
 577                      else
 578                          $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
 579                  }
 580  
 581                  echo '<td ' . $attributes . '>';
 582                  if ( 'excerpt' == $mode )
 583                      echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
 584                  else
 585                      echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
 586                  echo '<br />';
 587                  if ( 'publish' == $post->post_status ) {
 588                      _e( 'Published' );
 589                  } elseif ( 'future' == $post->post_status ) {
 590                      if ( $time_diff > 0 )
 591                          echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
 592                      else
 593                          _e( 'Scheduled' );
 594                  } else {
 595                      _e( 'Last Modified' );
 596                  }
 597                  echo '</td>';
 598              break;
 599  
 600              case 'categories':
 601              ?>
 602              <td <?php echo $attributes ?>><?php
 603                  $categories = get_the_category();
 604                  if ( !empty( $categories ) ) {
 605                      $out = array();
 606                      foreach ( $categories as $c ) {
 607                          $out[] = sprintf( '<a href="%s">%s</a>',
 608                              esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'category_name' => $c->slug ), 'edit.php' ) ),
 609                              esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'category', 'display' ) )
 610                          );
 611                      }
 612                      /* translators: used between list items, there is a space after the comma */
 613                      echo join( __( ', ' ), $out );
 614                  } else {
 615                      _e( 'Uncategorized' );
 616                  }
 617              ?></td>
 618              <?php
 619              break;
 620  
 621              case 'tags':
 622              ?>
 623              <td <?php echo $attributes ?>><?php
 624                  $tags = get_the_tags( $post->ID );
 625                  if ( !empty( $tags ) ) {
 626                      $out = array();
 627                      foreach ( $tags as $c ) {
 628                          $out[] = sprintf( '<a href="%s">%s</a>',
 629                              esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'tag' => $c->slug ), 'edit.php' ) ),
 630                              esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'tag', 'display' ) )
 631                          );
 632                      }
 633                      /* translators: used between list items, there is a space after the comma */
 634                      echo join( __( ', ' ), $out );
 635                  } else {
 636                      _e( 'No Tags' );
 637                  }
 638              ?></td>
 639              <?php
 640              break;
 641  
 642              case 'comments':
 643              ?>
 644              <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
 645              <?php
 646                  $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
 647  
 648                  $this->comments_bubble( $post->ID, $pending_comments );
 649              ?>
 650              </div></td>
 651              <?php
 652              break;
 653  
 654              case 'author':
 655              ?>
 656              <td <?php echo $attributes ?>><?php
 657                  printf( '<a href="%s">%s</a>',
 658                      esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
 659                      get_the_author()
 660                  );
 661              ?></td>
 662              <?php
 663              break;
 664  
 665              default:
 666              ?>
 667              <td <?php echo $attributes ?>><?php
 668                  if ( is_post_type_hierarchical( $post->post_type ) )
 669                      do_action( 'manage_pages_custom_column', $column_name, $post->ID );
 670                  else
 671                      do_action( 'manage_posts_custom_column', $column_name, $post->ID );
 672                  do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
 673              ?></td>
 674              <?php
 675              break;
 676          }
 677      }
 678      ?>
 679          </tr>
 680      <?php
 681          $post = $global_post;
 682      }
 683  
 684      /**
 685       * Outputs the hidden row displayed when inline editing
 686       *
 687       * @since 3.1.0
 688       */
 689  	function inline_edit() {
 690          global $mode;
 691  
 692          $screen = get_current_screen();
 693  
 694          $post = get_default_post_to_edit( $screen->post_type );
 695          $post_type_object = get_post_type_object( $screen->post_type );
 696  
 697          $taxonomy_names = get_object_taxonomies( $screen->post_type );
 698          $hierarchical_taxonomies = array();
 699          $flat_taxonomies = array();
 700          foreach ( $taxonomy_names as $taxonomy_name ) {
 701              $taxonomy = get_taxonomy( $taxonomy_name );
 702  
 703              if ( !$taxonomy->show_ui )
 704                  continue;
 705  
 706              if ( $taxonomy->hierarchical )
 707                  $hierarchical_taxonomies[] = $taxonomy;
 708              else
 709                  $flat_taxonomies[] = $taxonomy;
 710          }
 711  
 712          $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
 713          $can_publish = current_user_can( $post_type_object->cap->publish_posts );
 714          $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
 715  
 716      ?>
 717  
 718      <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
 719          <?php
 720          $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
 721          $bulk = 0;
 722          while ( $bulk < 2 ) { ?>
 723  
 724          <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
 725              echo $bulk ? "bulk-edit-row bulk-edit-row-$hclass bulk-edit-$screen->post_type" : "quick-edit-row quick-edit-row-$hclass inline-edit-$screen->post_type";
 726          ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
 727  
 728          <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
 729              <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
 730      <?php
 731  
 732      if ( post_type_supports( $screen->post_type, 'title' ) ) :
 733          if ( $bulk ) : ?>
 734              <div id="bulk-title-div">
 735                  <div id="bulk-titles"></div>
 736              </div>
 737  
 738      <?php else : // $bulk ?>
 739  
 740              <label>
 741                  <span class="title"><?php _e( 'Title' ); ?></span>
 742                  <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
 743              </label>
 744  
 745              <label>
 746                  <span class="title"><?php _e( 'Slug' ); ?></span>
 747                  <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
 748              </label>
 749  
 750      <?php endif; // $bulk
 751      endif; // post_type_supports title ?>
 752  
 753      <?php if ( !$bulk ) : ?>
 754              <label><span class="title"><?php _e( 'Date' ); ?></span></label>
 755              <div class="inline-edit-date">
 756                  <?php touch_time( 1, 1, 4, 1 ); ?>
 757              </div>
 758              <br class="clear" />
 759      <?php endif; // $bulk
 760  
 761          if ( post_type_supports( $screen->post_type, 'author' ) ) :
 762              $authors_dropdown = '';
 763  
 764              if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
 765                  $users_opt = array(
 766                      'hide_if_only_one_author' => false,
 767                      'who' => 'authors',
 768                      'name' => 'post_author',
 769                      'class'=> 'authors',
 770                      'multi' => 1,
 771                      'echo' => 0
 772                  );
 773                  if ( $bulk )
 774                      $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
 775  
 776                  if ( $authors = wp_dropdown_users( $users_opt ) ) :
 777                      $authors_dropdown  = '<label class="inline-edit-author">';
 778                      $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
 779                      $authors_dropdown .= $authors;
 780                      $authors_dropdown .= '</label>';
 781                  endif;
 782              endif; // authors
 783      ?>
 784  
 785      <?php if ( !$bulk ) echo $authors_dropdown;
 786      endif; // post_type_supports author
 787  
 788      if ( !$bulk ) :
 789      ?>
 790  
 791              <div class="inline-edit-group">
 792                  <label class="alignleft">
 793                      <span class="title"><?php _e( 'Password' ); ?></span>
 794                      <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
 795                  </label>
 796  
 797                  <em style="margin:5px 10px 0 0" class="alignleft">
 798                      <?php
 799                      /* translators: Between password field and private checkbox on post quick edit interface */
 800                      echo __( '&ndash;OR&ndash;' );
 801                      ?>
 802                  </em>
 803                  <label class="alignleft inline-edit-private">
 804                      <input type="checkbox" name="keep_private" value="private" />
 805                      <span class="checkbox-title"><?php echo __( 'Private' ); ?></span>
 806                  </label>
 807              </div>
 808  
 809      <?php endif; ?>
 810  
 811          </div></fieldset>
 812  
 813      <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
 814  
 815          <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
 816  
 817      <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
 818  
 819              <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?>
 820                  <span class="catshow"><?php _e( '[more]' ); ?></span>
 821                  <span class="cathide" style="display:none;"><?php _e( '[less]' ); ?></span>
 822              </span>
 823              <input type="hidden" name="<?php echo ( $taxonomy->name == 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
 824              <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
 825                  <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
 826              </ul>
 827  
 828      <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
 829  
 830          </div></fieldset>
 831  
 832      <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
 833  
 834          <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
 835  
 836      <?php
 837          if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
 838              echo $authors_dropdown;
 839  
 840          if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
 841  
 842              if ( $post_type_object->hierarchical ) :
 843          ?>
 844              <label>
 845                  <span class="title"><?php _e( 'Parent' ); ?></span>
 846      <?php
 847          $dropdown_args = array(
 848              'post_type'         => $post_type_object->name,
 849              'selected'          => $post->post_parent,
 850              'name'              => 'post_parent',
 851              'show_option_none'  => __( 'Main Page (no parent)' ),
 852              'option_none_value' => 0,
 853              'sort_column'       => 'menu_order, post_title',
 854          );
 855  
 856          if ( $bulk )
 857              $dropdown_args['show_option_no_change'] =  __( '&mdash; No Change &mdash;' );
 858          $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
 859          wp_dropdown_pages( $dropdown_args );
 860      ?>
 861              </label>
 862  
 863      <?php
 864              endif; // hierarchical
 865  
 866              if ( !$bulk ) : ?>
 867  
 868              <label>
 869                  <span class="title"><?php _e( 'Order' ); ?></span>
 870                  <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
 871              </label>
 872  
 873      <?php    endif; // !$bulk
 874  
 875              if ( 'page' == $screen->post_type ) :
 876      ?>
 877  
 878              <label>
 879                  <span class="title"><?php _e( 'Template' ); ?></span>
 880                  <select name="page_template">
 881      <?php    if ( $bulk ) : ?>
 882                      <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
 883      <?php    endif; // $bulk ?>
 884                      <option value="default"><?php _e( 'Default Template' ); ?></option>
 885                      <?php page_template_dropdown() ?>
 886                  </select>
 887              </label>
 888  
 889      <?php
 890              endif; // page post_type
 891          endif; // page-attributes
 892      ?>
 893  
 894      <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
 895  
 896      <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
 897          <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
 898              <label class="inline-edit-tags">
 899                  <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
 900                  <textarea cols="22" rows="1" name="tax_input[<?php echo esc_attr( $taxonomy->name )?>]" class="tax_input_<?php echo esc_attr( $taxonomy->name )?>"></textarea>
 901              </label>
 902          <?php endif; ?>
 903  
 904      <?php endforeach; //$flat_taxonomies as $taxonomy ?>
 905  
 906      <?php endif; // count( $flat_taxonomies ) && !$bulk  ?>
 907  
 908      <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
 909          if ( $bulk ) : ?>
 910  
 911              <div class="inline-edit-group">
 912          <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
 913              <label class="alignleft">
 914                  <span class="title"><?php _e( 'Comments' ); ?></span>
 915                  <select name="comment_status">
 916                      <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
 917                      <option value="open"><?php _e( 'Allow' ); ?></option>
 918                      <option value="closed"><?php _e( 'Do not allow' ); ?></option>
 919                  </select>
 920              </label>
 921          <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
 922              <label class="alignright">
 923                  <span class="title"><?php _e( 'Pings' ); ?></span>
 924                  <select name="ping_status">
 925                      <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
 926                      <option value="open"><?php _e( 'Allow' ); ?></option>
 927                      <option value="closed"><?php _e( 'Do not allow' ); ?></option>
 928                  </select>
 929              </label>
 930          <?php endif; ?>
 931              </div>
 932  
 933      <?php else : // $bulk ?>
 934  
 935              <div class="inline-edit-group">
 936              <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
 937                  <label class="alignleft">
 938                      <input type="checkbox" name="comment_status" value="open" />
 939                      <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
 940                  </label>
 941              <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
 942                  <label class="alignleft">
 943                      <input type="checkbox" name="ping_status" value="open" />
 944                      <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
 945                  </label>
 946              <?php endif; ?>
 947              </div>
 948  
 949      <?php endif; // $bulk
 950      endif; // post_type_supports comments or pings ?>
 951  
 952              <div class="inline-edit-group">
 953                  <label class="inline-edit-status alignleft">
 954                      <span class="title"><?php _e( 'Status' ); ?></span>
 955                      <select name="_status">
 956      <?php if ( $bulk ) : ?>
 957                          <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
 958      <?php endif; // $bulk ?>
 959                      <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
 960                          <option value="publish"><?php _e( 'Published' ); ?></option>
 961                          <option value="future"><?php _e( 'Scheduled' ); ?></option>
 962      <?php if ( $bulk ) : ?>
 963                          <option value="private"><?php _e( 'Private' ) ?></option>
 964      <?php endif; // $bulk ?>
 965                      <?php endif; ?>
 966                          <option value="pending"><?php _e( 'Pending Review' ); ?></option>
 967                          <option value="draft"><?php _e( 'Draft' ); ?></option>
 968                      </select>
 969                  </label>
 970  
 971      <?php if ( 'post' == $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
 972  
 973      <?php    if ( $bulk ) : ?>
 974  
 975                  <label class="alignright">
 976                      <span class="title"><?php _e( 'Sticky' ); ?></span>
 977                      <select name="sticky">
 978                          <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
 979                          <option value="sticky"><?php _e( 'Sticky' ); ?></option>
 980                          <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
 981                      </select>
 982                  </label>
 983  
 984      <?php    else : // $bulk ?>
 985  
 986                  <label class="alignleft">
 987                      <input type="checkbox" name="sticky" value="sticky" />
 988                      <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
 989                  </label>
 990  
 991      <?php    endif; // $bulk ?>
 992  
 993      <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
 994  
 995              </div>
 996  
 997      <?php if ( post_type_supports( $screen->post_type, 'post-formats' ) && current_theme_supports( 'post-formats' ) ) :
 998          $post_formats = get_theme_support( 'post-formats' );
 999          if ( isset( $post_formats[0] ) && is_array( $post_formats[0] ) ) :
1000              $all_post_formats = get_post_format_strings();
1001              unset( $all_post_formats['standard'] ); ?>
1002              <div class="inline-edit-group">
1003                  <label class="alignleft" for="post_format">
1004                  <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1005                  <select name="post_format">
1006                  <?php if ( $bulk ) : ?>
1007                      <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1008                  <?php endif; ?>
1009                      <option value="0"><?php _ex( 'Standard', 'Post format' ); ?></option>
1010                  <?php foreach ( $all_post_formats as $slug => $format ) :
1011                      $unsupported = ! in_array( $slug, $post_formats[0] );
1012                      if ( $bulk && $unsupported )
1013                          continue;
1014                      ?>
1015                      <option value="<?php echo esc_attr( $slug ); ?>"<?php if ( $unsupported ) echo ' class="unsupported"'; ?>><?php echo esc_html( $format ); ?></option>
1016                  <?php endforeach; ?>
1017                  </select></label>
1018              </div>
1019          <?php endif; ?>
1020      <?php endif; // post-formats ?>
1021  
1022          </div></fieldset>
1023  
1024      <?php
1025          list( $columns ) = $this->get_column_info();
1026  
1027          foreach ( $columns as $column_name => $column_display_name ) {
1028              if ( isset( $core_columns[$column_name] ) )
1029                  continue;
1030              do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $screen->post_type );
1031          }
1032      ?>
1033          <p class="submit inline-edit-save">
1034              <a accesskey="c" href="#inline-edit" title="<?php esc_attr_e( 'Cancel' ); ?>" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
1035              <?php if ( ! $bulk ) {
1036                  wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1037                  $update_text = __( 'Update' );
1038                  ?>
1039                  <a accesskey="s" href="#inline-edit" title="<?php esc_attr_e( 'Update' ); ?>" class="button-primary save alignright"><?php echo esc_attr( $update_text ); ?></a>
1040                  <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1041              <?php } else {
1042                  submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false, array( 'accesskey' => 's' ) );
1043              } ?>
1044              <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1045              <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1046              <span class="error" style="display:none"></span>
1047              <br class="clear" />
1048          </p>
1049          </td></tr>
1050      <?php
1051          $bulk++;
1052          }
1053  ?>
1054          </tbody></table></form>
1055  <?php
1056      }
1057  }


Generated: Fri May 25 03:56:23 2012 Hosted by follow the white rabbit.