[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * List Table API: WP_Posts_List_Table class
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   * @since 3.1.0
   8   */
   9  
  10  /**
  11   * Core class used to implement displaying posts in a list table.
  12   *
  13   * @since 3.1.0
  14   * @access private
  15   *
  16   * @see WP_List_Table
  17   */
  18  class WP_Posts_List_Table extends WP_List_Table {
  19  
  20      /**
  21       * Whether the items should be displayed hierarchically or linearly.
  22       *
  23       * @since 3.1.0
  24       * @var bool
  25       */
  26      protected $hierarchical_display;
  27  
  28      /**
  29       * Holds the number of pending comments for each post.
  30       *
  31       * @since 3.1.0
  32       * @var array
  33       */
  34      protected $comment_pending_count;
  35  
  36      /**
  37       * Holds the number of posts for this user.
  38       *
  39       * @since 3.1.0
  40       * @var int
  41       */
  42      private $user_posts_count;
  43  
  44      /**
  45       * Holds the number of posts which are sticky.
  46       *
  47       * @since 3.1.0
  48       * @var int
  49       */
  50      private $sticky_posts_count = 0;
  51  
  52      private $is_trash;
  53  
  54      /**
  55       * Current level for output.
  56       *
  57       * @since 4.3.0
  58       * @var int
  59       */
  60      protected $current_level = 0;
  61  
  62      /**
  63       * Constructor.
  64       *
  65       * @since 3.1.0
  66       *
  67       * @see WP_List_Table::__construct() for more information on default arguments.
  68       *
  69       * @global WP_Post_Type $post_type_object
  70       * @global wpdb         $wpdb             WordPress database abstraction object.
  71       *
  72       * @param array $args An associative array of arguments.
  73       */
  74  	public function __construct( $args = array() ) {
  75          global $post_type_object, $wpdb;
  76  
  77          parent::__construct(
  78              array(
  79                  'plural' => 'posts',
  80                  'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  81              )
  82          );
  83  
  84          $post_type        = $this->screen->post_type;
  85          $post_type_object = get_post_type_object( $post_type );
  86  
  87          $exclude_states         = get_post_stati(
  88              array(
  89                  'show_in_admin_all_list' => false,
  90              )
  91          );
  92          $this->user_posts_count = intval(
  93              $wpdb->get_var(
  94                  $wpdb->prepare(
  95                      "
  96              SELECT COUNT( 1 )
  97              FROM $wpdb->posts
  98              WHERE post_type = %s
  99              AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
 100              AND post_author = %d
 101          ",
 102                      $post_type,
 103                      get_current_user_id()
 104                  )
 105              )
 106          );
 107  
 108          if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
 109              $_GET['author'] = get_current_user_id();
 110          }
 111  
 112          $sticky_posts = get_option( 'sticky_posts' );
 113          if ( 'post' === $post_type && $sticky_posts ) {
 114              $sticky_posts             = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
 115              $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
 116          }
 117      }
 118  
 119      /**
 120       * Sets whether the table layout should be hierarchical or not.
 121       *
 122       * @since 4.2.0
 123       *
 124       * @param bool $display Whether the table layout should be hierarchical.
 125       */
 126  	public function set_hierarchical_display( $display ) {
 127          $this->hierarchical_display = $display;
 128      }
 129  
 130      /**
 131       * @return bool
 132       */
 133  	public function ajax_user_can() {
 134          return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
 135      }
 136  
 137      /**
 138       * @global array    $avail_post_stati
 139       * @global WP_Query $wp_query         WordPress Query object.
 140       * @global int      $per_page
 141       * @global string   $mode
 142       */
 143  	public function prepare_items() {
 144          global $avail_post_stati, $wp_query, $per_page, $mode;
 145  
 146          // is going to call wp()
 147          $avail_post_stati = wp_edit_posts_query();
 148  
 149          $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
 150  
 151          $post_type = $this->screen->post_type;
 152          $per_page  = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
 153  
 154          /** This filter is documented in wp-admin/includes/post.php */
 155          $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
 156  
 157          if ( $this->hierarchical_display ) {
 158              $total_items = $wp_query->post_count;
 159          } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
 160              $total_items = $wp_query->found_posts;
 161          } else {
 162              $post_counts = (array) wp_count_posts( $post_type, 'readable' );
 163  
 164              if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati ) ) {
 165                  $total_items = $post_counts[ $_REQUEST['post_status'] ];
 166              } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
 167                  $total_items = $this->sticky_posts_count;
 168              } elseif ( isset( $_GET['author'] ) && $_GET['author'] == get_current_user_id() ) {
 169                  $total_items = $this->user_posts_count;
 170              } else {
 171                  $total_items = array_sum( $post_counts );
 172  
 173                  // Subtract post types that are not included in the admin all list.
 174                  foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
 175                      $total_items -= $post_counts[ $state ];
 176                  }
 177              }
 178          }
 179  
 180          if ( ! empty( $_REQUEST['mode'] ) ) {
 181              $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
 182              set_user_setting( 'posts_list_mode', $mode );
 183          } else {
 184              $mode = get_user_setting( 'posts_list_mode', 'list' );
 185          }
 186  
 187          $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash';
 188  
 189          $this->set_pagination_args(
 190              array(
 191                  'total_items' => $total_items,
 192                  'per_page'    => $per_page,
 193              )
 194          );
 195      }
 196  
 197      /**
 198       * @return bool
 199       */
 200  	public function has_items() {
 201          return have_posts();
 202      }
 203  
 204      /**
 205       */
 206  	public function no_items() {
 207          if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] ) {
 208              echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
 209          } else {
 210              echo get_post_type_object( $this->screen->post_type )->labels->not_found;
 211          }
 212      }
 213  
 214      /**
 215       * Determine if the current view is the "All" view.
 216       *
 217       * @since 4.2.0
 218       *
 219       * @return bool Whether the current view is the "All" view.
 220       */
 221  	protected function is_base_request() {
 222          $vars = $_GET;
 223          unset( $vars['paged'] );
 224  
 225          if ( empty( $vars ) ) {
 226              return true;
 227          } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) {
 228              return $this->screen->post_type === $vars['post_type'];
 229          }
 230  
 231          return 1 === count( $vars ) && ! empty( $vars['mode'] );
 232      }
 233  
 234      /**
 235       * Helper to create links to edit.php with params.
 236       *
 237       * @since 4.4.0
 238       *
 239       * @param string[] $args  Associative array of URL parameters for the link.
 240       * @param string   $label Link text.
 241       * @param string   $class Optional. Class attribute. Default empty string.
 242       * @return string The formatted link string.
 243       */
 244  	protected function get_edit_link( $args, $label, $class = '' ) {
 245          $url = add_query_arg( $args, 'edit.php' );
 246  
 247          $class_html   = '';
 248          $aria_current = '';
 249          if ( ! empty( $class ) ) {
 250              $class_html = sprintf(
 251                  ' class="%s"',
 252                  esc_attr( $class )
 253              );
 254  
 255              if ( 'current' === $class ) {
 256                  $aria_current = ' aria-current="page"';
 257              }
 258          }
 259  
 260          return sprintf(
 261              '<a href="%s"%s%s>%s</a>',
 262              esc_url( $url ),
 263              $class_html,
 264              $aria_current,
 265              $label
 266          );
 267      }
 268  
 269      /**
 270       * @global array $locked_post_status This seems to be deprecated.
 271       * @global array $avail_post_stati
 272       * @return array
 273       */
 274  	protected function get_views() {
 275          global $locked_post_status, $avail_post_stati;
 276  
 277          $post_type = $this->screen->post_type;
 278  
 279          if ( ! empty( $locked_post_status ) ) {
 280              return array();
 281          }
 282  
 283          $status_links = array();
 284          $num_posts    = wp_count_posts( $post_type, 'readable' );
 285          $total_posts  = array_sum( (array) $num_posts );
 286          $class        = '';
 287  
 288          $current_user_id = get_current_user_id();
 289          $all_args        = array( 'post_type' => $post_type );
 290          $mine            = '';
 291  
 292          // Subtract post types that are not included in the admin all list.
 293          foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
 294              $total_posts -= $num_posts->$state;
 295          }
 296  
 297          if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
 298              if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
 299                  $class = 'current';
 300              }
 301  
 302              $mine_args = array(
 303                  'post_type' => $post_type,
 304                  'author'    => $current_user_id,
 305              );
 306  
 307              $mine_inner_html = sprintf(
 308                  /* translators: %s: Number of posts. */
 309                  _nx(
 310                      'Mine <span class="count">(%s)</span>',
 311                      'Mine <span class="count">(%s)</span>',
 312                      $this->user_posts_count,
 313                      'posts'
 314                  ),
 315                  number_format_i18n( $this->user_posts_count )
 316              );
 317  
 318              $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
 319  
 320              $all_args['all_posts'] = 1;
 321              $class                 = '';
 322          }
 323  
 324          if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
 325              $class = 'current';
 326          }
 327  
 328          $all_inner_html = sprintf(
 329              /* translators: %s: Number of posts. */
 330              _nx(
 331                  'All <span class="count">(%s)</span>',
 332                  'All <span class="count">(%s)</span>',
 333                  $total_posts,
 334                  'posts'
 335              ),
 336              number_format_i18n( $total_posts )
 337          );
 338  
 339          $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
 340          if ( $mine ) {
 341              $status_links['mine'] = $mine;
 342          }
 343  
 344          foreach ( get_post_stati( array( 'show_in_admin_status_list' => true ), 'objects' ) as $status ) {
 345              $class = '';
 346  
 347              $status_name = $status->name;
 348  
 349              if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) {
 350                  continue;
 351              }
 352  
 353              if ( isset( $_REQUEST['post_status'] ) && $status_name === $_REQUEST['post_status'] ) {
 354                  $class = 'current';
 355              }
 356  
 357              $status_args = array(
 358                  'post_status' => $status_name,
 359                  'post_type'   => $post_type,
 360              );
 361  
 362              $status_label = sprintf(
 363                  translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
 364                  number_format_i18n( $num_posts->$status_name )
 365              );
 366  
 367              $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
 368          }
 369  
 370          if ( ! empty( $this->sticky_posts_count ) ) {
 371              $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
 372  
 373              $sticky_args = array(
 374                  'post_type'   => $post_type,
 375                  'show_sticky' => 1,
 376              );
 377  
 378              $sticky_inner_html = sprintf(
 379                  /* translators: %s: Number of posts. */
 380                  _nx(
 381                      'Sticky <span class="count">(%s)</span>',
 382                      'Sticky <span class="count">(%s)</span>',
 383                      $this->sticky_posts_count,
 384                      'posts'
 385                  ),
 386                  number_format_i18n( $this->sticky_posts_count )
 387              );
 388  
 389              $sticky_link = array(
 390                  'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class ),
 391              );
 392  
 393              // Sticky comes after Publish, or if not listed, after All.
 394              $split        = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
 395              $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
 396          }
 397  
 398          return $status_links;
 399      }
 400  
 401      /**
 402       * @return array
 403       */
 404  	protected function get_bulk_actions() {
 405          $actions       = array();
 406          $post_type_obj = get_post_type_object( $this->screen->post_type );
 407  
 408          if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
 409              if ( $this->is_trash ) {
 410                  $actions['untrash'] = __( 'Restore' );
 411              } else {
 412                  $actions['edit'] = __( 'Edit' );
 413              }
 414          }
 415  
 416          if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
 417              if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
 418                  $actions['delete'] = __( 'Delete Permanently' );
 419              } else {
 420                  $actions['trash'] = __( 'Move to Trash' );
 421              }
 422          }
 423  
 424          return $actions;
 425      }
 426  
 427      /**
 428       * Displays a categories drop-down for filtering on the Posts list table.
 429       *
 430       * @since 4.6.0
 431       *
 432       * @global int $cat Currently selected category.
 433       *
 434       * @param string $post_type Post type slug.
 435       */
 436  	protected function categories_dropdown( $post_type ) {
 437          global $cat;
 438  
 439          /**
 440           * Filters whether to remove the 'Categories' drop-down from the post list table.
 441           *
 442           * @since 4.6.0
 443           *
 444           * @param bool   $disable   Whether to disable the categories drop-down. Default false.
 445           * @param string $post_type Post type slug.
 446           */
 447          if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
 448              return;
 449          }
 450  
 451          if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
 452              $dropdown_options = array(
 453                  'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
 454                  'hide_empty'      => 0,
 455                  'hierarchical'    => 1,
 456                  'show_count'      => 0,
 457                  'orderby'         => 'name',
 458                  'selected'        => $cat,
 459              );
 460  
 461              echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
 462              wp_dropdown_categories( $dropdown_options );
 463          }
 464      }
 465  
 466      /**
 467       * Displays a formats drop-down for filtering items.
 468       *
 469       * @since 5.2.0
 470       * @access protected
 471       *
 472       * @param string $post_type Post type key.
 473       */
 474  	protected function formats_dropdown( $post_type ) {
 475          /**
 476           * Filters whether to remove the 'Formats' drop-down from the post list table.
 477           *
 478           * @since 5.2.0
 479           *
 480           * @param bool $disable Whether to disable the drop-down. Default false.
 481           */
 482          if ( apply_filters( 'disable_formats_dropdown', false ) ) {
 483              return;
 484          }
 485  
 486          // Make sure the dropdown shows only formats with a post count greater than 0.
 487          $used_post_formats = get_terms(
 488              array(
 489                  'taxonomy'   => 'post_format',
 490                  'hide_empty' => true,
 491              )
 492          );
 493  
 494          /*
 495           * Return if the post type doesn't have post formats, or there are no posts using formats,
 496           * or if we're in the trash.
 497           */
 498          if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || ! $used_post_formats || $this->is_trash ) {
 499              return;
 500          }
 501  
 502          $displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
 503          ?>
 504          <label for="filter-by-format" class="screen-reader-text"><?php _e( 'Filter by post format' ); ?></label>
 505          <select name="post_format" id="filter-by-format">
 506              <option<?php selected( $displayed_post_format, '' ); ?> value=""><?php _e( 'All formats' ); ?></option>
 507              <?php
 508              foreach ( $used_post_formats as $used_post_format ) {
 509                  // Post format slug.
 510                  $slug = str_replace( 'post-format-', '', $used_post_format->slug );
 511                  // Pretty, translated version of the post format slug.
 512                  $pretty_name = get_post_format_string( $slug );
 513                  // Skip the standard post format.
 514                  if ( 'standard' === $slug ) {
 515                      continue;
 516                  }
 517                  ?>
 518                  <option<?php selected( $displayed_post_format, $slug ); ?> value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $pretty_name ); ?></option>
 519                  <?php
 520              }
 521              ?>
 522          </select>
 523          <?php
 524      }
 525  
 526      /**
 527       * @param string $which
 528       */
 529  	protected function extra_tablenav( $which ) {
 530          ?>
 531          <div class="alignleft actions">
 532          <?php
 533          if ( 'top' === $which && ! is_singular() ) {
 534              ob_start();
 535  
 536              $this->months_dropdown( $this->screen->post_type );
 537              $this->categories_dropdown( $this->screen->post_type );
 538              $this->formats_dropdown( $this->screen->post_type );
 539  
 540              /**
 541               * Fires before the Filter button on the Posts and Pages list tables.
 542               *
 543               * The Filter button allows sorting by date and/or category on the
 544               * Posts list table, and sorting by date on the Pages list table.
 545               *
 546               * @since 2.1.0
 547               * @since 4.4.0 The `$post_type` parameter was added.
 548               * @since 4.6.0 The `$which` parameter was added.
 549               *
 550               * @param string $post_type The post type slug.
 551               * @param string $which     The location of the extra table nav markup:
 552               *                          'top' or 'bottom' for WP_Posts_List_Table,
 553               *                          'bar' for WP_Media_List_Table.
 554               */
 555              do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
 556  
 557              $output = ob_get_clean();
 558  
 559              if ( ! empty( $output ) ) {
 560                  echo $output;
 561                  submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
 562              }
 563          }
 564  
 565          if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) {
 566              submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
 567          }
 568          ?>
 569          </div>
 570          <?php
 571          /**
 572           * Fires immediately following the closing "actions" div in the tablenav for the posts
 573           * list table.
 574           *
 575           * @since 4.4.0
 576           *
 577           * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
 578           */
 579          do_action( 'manage_posts_extra_tablenav', $which );
 580      }
 581  
 582      /**
 583       * @return string
 584       */
 585  	public function current_action() {
 586          if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
 587              return 'delete_all';
 588          }
 589  
 590          return parent::current_action();
 591      }
 592  
 593      /**
 594       * @return array
 595       */
 596  	protected function get_table_classes() {
 597          return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
 598      }
 599  
 600      /**
 601       * @return array
 602       */
 603  	public function get_columns() {
 604          $post_type = $this->screen->post_type;
 605  
 606          $posts_columns = array();
 607  
 608          $posts_columns['cb'] = '<input type="checkbox" />';
 609  
 610          /* translators: Posts screen column name. */
 611          $posts_columns['title'] = _x( 'Title', 'column name' );
 612  
 613          if ( post_type_supports( $post_type, 'author' ) ) {
 614              $posts_columns['author'] = __( 'Author' );
 615          }
 616  
 617          $taxonomies = get_object_taxonomies( $post_type, 'objects' );
 618          $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
 619  
 620          /**
 621           * Filters the taxonomy columns in the Posts list table.
 622           *
 623           * The dynamic portion of the hook name, `$post_type`, refers to the post
 624           * type slug.
 625           *
 626           * @since 3.5.0
 627           *
 628           * @param string[] $taxonomies Array of taxonomy names to show columns for.
 629           * @param string   $post_type  The post type.
 630           */
 631          $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
 632          $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
 633  
 634          foreach ( $taxonomies as $taxonomy ) {
 635              if ( 'category' === $taxonomy ) {
 636                  $column_key = 'categories';
 637              } elseif ( 'post_tag' === $taxonomy ) {
 638                  $column_key = 'tags';
 639              } else {
 640                  $column_key = 'taxonomy-' . $taxonomy;
 641              }
 642  
 643              $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
 644          }
 645  
 646          $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
 647          if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) {
 648              $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
 649          }
 650  
 651          $posts_columns['date'] = __( 'Date' );
 652  
 653          if ( 'page' === $post_type ) {
 654  
 655              /**
 656               * Filters the columns displayed in the Pages list table.
 657               *
 658               * @since 2.5.0
 659               *
 660               * @param string[] $post_columns An associative array of column headings.
 661               */
 662              $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
 663          } else {
 664  
 665              /**
 666               * Filters the columns displayed in the Posts list table.
 667               *
 668               * @since 1.5.0
 669               *
 670               * @param string[] $post_columns An associative array of column headings.
 671               * @param string   $post_type    The post type slug.
 672               */
 673              $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
 674          }
 675  
 676          /**
 677           * Filters the columns displayed in the Posts list table for a specific post type.
 678           *
 679           * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
 680           *
 681           * @since 3.0.0
 682           *
 683           * @param string[] $post_columns An associative array of column headings.
 684           */
 685          return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
 686      }
 687  
 688      /**
 689       * @return array
 690       */
 691  	protected function get_sortable_columns() {
 692          return array(
 693              'title'    => 'title',
 694              'parent'   => 'parent',
 695              'comments' => 'comment_count',
 696              'date'     => array( 'date', true ),
 697          );
 698      }
 699  
 700      /**
 701       * @global WP_Query $wp_query WordPress Query object.
 702       * @global int $per_page
 703       * @param array $posts
 704       * @param int $level
 705       */
 706  	public function display_rows( $posts = array(), $level = 0 ) {
 707          global $wp_query, $per_page;
 708  
 709          if ( empty( $posts ) ) {
 710              $posts = $wp_query->posts;
 711          }
 712  
 713          add_filter( 'the_title', 'esc_html' );
 714  
 715          if ( $this->hierarchical_display ) {
 716              $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
 717          } else {
 718              $this->_display_rows( $posts, $level );
 719          }
 720      }
 721  
 722      /**
 723       * @param array $posts
 724       * @param int $level
 725       */
 726  	private function _display_rows( $posts, $level = 0 ) {
 727          $post_type = $this->screen->post_type;
 728  
 729          // Create array of post IDs.
 730          $post_ids = array();
 731  
 732          foreach ( $posts as $a_post ) {
 733              $post_ids[] = $a_post->ID;
 734          }
 735  
 736          if ( post_type_supports( $post_type, 'comments' ) ) {
 737              $this->comment_pending_count = get_pending_comments_num( $post_ids );
 738          }
 739  
 740          foreach ( $posts as $post ) {
 741              $this->single_row( $post, $level );
 742          }
 743      }
 744  
 745      /**
 746       * @global wpdb    $wpdb WordPress database abstraction object.
 747       * @global WP_Post $post Global post object.
 748       * @param array $pages
 749       * @param int $pagenum
 750       * @param int $per_page
 751       */
 752  	private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
 753          global $wpdb;
 754  
 755          $level = 0;
 756  
 757          if ( ! $pages ) {
 758              $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
 759  
 760              if ( ! $pages ) {
 761                  return;
 762              }
 763          }
 764  
 765          /*
 766           * Arrange pages into two parts: top level pages and children_pages
 767           * children_pages is two dimensional array, eg.
 768           * children_pages[10][] contains all sub-pages whose parent is 10.
 769           * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
 770           * If searching, ignore hierarchy and treat everything as top level
 771           */
 772          if ( empty( $_REQUEST['s'] ) ) {
 773  
 774              $top_level_pages = array();
 775              $children_pages  = array();
 776  
 777              foreach ( $pages as $page ) {
 778  
 779                  // Catch and repair bad pages.
 780                  if ( $page->post_parent == $page->ID ) {
 781                      $page->post_parent = 0;
 782                      $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
 783                      clean_post_cache( $page );
 784                  }
 785  
 786                  if ( 0 == $page->post_parent ) {
 787                      $top_level_pages[] = $page;
 788                  } else {
 789                      $children_pages[ $page->post_parent ][] = $page;
 790                  }
 791              }
 792  
 793              $pages = &$top_level_pages;
 794          }
 795  
 796          $count      = 0;
 797          $start      = ( $pagenum - 1 ) * $per_page;
 798          $end        = $start + $per_page;
 799          $to_display = array();
 800  
 801          foreach ( $pages as $page ) {
 802              if ( $count >= $end ) {
 803                  break;
 804              }
 805  
 806              if ( $count >= $start ) {
 807                  $to_display[ $page->ID ] = $level;
 808              }
 809  
 810              $count++;
 811  
 812              if ( isset( $children_pages ) ) {
 813                  $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
 814              }
 815          }
 816  
 817          // If it is the last pagenum and there are orphaned pages, display them with paging as well.
 818          if ( isset( $children_pages ) && $count < $end ) {
 819              foreach ( $children_pages as $orphans ) {
 820                  foreach ( $orphans as $op ) {
 821                      if ( $count >= $end ) {
 822                          break;
 823                      }
 824  
 825                      if ( $count >= $start ) {
 826                          $to_display[ $op->ID ] = 0;
 827                      }
 828  
 829                      $count++;
 830                  }
 831              }
 832          }
 833  
 834          $ids = array_keys( $to_display );
 835          _prime_post_caches( $ids );
 836  
 837          if ( ! isset( $GLOBALS['post'] ) ) {
 838              $GLOBALS['post'] = reset( $ids );
 839          }
 840  
 841          foreach ( $to_display as $page_id => $level ) {
 842              echo "\t";
 843              $this->single_row( $page_id, $level );
 844          }
 845      }
 846  
 847      /**
 848       * Given a top level page ID, display the nested hierarchy of sub-pages
 849       * together with paging support
 850       *
 851       * @since 3.1.0 (Standalone function exists since 2.6.0)
 852       * @since 4.2.0 Added the `$to_display` parameter.
 853       *
 854       * @param array $children_pages
 855       * @param int $count
 856       * @param int $parent
 857       * @param int $level
 858       * @param int $pagenum
 859       * @param int $per_page
 860       * @param array $to_display List of pages to be displayed. Passed by reference.
 861       */
 862  	private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
 863          if ( ! isset( $children_pages[ $parent ] ) ) {
 864              return;
 865          }
 866  
 867          $start = ( $pagenum - 1 ) * $per_page;
 868          $end   = $start + $per_page;
 869  
 870          foreach ( $children_pages[ $parent ] as $page ) {
 871              if ( $count >= $end ) {
 872                  break;
 873              }
 874  
 875              // If the page starts in a subtree, print the parents.
 876              if ( $count == $start && $page->post_parent > 0 ) {
 877                  $my_parents = array();
 878                  $my_parent  = $page->post_parent;
 879                  while ( $my_parent ) {
 880                      // Get the ID from the list or the attribute if my_parent is an object
 881                      $parent_id = $my_parent;
 882                      if ( is_object( $my_parent ) ) {
 883                          $parent_id = $my_parent->ID;
 884                      }
 885  
 886                      $my_parent    = get_post( $parent_id );
 887                      $my_parents[] = $my_parent;
 888                      if ( ! $my_parent->post_parent ) {
 889                          break;
 890                      }
 891                      $my_parent = $my_parent->post_parent;
 892                  }
 893                  $num_parents = count( $my_parents );
 894                  while ( $my_parent = array_pop( $my_parents ) ) {
 895                      $to_display[ $my_parent->ID ] = $level - $num_parents;
 896                      $num_parents--;
 897                  }
 898              }
 899  
 900              if ( $count >= $start ) {
 901                  $to_display[ $page->ID ] = $level;
 902              }
 903  
 904              $count++;
 905  
 906              $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
 907          }
 908  
 909          unset( $children_pages[ $parent ] ); //required in order to keep track of orphans
 910      }
 911  
 912      /**
 913       * Handles the checkbox column output.
 914       *
 915       * @since 4.3.0
 916       *
 917       * @param WP_Post $post The current WP_Post object.
 918       */
 919  	public function column_cb( $post ) {
 920          if ( current_user_can( 'edit_post', $post->ID ) ) :
 921              ?>
 922              <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>">
 923                  <?php
 924                      /* translators: %s: Post title. */
 925                      printf( __( 'Select %s' ), _draft_or_post_title() );
 926                  ?>
 927              </label>
 928              <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
 929              <div class="locked-indicator">
 930                  <span class="locked-indicator-icon" aria-hidden="true"></span>
 931                  <span class="screen-reader-text">
 932                  <?php
 933                  printf(
 934                      /* translators: %s: Post title. */
 935                      __( '&#8220;%s&#8221; is locked' ),
 936                      _draft_or_post_title()
 937                  );
 938                  ?>
 939                  </span>
 940              </div>
 941              <?php
 942          endif;
 943      }
 944  
 945      /**
 946       * @since 4.3.0
 947       *
 948       * @param WP_Post $post
 949       * @param string  $classes
 950       * @param string  $data
 951       * @param string  $primary
 952       */
 953  	protected function _column_title( $post, $classes, $data, $primary ) {
 954          echo '<td class="' . $classes . ' page-title" ', $data, '>';
 955          echo $this->column_title( $post );
 956          echo $this->handle_row_actions( $post, 'title', $primary );
 957          echo '</td>';
 958      }
 959  
 960      /**
 961       * Handles the title column output.
 962       *
 963       * @since 4.3.0
 964       *
 965       * @global string $mode List table view mode.
 966       *
 967       * @param WP_Post $post The current WP_Post object.
 968       */
 969  	public function column_title( $post ) {
 970          global $mode;
 971  
 972          if ( $this->hierarchical_display ) {
 973              if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
 974                  // Sent level 0 by accident, by default, or because we don't know the actual level.
 975                  $find_main_page = (int) $post->post_parent;
 976                  while ( $find_main_page > 0 ) {
 977                      $parent = get_post( $find_main_page );
 978  
 979                      if ( is_null( $parent ) ) {
 980                          break;
 981                      }
 982  
 983                      $this->current_level++;
 984                      $find_main_page = (int) $parent->post_parent;
 985  
 986                      if ( ! isset( $parent_name ) ) {
 987                          /** This filter is documented in wp-includes/post-template.php */
 988                          $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
 989                      }
 990                  }
 991              }
 992          }
 993  
 994          $can_edit_post = current_user_can( 'edit_post', $post->ID );
 995  
 996          if ( $can_edit_post && $post->post_status != 'trash' ) {
 997              $lock_holder = wp_check_post_lock( $post->ID );
 998  
 999              if ( $lock_holder ) {
1000                  $lock_holder   = get_userdata( $lock_holder );
1001                  $locked_avatar = get_avatar( $lock_holder->ID, 18 );
1002                  /* translators: %s: User's display name. */
1003                  $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
1004              } else {
1005                  $locked_avatar = '';
1006                  $locked_text   = '';
1007              }
1008  
1009              echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
1010          }
1011  
1012          $pad = str_repeat( '&#8212; ', $this->current_level );
1013          echo '<strong>';
1014  
1015          $title = _draft_or_post_title();
1016  
1017          if ( $can_edit_post && $post->post_status != 'trash' ) {
1018              printf(
1019                  '<a class="row-title" href="%s" aria-label="%s">%s%s</a>',
1020                  get_edit_post_link( $post->ID ),
1021                  /* translators: %s: Post title. */
1022                  esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) ),
1023                  $pad,
1024                  $title
1025              );
1026          } else {
1027              printf(
1028                  '<span>%s%s</span>',
1029                  $pad,
1030                  $title
1031              );
1032          }
1033          _post_states( $post );
1034  
1035          if ( isset( $parent_name ) ) {
1036              $post_type_object = get_post_type_object( $post->post_type );
1037              echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
1038          }
1039          echo "</strong>\n";
1040  
1041          if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
1042              if ( post_password_required( $post ) ) {
1043                  echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
1044              } else {
1045                  echo esc_html( get_the_excerpt() );
1046              }
1047          }
1048  
1049          get_inline_data( $post );
1050      }
1051  
1052      /**
1053       * Handles the post date column output.
1054       *
1055       * @since 4.3.0
1056       *
1057       * @global string $mode List table view mode.
1058       *
1059       * @param WP_Post $post The current WP_Post object.
1060       */
1061  	public function column_date( $post ) {
1062          global $mode;
1063  
1064          if ( '0000-00-00 00:00:00' === $post->post_date ) {
1065              $t_time    = __( 'Unpublished' );
1066              $h_time    = $t_time;
1067              $time_diff = 0;
1068          } else {
1069              $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
1070              $m_time = $post->post_date;
1071              $time   = get_post_time( 'G', true, $post );
1072  
1073              $time_diff = time() - $time;
1074  
1075              if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
1076                  /* translators: %s: Human-readable time difference. */
1077                  $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
1078              } else {
1079                  $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
1080              }
1081          }
1082  
1083          if ( 'publish' === $post->post_status ) {
1084              $status = __( 'Published' );
1085          } elseif ( 'future' === $post->post_status ) {
1086              if ( $time_diff > 0 ) {
1087                  $status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
1088              } else {
1089                  $status = __( 'Scheduled' );
1090              }
1091          } else {
1092              $status = __( 'Last Modified' );
1093          }
1094  
1095          /**
1096           * Filters the status text of the post.
1097           *
1098           * @since 4.8.0
1099           *
1100           * @param string  $status      The status text.
1101           * @param WP_Post $post        Post object.
1102           * @param string  $column_name The column name.
1103           * @param string  $mode        The list display mode ('excerpt' or 'list').
1104           */
1105          $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
1106  
1107          if ( $status ) {
1108              echo $status . '<br />';
1109          }
1110  
1111          if ( 'excerpt' === $mode ) {
1112              /**
1113               * Filters the published time of the post.
1114               *
1115               * If `$mode` equals 'excerpt', the published time and date are both displayed.
1116               * If `$mode` equals 'list' (default), the publish date is displayed, with the
1117               * time and date together available as an abbreviation definition.
1118               *
1119               * @since 2.5.1
1120               *
1121               * @param string  $t_time      The published time.
1122               * @param WP_Post $post        Post object.
1123               * @param string  $column_name The column name.
1124               * @param string  $mode        The list display mode ('excerpt' or 'list').
1125               */
1126              echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
1127          } else {
1128  
1129              /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
1130              echo '<span title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</span>';
1131          }
1132      }
1133  
1134      /**
1135       * Handles the comments column output.
1136       *
1137       * @since 4.3.0
1138       *
1139       * @param WP_Post $post The current WP_Post object.
1140       */
1141  	public function column_comments( $post ) {
1142          ?>
1143          <div class="post-com-count-wrapper">
1144          <?php
1145              $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
1146  
1147              $this->comments_bubble( $post->ID, $pending_comments );
1148          ?>
1149          </div>
1150          <?php
1151      }
1152  
1153      /**
1154       * Handles the post author column output.
1155       *
1156       * @since 4.3.0
1157       *
1158       * @param WP_Post $post The current WP_Post object.
1159       */
1160  	public function column_author( $post ) {
1161          $args = array(
1162              'post_type' => $post->post_type,
1163              'author'    => get_the_author_meta( 'ID' ),
1164          );
1165          echo $this->get_edit_link( $args, get_the_author() );
1166      }
1167  
1168      /**
1169       * Handles the default column output.
1170       *
1171       * @since 4.3.0
1172       *
1173       * @param WP_Post $post        The current WP_Post object.
1174       * @param string  $column_name The current column name.
1175       */
1176  	public function column_default( $post, $column_name ) {
1177          if ( 'categories' === $column_name ) {
1178              $taxonomy = 'category';
1179          } elseif ( 'tags' === $column_name ) {
1180              $taxonomy = 'post_tag';
1181          } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
1182              $taxonomy = substr( $column_name, 9 );
1183          } else {
1184              $taxonomy = false;
1185          }
1186          if ( $taxonomy ) {
1187              $taxonomy_object = get_taxonomy( $taxonomy );
1188              $terms           = get_the_terms( $post->ID, $taxonomy );
1189              if ( is_array( $terms ) ) {
1190                  $term_links = array();
1191                  foreach ( $terms as $t ) {
1192                      $posts_in_term_qv = array();
1193                      if ( 'post' != $post->post_type ) {
1194                          $posts_in_term_qv['post_type'] = $post->post_type;
1195                      }
1196                      if ( $taxonomy_object->query_var ) {
1197                          $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
1198                      } else {
1199                          $posts_in_term_qv['taxonomy'] = $taxonomy;
1200                          $posts_in_term_qv['term']     = $t->slug;
1201                      }
1202  
1203                      $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
1204  
1205                      $term_links[] = $this->get_edit_link( $posts_in_term_qv, $label );
1206                  }
1207  
1208                  /**
1209                   * Filters the links in `$taxonomy` column of edit.php.
1210                   *
1211                   * @since 5.2.0
1212                   *
1213                   * @param array  $term_links List of links to edit.php, filtered by the taxonomy term.
1214                   * @param string $taxonomy   Taxonomy name.
1215                   * @param array  $terms      Array of terms appearing in the post row.
1216                   */
1217                  $term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
1218  
1219                  /* translators: Used between list items, there is a space after the comma. */
1220                  echo join( __( ', ' ), $term_links );
1221              } else {
1222                  echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
1223              }
1224              return;
1225          }
1226  
1227          if ( is_post_type_hierarchical( $post->post_type ) ) {
1228  
1229              /**
1230               * Fires in each custom column on the Posts list table.
1231               *
1232               * This hook only fires if the current post type is hierarchical,
1233               * such as pages.
1234               *
1235               * @since 2.5.0
1236               *
1237               * @param string $column_name The name of the column to display.
1238               * @param int    $post_id     The current post ID.
1239               */
1240              do_action( 'manage_pages_custom_column', $column_name, $post->ID );
1241          } else {
1242  
1243              /**
1244               * Fires in each custom column in the Posts list table.
1245               *
1246               * This hook only fires if the current post type is non-hierarchical,
1247               * such as posts.
1248               *
1249               * @since 1.5.0
1250               *
1251               * @param string $column_name The name of the column to display.
1252               * @param int    $post_id     The current post ID.
1253               */
1254              do_action( 'manage_posts_custom_column', $column_name, $post->ID );
1255          }
1256  
1257          /**
1258           * Fires for each custom column of a specific post type in the Posts list table.
1259           *
1260           * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
1261           *
1262           * @since 3.1.0
1263           *
1264           * @param string $column_name The name of the column to display.
1265           * @param int    $post_id     The current post ID.
1266           */
1267          do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
1268      }
1269  
1270      /**
1271       * @global WP_Post $post Global post object.
1272       *
1273       * @param int|WP_Post $post
1274       * @param int         $level
1275       */
1276  	public function single_row( $post, $level = 0 ) {
1277          $global_post = get_post();
1278  
1279          $post                = get_post( $post );
1280          $this->current_level = $level;
1281  
1282          $GLOBALS['post'] = $post;
1283          setup_postdata( $post );
1284  
1285          $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
1286  
1287          $lock_holder = wp_check_post_lock( $post->ID );
1288          if ( $lock_holder ) {
1289              $classes .= ' wp-locked';
1290          }
1291  
1292          if ( $post->post_parent ) {
1293              $count    = count( get_post_ancestors( $post->ID ) );
1294              $classes .= ' level-' . $count;
1295          } else {
1296              $classes .= ' level-0';
1297          }
1298          ?>
1299          <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
1300              <?php $this->single_row_columns( $post ); ?>
1301          </tr>
1302          <?php
1303          $GLOBALS['post'] = $global_post;
1304      }
1305  
1306      /**
1307       * Gets the name of the default primary column.
1308       *
1309       * @since 4.3.0
1310       *
1311       * @return string Name of the default primary column, in this case, 'title'.
1312       */
1313  	protected function get_default_primary_column_name() {
1314          return 'title';
1315      }
1316  
1317      /**
1318       * Generates and displays row action links.
1319       *
1320       * @since 4.3.0
1321       *
1322       * @param object $post        Post being acted upon.
1323       * @param string $column_name Current column name.
1324       * @param string $primary     Primary column name.
1325       * @return string Row actions output for posts.
1326       */
1327  	protected function handle_row_actions( $post, $column_name, $primary ) {
1328          if ( $primary !== $column_name ) {
1329              return '';
1330          }
1331  
1332          $post_type_object = get_post_type_object( $post->post_type );
1333          $can_edit_post    = current_user_can( 'edit_post', $post->ID );
1334          $actions          = array();
1335          $title            = _draft_or_post_title();
1336  
1337          if ( $can_edit_post && 'trash' != $post->post_status ) {
1338              $actions['edit'] = sprintf(
1339                  '<a href="%s" aria-label="%s">%s</a>',
1340                  get_edit_post_link( $post->ID ),
1341                  /* translators: %s: Post title. */
1342                  esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
1343                  __( 'Edit' )
1344              );
1345  
1346              if ( 'wp_block' !== $post->post_type ) {
1347                  $actions['inline hide-if-no-js'] = sprintf(
1348                      '<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
1349                      /* translators: %s: Post title. */
1350                      esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $title ) ),
1351                      __( 'Quick&nbsp;Edit' )
1352                  );
1353              }
1354          }
1355  
1356          if ( current_user_can( 'delete_post', $post->ID ) ) {
1357              if ( 'trash' === $post->post_status ) {
1358                  $actions['untrash'] = sprintf(
1359                      '<a href="%s" aria-label="%s">%s</a>',
1360                      wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
1361                      /* translators: %s: Post title. */
1362                      esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $title ) ),
1363                      __( 'Restore' )
1364                  );
1365              } elseif ( EMPTY_TRASH_DAYS ) {
1366                  $actions['trash'] = sprintf(
1367                      '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1368                      get_delete_post_link( $post->ID ),
1369                      /* translators: %s: Post title. */
1370                      esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $title ) ),
1371                      _x( 'Trash', 'verb' )
1372                  );
1373              }
1374              if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
1375                  $actions['delete'] = sprintf(
1376                      '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1377                      get_delete_post_link( $post->ID, '', true ),
1378                      /* translators: %s: Post title. */
1379                      esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $title ) ),
1380                      __( 'Delete Permanently' )
1381                  );
1382              }
1383          }
1384  
1385          if ( is_post_type_viewable( $post_type_object ) ) {
1386              if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
1387                  if ( $can_edit_post ) {
1388                      $preview_link    = get_preview_post_link( $post );
1389                      $actions['view'] = sprintf(
1390                          '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1391                          esc_url( $preview_link ),
1392                          /* translators: %s: Post title. */
1393                          esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ),
1394                          __( 'Preview' )
1395                      );
1396                  }
1397              } elseif ( 'trash' != $post->post_status ) {
1398                  $actions['view'] = sprintf(
1399                      '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1400                      get_permalink( $post->ID ),
1401                      /* translators: %s: Post title. */
1402                      esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ),
1403                      __( 'View' )
1404                  );
1405              }
1406          }
1407  
1408          if ( 'wp_block' === $post->post_type ) {
1409              $actions['export'] = sprintf(
1410                  '<button type="button" class="wp-list-reusable-blocks__export button-link" data-id="%s" aria-label="%s">%s</button>',
1411                  $post->ID,
1412                  /* translators: %s: Post title. */
1413                  esc_attr( sprintf( __( 'Export &#8220;%s&#8221; as JSON' ), $title ) ),
1414                  __( 'Export as JSON' )
1415              );
1416          }
1417  
1418          if ( is_post_type_hierarchical( $post->post_type ) ) {
1419  
1420              /**
1421               * Filters the array of row action links on the Pages list table.
1422               *
1423               * The filter is evaluated only for hierarchical post types.
1424               *
1425               * @since 2.8.0
1426               *
1427               * @param string[] $actions An array of row action links. Defaults are
1428               *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1429               *                          'Delete Permanently', 'Preview', and 'View'.
1430               * @param WP_Post  $post    The post object.
1431               */
1432              $actions = apply_filters( 'page_row_actions', $actions, $post );
1433          } else {
1434  
1435              /**
1436               * Filters the array of row action links on the Posts list table.
1437               *
1438               * The filter is evaluated only for non-hierarchical post types.
1439               *
1440               * @since 2.8.0
1441               *
1442               * @param string[] $actions An array of row action links. Defaults are
1443               *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1444               *                          'Delete Permanently', 'Preview', and 'View'.
1445               * @param WP_Post  $post    The post object.
1446               */
1447              $actions = apply_filters( 'post_row_actions', $actions, $post );
1448          }
1449  
1450          return $this->row_actions( $actions );
1451      }
1452  
1453      /**
1454       * Outputs the hidden row displayed when inline editing
1455       *
1456       * @since 3.1.0
1457       *
1458       * @global string $mode List table view mode.
1459       */
1460  	public function inline_edit() {
1461          global $mode;
1462  
1463          $screen = $this->screen;
1464  
1465          $post             = get_default_post_to_edit( $screen->post_type );
1466          $post_type_object = get_post_type_object( $screen->post_type );
1467  
1468          $taxonomy_names          = get_object_taxonomies( $screen->post_type );
1469          $hierarchical_taxonomies = array();
1470          $flat_taxonomies         = array();
1471          foreach ( $taxonomy_names as $taxonomy_name ) {
1472  
1473              $taxonomy = get_taxonomy( $taxonomy_name );
1474  
1475              $show_in_quick_edit = $taxonomy->show_in_quick_edit;
1476  
1477              /**
1478               * Filters whether the current taxonomy should be shown in the Quick Edit panel.
1479               *
1480               * @since 4.2.0
1481               *
1482               * @param bool   $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1483               * @param string $taxonomy_name      Taxonomy name.
1484               * @param string $post_type          Post type of current Quick Edit post.
1485               */
1486              if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1487                  continue;
1488              }
1489  
1490              if ( $taxonomy->hierarchical ) {
1491                  $hierarchical_taxonomies[] = $taxonomy;
1492              } else {
1493                  $flat_taxonomies[] = $taxonomy;
1494              }
1495          }
1496  
1497          $m            = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
1498          $can_publish  = current_user_can( $post_type_object->cap->publish_posts );
1499          $core_columns = array(
1500              'cb'         => true,
1501              'date'       => true,
1502              'title'      => true,
1503              'categories' => true,
1504              'tags'       => true,
1505              'comments'   => true,
1506              'author'     => true,
1507          );
1508  
1509          ?>
1510  
1511      <form method="get"><table style="display: none"><tbody id="inlineedit">
1512          <?php
1513          $hclass              = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1514          $inline_edit_classes = "inline-edit-row inline-edit-row-$hclass";
1515          $bulk_edit_classes   = "bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}";
1516          $quick_edit_classes  = "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}";
1517  
1518          $bulk = 0;
1519          while ( $bulk < 2 ) {
1520              ?>
1521  
1522          <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="
1523                              <?php
1524                              echo $inline_edit_classes . ' ';
1525                              echo $bulk ? $bulk_edit_classes : $quick_edit_classes;
1526                              ?>
1527          " style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1528  
1529          <fieldset class="inline-edit-col-left">
1530              <legend class="inline-edit-legend"><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></legend>
1531              <div class="inline-edit-col">
1532              <?php
1533  
1534              if ( post_type_supports( $screen->post_type, 'title' ) ) :
1535                  if ( $bulk ) :
1536                      ?>
1537              <div id="bulk-title-div">
1538                  <div id="bulk-titles"></div>
1539              </div>
1540  
1541              <?php else : // $bulk ?>
1542  
1543              <label>
1544                  <span class="title"><?php _e( 'Title' ); ?></span>
1545                  <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
1546              </label>
1547  
1548                  <?php if ( is_post_type_viewable( $screen->post_type ) ) : // is_post_type_viewable check ?>
1549  
1550              <label>
1551                  <span class="title"><?php _e( 'Slug' ); ?></span>
1552                  <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
1553              </label>
1554  
1555                      <?php
1556      endif; // is_post_type_viewable check
1557      endif; // $bulk
1558      endif; // post_type_supports title
1559              ?>
1560  
1561              <?php if ( ! $bulk ) : ?>
1562              <fieldset class="inline-edit-date">
1563              <legend><span class="title"><?php _e( 'Date' ); ?></span></legend>
1564                  <?php touch_time( 1, 1, 0, 1 ); ?>
1565              </fieldset>
1566              <br class="clear" />
1567                  <?php
1568      endif; // $bulk
1569  
1570              if ( post_type_supports( $screen->post_type, 'author' ) ) :
1571                  $authors_dropdown = '';
1572  
1573                  if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) :
1574                      $users_opt = array(
1575                          'hide_if_only_one_author' => false,
1576                          'who'                     => 'authors',
1577                          'name'                    => 'post_author',
1578                          'class'                   => 'authors',
1579                          'multi'                   => 1,
1580                          'echo'                    => 0,
1581                          'show'                    => 'display_name_with_login',
1582                      );
1583                      if ( $bulk ) {
1584                          $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
1585                      }
1586  
1587                      $authors = wp_dropdown_users( $users_opt );
1588                      if ( $authors ) :
1589                          $authors_dropdown  = '<label class="inline-edit-author">';
1590                          $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1591                          $authors_dropdown .= $authors;
1592                          $authors_dropdown .= '</label>';
1593                      endif;
1594                  endif; // authors
1595                  ?>
1596  
1597                  <?php
1598                  if ( ! $bulk ) {
1599                      echo $authors_dropdown;}
1600      endif; // post_type_supports author
1601  
1602              if ( ! $bulk && $can_publish ) :
1603                  ?>
1604  
1605          <div class="inline-edit-group wp-clearfix">
1606              <label class="alignleft">
1607                  <span class="title"><?php _e( 'Password' ); ?></span>
1608                  <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
1609              </label>
1610  
1611              <em class="alignleft inline-edit-or">
1612                  <?php
1613                  /* translators: Between password field and private checkbox on post quick edit interface. */
1614                  _e( '&ndash;OR&ndash;' );
1615                  ?>
1616                  </em>
1617                  <label class="alignleft inline-edit-private">
1618                  <input type="checkbox" name="keep_private" value="private" />
1619                  <span class="checkbox-title"><?php _e( 'Private' ); ?></span>
1620                  </label>
1621              </div>
1622  
1623                  <?php endif; ?>
1624  
1625          </div></fieldset>
1626  
1627              <?php if ( count( $hierarchical_taxonomies ) && ! $bulk ) : ?>
1628  
1629          <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
1630  
1631                  <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
1632  
1633              <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ); ?></span>
1634              <input type="hidden" name="<?php echo ( $taxonomy->name === 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
1635              <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name ); ?>-checklist">
1636                      <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ); ?>
1637              </ul>
1638  
1639      <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
1640  
1641          </div></fieldset>
1642  
1643      <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
1644  
1645          <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
1646  
1647              <?php
1648              if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) {
1649                  echo $authors_dropdown;
1650              }
1651  
1652              if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
1653  
1654                  if ( $post_type_object->hierarchical ) :
1655                      ?>
1656          <label>
1657              <span class="title"><?php _e( 'Parent' ); ?></span>
1658                      <?php
1659                      $dropdown_args = array(
1660                          'post_type'         => $post_type_object->name,
1661                          'selected'          => $post->post_parent,
1662                          'name'              => 'post_parent',
1663                          'show_option_none'  => __( 'Main Page (no parent)' ),
1664                          'option_none_value' => 0,
1665                          'sort_column'       => 'menu_order, post_title',
1666                      );
1667  
1668                      if ( $bulk ) {
1669                          $dropdown_args['show_option_no_change'] = __( '&mdash; No Change &mdash;' );
1670                      }
1671  
1672                      /**
1673                       * Filters the arguments used to generate the Quick Edit page-parent drop-down.
1674                       *
1675                       * @since 2.7.0
1676                       *
1677                       * @see wp_dropdown_pages()
1678                       *
1679                       * @param array $dropdown_args An array of arguments.
1680                       */
1681                      $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
1682  
1683                      wp_dropdown_pages( $dropdown_args );
1684                      ?>
1685          </label>
1686  
1687                      <?php
1688                  endif; // hierarchical
1689  
1690                  if ( ! $bulk ) :
1691                      ?>
1692  
1693              <label>
1694                  <span class="title"><?php _e( 'Order' ); ?></span>
1695                  <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order; ?>" /></span>
1696              </label>
1697  
1698                      <?php
1699                  endif; // !$bulk
1700          endif; // page-attributes
1701              ?>
1702  
1703              <?php if ( 0 < count( get_page_templates( null, $screen->post_type ) ) ) : ?>
1704          <label>
1705              <span class="title"><?php _e( 'Template' ); ?></span>
1706              <select name="page_template">
1707                  <?php    if ( $bulk ) : ?>
1708                  <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1709                  <?php    endif; // $bulk ?>
1710                  <?php
1711                  /** This filter is documented in wp-admin/includes/meta-boxes.php */
1712                  $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );
1713                  ?>
1714                  <option value="default"><?php echo esc_html( $default_title ); ?></option>
1715                  <?php page_template_dropdown( '', $screen->post_type ); ?>
1716              </select>
1717          </label>
1718      <?php endif; ?>
1719  
1720              <?php if ( count( $flat_taxonomies ) && ! $bulk ) : ?>
1721  
1722                  <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
1723                      <?php
1724                      if ( current_user_can( $taxonomy->cap->assign_terms ) ) :
1725                          $taxonomy_name = esc_attr( $taxonomy->name );
1726  
1727                          ?>
1728              <label class="inline-edit-tags">
1729                  <span class="title"><?php echo esc_html( $taxonomy->labels->name ); ?></span>
1730                  <textarea data-wp-taxonomy="<?php echo $taxonomy_name; ?>" cols="22" rows="1" name="tax_input[<?php echo $taxonomy_name; ?>]" class="tax_input_<?php echo $taxonomy_name; ?>"></textarea>
1731              </label>
1732                      <?php endif; ?>
1733  
1734      <?php endforeach; //$flat_taxonomies as $taxonomy ?>
1735  
1736      <?php endif; // count( $flat_taxonomies ) && !$bulk ?>
1737  
1738              <?php
1739              if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
1740                  if ( $bulk ) :
1741                      ?>
1742  
1743              <div class="inline-edit-group wp-clearfix">
1744                      <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1745              <label class="alignleft">
1746                  <span class="title"><?php _e( 'Comments' ); ?></span>
1747                  <select name="comment_status">
1748                      <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1749                      <option value="open"><?php _e( 'Allow' ); ?></option>
1750                      <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1751                  </select>
1752              </label>
1753          <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1754              <label class="alignright">
1755                  <span class="title"><?php _e( 'Pings' ); ?></span>
1756                  <select name="ping_status">
1757                      <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1758                      <option value="open"><?php _e( 'Allow' ); ?></option>
1759                      <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1760                  </select>
1761              </label>
1762          <?php endif; ?>
1763              </div>
1764  
1765              <?php else : // $bulk ?>
1766  
1767              <div class="inline-edit-group wp-clearfix">
1768                  <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1769                  <label class="alignleft">
1770                      <input type="checkbox" name="comment_status" value="open" />
1771                      <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
1772                  </label>
1773              <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1774                  <label class="alignleft">
1775                      <input type="checkbox" name="ping_status" value="open" />
1776                      <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
1777                  </label>
1778              <?php endif; ?>
1779              </div>
1780  
1781                  <?php
1782      endif; // $bulk
1783      endif; // post_type_supports comments or pings
1784              ?>
1785  
1786              <div class="inline-edit-group wp-clearfix">
1787                  <label class="inline-edit-status alignleft">
1788                      <span class="title"><?php _e( 'Status' ); ?></span>
1789                      <select name="_status">
1790              <?php if ( $bulk ) : ?>
1791                          <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1792      <?php endif; // $bulk ?>
1793                      <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
1794                          <option value="publish"><?php _e( 'Published' ); ?></option>
1795                          <option value="future"><?php _e( 'Scheduled' ); ?></option>
1796                          <?php if ( $bulk ) : ?>
1797                          <option value="private"><?php _e( 'Private' ); ?></option>
1798      <?php endif; // $bulk ?>
1799                      <?php endif; ?>
1800                          <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1801                          <option value="draft"><?php _e( 'Draft' ); ?></option>
1802                      </select>
1803                  </label>
1804  
1805              <?php if ( 'post' === $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1806  
1807                  <?php    if ( $bulk ) : ?>
1808  
1809                  <label class="alignright">
1810                      <span class="title"><?php _e( 'Sticky' ); ?></span>
1811                      <select name="sticky">
1812                          <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1813                          <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1814                          <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1815                      </select>
1816                  </label>
1817  
1818      <?php    else : // $bulk ?>
1819  
1820                  <label class="alignleft">
1821                      <input type="checkbox" name="sticky" value="sticky" />
1822                      <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1823                  </label>
1824  
1825      <?php    endif; // $bulk ?>
1826  
1827      <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
1828  
1829              </div>
1830  
1831              <?php
1832  
1833              if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) {
1834                  $post_formats = get_theme_support( 'post-formats' );
1835  
1836                  ?>
1837          <label class="alignleft">
1838          <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1839          <select name="post_format">
1840              <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1841              <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
1842                  <?php
1843                  if ( is_array( $post_formats[0] ) ) {
1844                      foreach ( $post_formats[0] as $format ) {
1845                          ?>
1846                      <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
1847                          <?php
1848                      }
1849                  }
1850                  ?>
1851          </select></label>
1852                  <?php
1853  
1854              }
1855  
1856              ?>
1857  
1858          </div></fieldset>
1859  
1860              <?php
1861              list( $columns ) = $this->get_column_info();
1862  
1863              foreach ( $columns as $column_name => $column_display_name ) {
1864                  if ( isset( $core_columns[ $column_name ] ) ) {
1865                      continue;
1866                  }
1867  
1868                  if ( $bulk ) {
1869  
1870                      /**
1871                       * Fires once for each column in Bulk Edit mode.
1872                       *
1873                       * @since 2.7.0
1874                       *
1875                       * @param string $column_name Name of the column to edit.
1876                       * @param string $post_type   The post type slug.
1877                       */
1878                      do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
1879                  } else {
1880  
1881                      /**
1882                       * Fires once for each column in Quick Edit mode.
1883                       *
1884                       * @since 2.7.0
1885                       *
1886                       * @param string $column_name Name of the column to edit.
1887                       * @param string $post_type   The post type slug, or current screen name if this is a taxonomy list table.
1888                       * @param string $taxonomy    The taxonomy name, if any.
1889                       */
1890                      do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' );
1891                  }
1892              }
1893              ?>
1894          <div class="submit inline-edit-save">
1895              <button type="button" class="button cancel alignleft"><?php _e( 'Cancel' ); ?></button>
1896              <?php
1897              if ( ! $bulk ) {
1898                  wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
1899                  ?>
1900                  <button type="button" class="button button-primary save alignright"><?php _e( 'Update' ); ?></button>
1901                  <span class="spinner"></span>
1902                  <?php
1903              } else {
1904                  submit_button( __( 'Update' ), 'primary alignright', 'bulk_edit', false );
1905              }
1906              ?>
1907              <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1908              <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1909              <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
1910                  <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
1911              <?php } ?>
1912              <br class="clear" />
1913              <div class="notice notice-error notice-alt inline hidden">
1914                  <p class="error"></p>
1915              </div>
1916          </div>
1917          </td></tr>
1918              <?php
1919              $bulk++;
1920          }
1921          ?>
1922          </tbody></table></form>
1923          <?php
1924      }
1925  }


Generated: Sat Sep 21 01:00:03 2019 Cross-referenced by PHPXref 0.7.1