[ 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 string   $mode             List table view mode.
 139       * @global array    $avail_post_stati
 140       * @global WP_Query $wp_query         WordPress Query object.
 141       * @global int      $per_page
 142       */
 143  	public function prepare_items() {
 144          global $mode, $avail_post_stati, $wp_query, $per_page;
 145  
 146          if ( ! empty( $_REQUEST['mode'] ) ) {
 147              $mode = 'excerpt' === $_REQUEST['mode'] ? 'excerpt' : 'list';
 148              set_user_setting( 'posts_list_mode', $mode );
 149          } else {
 150              $mode = get_user_setting( 'posts_list_mode', 'list' );
 151          }
 152  
 153          // Is going to call wp().
 154          $avail_post_stati = wp_edit_posts_query();
 155  
 156          $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
 157  
 158          $post_type = $this->screen->post_type;
 159          $per_page  = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
 160  
 161          /** This filter is documented in wp-admin/includes/post.php */
 162          $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
 163  
 164          if ( $this->hierarchical_display ) {
 165              $total_items = $wp_query->post_count;
 166          } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
 167              $total_items = $wp_query->found_posts;
 168          } else {
 169              $post_counts = (array) wp_count_posts( $post_type, 'readable' );
 170  
 171              if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'], $avail_post_stati, true ) ) {
 172                  $total_items = $post_counts[ $_REQUEST['post_status'] ];
 173              } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
 174                  $total_items = $this->sticky_posts_count;
 175              } elseif ( isset( $_GET['author'] ) && get_current_user_id() == $_GET['author'] ) {
 176                  $total_items = $this->user_posts_count;
 177              } else {
 178                  $total_items = array_sum( $post_counts );
 179  
 180                  // Subtract post types that are not included in the admin all list.
 181                  foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
 182                      $total_items -= $post_counts[ $state ];
 183                  }
 184              }
 185          }
 186  
 187          $this->is_trash = isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'];
 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, true ) || 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 ), true );
 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 slug.
 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           * @since 5.5.0 The `$post_type` parameter was added.
 480           *
 481           * @param bool   $disable   Whether to disable the drop-down. Default false.
 482           * @param string $post_type Post type slug.
 483           */
 484          if ( apply_filters( 'disable_formats_dropdown', false, $post_type ) ) {
 485              return;
 486          }
 487  
 488          // Return if the post type doesn't have post formats or if we're in the Trash.
 489          if ( ! is_object_in_taxonomy( $post_type, 'post_format' ) || $this->is_trash ) {
 490              return;
 491          }
 492  
 493          // Make sure the dropdown shows only formats with a post count greater than 0.
 494          $used_post_formats = get_terms(
 495              array(
 496                  'taxonomy'   => 'post_format',
 497                  'hide_empty' => true,
 498              )
 499          );
 500  
 501          // Return if there are no posts using formats.
 502          if ( ! $used_post_formats ) {
 503              return;
 504          }
 505  
 506          $displayed_post_format = isset( $_GET['post_format'] ) ? $_GET['post_format'] : '';
 507          ?>
 508          <label for="filter-by-format" class="screen-reader-text"><?php _e( 'Filter by post format' ); ?></label>
 509          <select name="post_format" id="filter-by-format">
 510              <option<?php selected( $displayed_post_format, '' ); ?> value=""><?php _e( 'All formats' ); ?></option>
 511              <?php
 512              foreach ( $used_post_formats as $used_post_format ) {
 513                  // Post format slug.
 514                  $slug = str_replace( 'post-format-', '', $used_post_format->slug );
 515                  // Pretty, translated version of the post format slug.
 516                  $pretty_name = get_post_format_string( $slug );
 517                  // Skip the standard post format.
 518                  if ( 'standard' === $slug ) {
 519                      continue;
 520                  }
 521                  ?>
 522                  <option<?php selected( $displayed_post_format, $slug ); ?> value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $pretty_name ); ?></option>
 523                  <?php
 524              }
 525              ?>
 526          </select>
 527          <?php
 528      }
 529  
 530      /**
 531       * @param string $which
 532       */
 533  	protected function extra_tablenav( $which ) {
 534          ?>
 535          <div class="alignleft actions">
 536          <?php
 537          if ( 'top' === $which ) {
 538              ob_start();
 539  
 540              $this->months_dropdown( $this->screen->post_type );
 541              $this->categories_dropdown( $this->screen->post_type );
 542              $this->formats_dropdown( $this->screen->post_type );
 543  
 544              /**
 545               * Fires before the Filter button on the Posts and Pages list tables.
 546               *
 547               * The Filter button allows sorting by date and/or category on the
 548               * Posts list table, and sorting by date on the Pages list table.
 549               *
 550               * @since 2.1.0
 551               * @since 4.4.0 The `$post_type` parameter was added.
 552               * @since 4.6.0 The `$which` parameter was added.
 553               *
 554               * @param string $post_type The post type slug.
 555               * @param string $which     The location of the extra table nav markup:
 556               *                          'top' or 'bottom' for WP_Posts_List_Table,
 557               *                          'bar' for WP_Media_List_Table.
 558               */
 559              do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
 560  
 561              $output = ob_get_clean();
 562  
 563              if ( ! empty( $output ) ) {
 564                  echo $output;
 565                  submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
 566              }
 567          }
 568  
 569          if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) {
 570              submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
 571          }
 572          ?>
 573          </div>
 574          <?php
 575          /**
 576           * Fires immediately following the closing "actions" div in the tablenav for the posts
 577           * list table.
 578           *
 579           * @since 4.4.0
 580           *
 581           * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
 582           */
 583          do_action( 'manage_posts_extra_tablenav', $which );
 584      }
 585  
 586      /**
 587       * @return string
 588       */
 589  	public function current_action() {
 590          if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
 591              return 'delete_all';
 592          }
 593  
 594          return parent::current_action();
 595      }
 596  
 597      /**
 598       * @global string $mode List table view mode.
 599       *
 600       * @return array
 601       */
 602  	protected function get_table_classes() {
 603          global $mode;
 604  
 605          $mode_class = esc_attr( 'table-view-' . $mode );
 606  
 607          return array( 'widefat', 'fixed', 'striped', $mode_class, is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
 608      }
 609  
 610      /**
 611       * @return array
 612       */
 613  	public function get_columns() {
 614          $post_type = $this->screen->post_type;
 615  
 616          $posts_columns = array();
 617  
 618          $posts_columns['cb'] = '<input type="checkbox" />';
 619  
 620          /* translators: Posts screen column name. */
 621          $posts_columns['title'] = _x( 'Title', 'column name' );
 622  
 623          if ( post_type_supports( $post_type, 'author' ) ) {
 624              $posts_columns['author'] = __( 'Author' );
 625          }
 626  
 627          $taxonomies = get_object_taxonomies( $post_type, 'objects' );
 628          $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
 629  
 630          /**
 631           * Filters the taxonomy columns in the Posts list table.
 632           *
 633           * The dynamic portion of the hook name, `$post_type`, refers to the post
 634           * type slug.
 635           *
 636           * @since 3.5.0
 637           *
 638           * @param string[] $taxonomies Array of taxonomy names to show columns for.
 639           * @param string   $post_type  The post type.
 640           */
 641          $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
 642          $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
 643  
 644          foreach ( $taxonomies as $taxonomy ) {
 645              if ( 'category' === $taxonomy ) {
 646                  $column_key = 'categories';
 647              } elseif ( 'post_tag' === $taxonomy ) {
 648                  $column_key = 'tags';
 649              } else {
 650                  $column_key = 'taxonomy-' . $taxonomy;
 651              }
 652  
 653              $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
 654          }
 655  
 656          $post_status = ! empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
 657          if ( post_type_supports( $post_type, 'comments' ) && ! in_array( $post_status, array( 'pending', 'draft', 'future' ), true ) ) {
 658              $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
 659          }
 660  
 661          $posts_columns['date'] = __( 'Date' );
 662  
 663          if ( 'page' === $post_type ) {
 664  
 665              /**
 666               * Filters the columns displayed in the Pages list table.
 667               *
 668               * @since 2.5.0
 669               *
 670               * @param string[] $post_columns An associative array of column headings.
 671               */
 672              $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
 673          } else {
 674  
 675              /**
 676               * Filters the columns displayed in the Posts list table.
 677               *
 678               * @since 1.5.0
 679               *
 680               * @param string[] $post_columns An associative array of column headings.
 681               * @param string   $post_type    The post type slug.
 682               */
 683              $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
 684          }
 685  
 686          /**
 687           * Filters the columns displayed in the Posts list table for a specific post type.
 688           *
 689           * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
 690           *
 691           * @since 3.0.0
 692           *
 693           * @param string[] $post_columns An associative array of column headings.
 694           */
 695          return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
 696      }
 697  
 698      /**
 699       * @return array
 700       */
 701  	protected function get_sortable_columns() {
 702          return array(
 703              'title'    => 'title',
 704              'parent'   => 'parent',
 705              'comments' => 'comment_count',
 706              'date'     => array( 'date', true ),
 707          );
 708      }
 709  
 710      /**
 711       * @global WP_Query $wp_query WordPress Query object.
 712       * @global int $per_page
 713       * @param array $posts
 714       * @param int   $level
 715       */
 716  	public function display_rows( $posts = array(), $level = 0 ) {
 717          global $wp_query, $per_page;
 718  
 719          if ( empty( $posts ) ) {
 720              $posts = $wp_query->posts;
 721          }
 722  
 723          add_filter( 'the_title', 'esc_html' );
 724  
 725          if ( $this->hierarchical_display ) {
 726              $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
 727          } else {
 728              $this->_display_rows( $posts, $level );
 729          }
 730      }
 731  
 732      /**
 733       * @param array $posts
 734       * @param int   $level
 735       */
 736  	private function _display_rows( $posts, $level = 0 ) {
 737          $post_type = $this->screen->post_type;
 738  
 739          // Create array of post IDs.
 740          $post_ids = array();
 741  
 742          foreach ( $posts as $a_post ) {
 743              $post_ids[] = $a_post->ID;
 744          }
 745  
 746          if ( post_type_supports( $post_type, 'comments' ) ) {
 747              $this->comment_pending_count = get_pending_comments_num( $post_ids );
 748          }
 749  
 750          foreach ( $posts as $post ) {
 751              $this->single_row( $post, $level );
 752          }
 753      }
 754  
 755      /**
 756       * @global wpdb    $wpdb WordPress database abstraction object.
 757       * @global WP_Post $post Global post object.
 758       * @param array $pages
 759       * @param int   $pagenum
 760       * @param int   $per_page
 761       */
 762  	private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
 763          global $wpdb;
 764  
 765          $level = 0;
 766  
 767          if ( ! $pages ) {
 768              $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
 769  
 770              if ( ! $pages ) {
 771                  return;
 772              }
 773          }
 774  
 775          /*
 776           * Arrange pages into two parts: top level pages and children_pages
 777           * children_pages is two dimensional array, eg.
 778           * children_pages[10][] contains all sub-pages whose parent is 10.
 779           * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
 780           * If searching, ignore hierarchy and treat everything as top level
 781           */
 782          if ( empty( $_REQUEST['s'] ) ) {
 783  
 784              $top_level_pages = array();
 785              $children_pages  = array();
 786  
 787              foreach ( $pages as $page ) {
 788  
 789                  // Catch and repair bad pages.
 790                  if ( $page->post_parent == $page->ID ) {
 791                      $page->post_parent = 0;
 792                      $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
 793                      clean_post_cache( $page );
 794                  }
 795  
 796                  if ( 0 == $page->post_parent ) {
 797                      $top_level_pages[] = $page;
 798                  } else {
 799                      $children_pages[ $page->post_parent ][] = $page;
 800                  }
 801              }
 802  
 803              $pages = &$top_level_pages;
 804          }
 805  
 806          $count      = 0;
 807          $start      = ( $pagenum - 1 ) * $per_page;
 808          $end        = $start + $per_page;
 809          $to_display = array();
 810  
 811          foreach ( $pages as $page ) {
 812              if ( $count >= $end ) {
 813                  break;
 814              }
 815  
 816              if ( $count >= $start ) {
 817                  $to_display[ $page->ID ] = $level;
 818              }
 819  
 820              $count++;
 821  
 822              if ( isset( $children_pages ) ) {
 823                  $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
 824              }
 825          }
 826  
 827          // If it is the last pagenum and there are orphaned pages, display them with paging as well.
 828          if ( isset( $children_pages ) && $count < $end ) {
 829              foreach ( $children_pages as $orphans ) {
 830                  foreach ( $orphans as $op ) {
 831                      if ( $count >= $end ) {
 832                          break;
 833                      }
 834  
 835                      if ( $count >= $start ) {
 836                          $to_display[ $op->ID ] = 0;
 837                      }
 838  
 839                      $count++;
 840                  }
 841              }
 842          }
 843  
 844          $ids = array_keys( $to_display );
 845          _prime_post_caches( $ids );
 846  
 847          if ( ! isset( $GLOBALS['post'] ) ) {
 848              $GLOBALS['post'] = reset( $ids );
 849          }
 850  
 851          foreach ( $to_display as $page_id => $level ) {
 852              echo "\t";
 853              $this->single_row( $page_id, $level );
 854          }
 855      }
 856  
 857      /**
 858       * Given a top level page ID, display the nested hierarchy of sub-pages
 859       * together with paging support
 860       *
 861       * @since 3.1.0 (Standalone function exists since 2.6.0)
 862       * @since 4.2.0 Added the `$to_display` parameter.
 863       *
 864       * @param array $children_pages
 865       * @param int   $count
 866       * @param int   $parent
 867       * @param int   $level
 868       * @param int   $pagenum
 869       * @param int   $per_page
 870       * @param array $to_display List of pages to be displayed. Passed by reference.
 871       */
 872  	private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
 873          if ( ! isset( $children_pages[ $parent ] ) ) {
 874              return;
 875          }
 876  
 877          $start = ( $pagenum - 1 ) * $per_page;
 878          $end   = $start + $per_page;
 879  
 880          foreach ( $children_pages[ $parent ] as $page ) {
 881              if ( $count >= $end ) {
 882                  break;
 883              }
 884  
 885              // If the page starts in a subtree, print the parents.
 886              if ( $count == $start && $page->post_parent > 0 ) {
 887                  $my_parents = array();
 888                  $my_parent  = $page->post_parent;
 889                  while ( $my_parent ) {
 890                      // Get the ID from the list or the attribute if my_parent is an object.
 891                      $parent_id = $my_parent;
 892                      if ( is_object( $my_parent ) ) {
 893                          $parent_id = $my_parent->ID;
 894                      }
 895  
 896                      $my_parent    = get_post( $parent_id );
 897                      $my_parents[] = $my_parent;
 898                      if ( ! $my_parent->post_parent ) {
 899                          break;
 900                      }
 901                      $my_parent = $my_parent->post_parent;
 902                  }
 903                  $num_parents = count( $my_parents );
 904                  while ( $my_parent = array_pop( $my_parents ) ) {
 905                      $to_display[ $my_parent->ID ] = $level - $num_parents;
 906                      $num_parents--;
 907                  }
 908              }
 909  
 910              if ( $count >= $start ) {
 911                  $to_display[ $page->ID ] = $level;
 912              }
 913  
 914              $count++;
 915  
 916              $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
 917          }
 918  
 919          unset( $children_pages[ $parent ] ); // Required in order to keep track of orphans.
 920      }
 921  
 922      /**
 923       * Handles the checkbox column output.
 924       *
 925       * @since 4.3.0
 926       *
 927       * @param WP_Post $post The current WP_Post object.
 928       */
 929  	public function column_cb( $post ) {
 930          if ( current_user_can( 'edit_post', $post->ID ) ) :
 931              ?>
 932              <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>">
 933                  <?php
 934                      /* translators: %s: Post title. */
 935                      printf( __( 'Select %s' ), _draft_or_post_title() );
 936                  ?>
 937              </label>
 938              <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
 939              <div class="locked-indicator">
 940                  <span class="locked-indicator-icon" aria-hidden="true"></span>
 941                  <span class="screen-reader-text">
 942                  <?php
 943                  printf(
 944                      /* translators: %s: Post title. */
 945                      __( '&#8220;%s&#8221; is locked' ),
 946                      _draft_or_post_title()
 947                  );
 948                  ?>
 949                  </span>
 950              </div>
 951              <?php
 952          endif;
 953      }
 954  
 955      /**
 956       * @since 4.3.0
 957       *
 958       * @param WP_Post $post
 959       * @param string  $classes
 960       * @param string  $data
 961       * @param string  $primary
 962       */
 963  	protected function _column_title( $post, $classes, $data, $primary ) {
 964          echo '<td class="' . $classes . ' page-title" ', $data, '>';
 965          echo $this->column_title( $post );
 966          echo $this->handle_row_actions( $post, 'title', $primary );
 967          echo '</td>';
 968      }
 969  
 970      /**
 971       * Handles the title column output.
 972       *
 973       * @since 4.3.0
 974       *
 975       * @global string $mode List table view mode.
 976       *
 977       * @param WP_Post $post The current WP_Post object.
 978       */
 979  	public function column_title( $post ) {
 980          global $mode;
 981  
 982          if ( $this->hierarchical_display ) {
 983              if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
 984                  // Sent level 0 by accident, by default, or because we don't know the actual level.
 985                  $find_main_page = (int) $post->post_parent;
 986                  while ( $find_main_page > 0 ) {
 987                      $parent = get_post( $find_main_page );
 988  
 989                      if ( is_null( $parent ) ) {
 990                          break;
 991                      }
 992  
 993                      $this->current_level++;
 994                      $find_main_page = (int) $parent->post_parent;
 995  
 996                      if ( ! isset( $parent_name ) ) {
 997                          /** This filter is documented in wp-includes/post-template.php */
 998                          $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
 999                      }
1000                  }
1001              }
1002          }
1003  
1004          $can_edit_post = current_user_can( 'edit_post', $post->ID );
1005  
1006          if ( $can_edit_post && 'trash' !== $post->post_status ) {
1007              $lock_holder = wp_check_post_lock( $post->ID );
1008  
1009              if ( $lock_holder ) {
1010                  $lock_holder   = get_userdata( $lock_holder );
1011                  $locked_avatar = get_avatar( $lock_holder->ID, 18 );
1012                  /* translators: %s: User's display name. */
1013                  $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
1014              } else {
1015                  $locked_avatar = '';
1016                  $locked_text   = '';
1017              }
1018  
1019              echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
1020          }
1021  
1022          $pad = str_repeat( '&#8212; ', $this->current_level );
1023          echo '<strong>';
1024  
1025          $title = _draft_or_post_title();
1026  
1027          if ( $can_edit_post && 'trash' !== $post->post_status ) {
1028              printf(
1029                  '<a class="row-title" href="%s" aria-label="%s">%s%s</a>',
1030                  get_edit_post_link( $post->ID ),
1031                  /* translators: %s: Post title. */
1032                  esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) ),
1033                  $pad,
1034                  $title
1035              );
1036          } else {
1037              printf(
1038                  '<span>%s%s</span>',
1039                  $pad,
1040                  $title
1041              );
1042          }
1043          _post_states( $post );
1044  
1045          if ( isset( $parent_name ) ) {
1046              $post_type_object = get_post_type_object( $post->post_type );
1047              echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
1048          }
1049          echo "</strong>\n";
1050  
1051          if ( 'excerpt' === $mode
1052              && ! is_post_type_hierarchical( $this->screen->post_type )
1053              && current_user_can( 'read_post', $post->ID )
1054          ) {
1055              if ( post_password_required( $post ) ) {
1056                  echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
1057              } else {
1058                  echo esc_html( get_the_excerpt() );
1059              }
1060          }
1061  
1062          get_inline_data( $post );
1063      }
1064  
1065      /**
1066       * Handles the post date column output.
1067       *
1068       * @since 4.3.0
1069       *
1070       * @global string $mode List table view mode.
1071       *
1072       * @param WP_Post $post The current WP_Post object.
1073       */
1074  	public function column_date( $post ) {
1075          global $mode;
1076  
1077          if ( '0000-00-00 00:00:00' === $post->post_date ) {
1078              $t_time    = __( 'Unpublished' );
1079              $time_diff = 0;
1080          } else {
1081              $t_time = sprintf(
1082                  /* translators: 1: Post date, 2: Post time. */
1083                  __( '%1$s at %2$s' ),
1084                  /* translators: Post date format. See https://www.php.net/manual/datetime.format.php */
1085                  get_the_time( __( 'Y/m/d' ), $post ),
1086                  /* translators: Post time format. See https://www.php.net/manual/datetime.format.php */
1087                  get_the_time( __( 'g:i a' ), $post )
1088              );
1089  
1090              $time      = get_post_timestamp( $post );
1091              $time_diff = time() - $time;
1092          }
1093  
1094          if ( 'publish' === $post->post_status ) {
1095              $status = __( 'Published' );
1096          } elseif ( 'future' === $post->post_status ) {
1097              if ( $time_diff > 0 ) {
1098                  $status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
1099              } else {
1100                  $status = __( 'Scheduled' );
1101              }
1102          } else {
1103              $status = __( 'Last Modified' );
1104          }
1105  
1106          /**
1107           * Filters the status text of the post.
1108           *
1109           * @since 4.8.0
1110           *
1111           * @param string  $status      The status text.
1112           * @param WP_Post $post        Post object.
1113           * @param string  $column_name The column name.
1114           * @param string  $mode        The list display mode ('excerpt' or 'list').
1115           */
1116          $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
1117  
1118          if ( $status ) {
1119              echo $status . '<br />';
1120          }
1121  
1122          /**
1123           * Filters the published time of the post.
1124           *
1125           * @since 2.5.1
1126           * @since 5.5.0 Removed the difference between 'excerpt' and 'list' modes.
1127           *              The published time and date are both displayed now,
1128           *              which is equivalent to the previous 'excerpt' mode.
1129           *
1130           * @param string  $t_time      The published time.
1131           * @param WP_Post $post        Post object.
1132           * @param string  $column_name The column name.
1133           * @param string  $mode        The list display mode ('excerpt' or 'list').
1134           */
1135          echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
1136      }
1137  
1138      /**
1139       * Handles the comments column output.
1140       *
1141       * @since 4.3.0
1142       *
1143       * @param WP_Post $post The current WP_Post object.
1144       */
1145  	public function column_comments( $post ) {
1146          ?>
1147          <div class="post-com-count-wrapper">
1148          <?php
1149              $pending_comments = isset( $this->comment_pending_count[ $post->ID ] ) ? $this->comment_pending_count[ $post->ID ] : 0;
1150  
1151              $this->comments_bubble( $post->ID, $pending_comments );
1152          ?>
1153          </div>
1154          <?php
1155      }
1156  
1157      /**
1158       * Handles the post author column output.
1159       *
1160       * @since 4.3.0
1161       *
1162       * @param WP_Post $post The current WP_Post object.
1163       */
1164  	public function column_author( $post ) {
1165          $args = array(
1166              'post_type' => $post->post_type,
1167              'author'    => get_the_author_meta( 'ID' ),
1168          );
1169          echo $this->get_edit_link( $args, get_the_author() );
1170      }
1171  
1172      /**
1173       * Handles the default column output.
1174       *
1175       * @since 4.3.0
1176       *
1177       * @param WP_Post $post        The current WP_Post object.
1178       * @param string  $column_name The current column name.
1179       */
1180  	public function column_default( $post, $column_name ) {
1181          if ( 'categories' === $column_name ) {
1182              $taxonomy = 'category';
1183          } elseif ( 'tags' === $column_name ) {
1184              $taxonomy = 'post_tag';
1185          } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
1186              $taxonomy = substr( $column_name, 9 );
1187          } else {
1188              $taxonomy = false;
1189          }
1190          if ( $taxonomy ) {
1191              $taxonomy_object = get_taxonomy( $taxonomy );
1192              $terms           = get_the_terms( $post->ID, $taxonomy );
1193              if ( is_array( $terms ) ) {
1194                  $term_links = array();
1195                  foreach ( $terms as $t ) {
1196                      $posts_in_term_qv = array();
1197                      if ( 'post' !== $post->post_type ) {
1198                          $posts_in_term_qv['post_type'] = $post->post_type;
1199                      }
1200                      if ( $taxonomy_object->query_var ) {
1201                          $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
1202                      } else {
1203                          $posts_in_term_qv['taxonomy'] = $taxonomy;
1204                          $posts_in_term_qv['term']     = $t->slug;
1205                      }
1206  
1207                      $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
1208  
1209                      $term_links[] = $this->get_edit_link( $posts_in_term_qv, $label );
1210                  }
1211  
1212                  /**
1213                   * Filters the links in `$taxonomy` column of edit.php.
1214                   *
1215                   * @since 5.2.0
1216                   *
1217                   * @param string[]  $term_links Array of term editing links.
1218                   * @param string    $taxonomy   Taxonomy name.
1219                   * @param WP_Term[] $terms      Array of term objects appearing in the post row.
1220                   */
1221                  $term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
1222  
1223                  /* translators: Used between list items, there is a space after the comma. */
1224                  echo join( __( ', ' ), $term_links );
1225              } else {
1226                  echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
1227              }
1228              return;
1229          }
1230  
1231          if ( is_post_type_hierarchical( $post->post_type ) ) {
1232  
1233              /**
1234               * Fires in each custom column on the Posts list table.
1235               *
1236               * This hook only fires if the current post type is hierarchical,
1237               * such as pages.
1238               *
1239               * @since 2.5.0
1240               *
1241               * @param string $column_name The name of the column to display.
1242               * @param int    $post_id     The current post ID.
1243               */
1244              do_action( 'manage_pages_custom_column', $column_name, $post->ID );
1245          } else {
1246  
1247              /**
1248               * Fires in each custom column in the Posts list table.
1249               *
1250               * This hook only fires if the current post type is non-hierarchical,
1251               * such as posts.
1252               *
1253               * @since 1.5.0
1254               *
1255               * @param string $column_name The name of the column to display.
1256               * @param int    $post_id     The current post ID.
1257               */
1258              do_action( 'manage_posts_custom_column', $column_name, $post->ID );
1259          }
1260  
1261          /**
1262           * Fires for each custom column of a specific post type in the Posts list table.
1263           *
1264           * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
1265           *
1266           * @since 3.1.0
1267           *
1268           * @param string $column_name The name of the column to display.
1269           * @param int    $post_id     The current post ID.
1270           */
1271          do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
1272      }
1273  
1274      /**
1275       * @global WP_Post $post Global post object.
1276       *
1277       * @param int|WP_Post $post
1278       * @param int         $level
1279       */
1280  	public function single_row( $post, $level = 0 ) {
1281          $global_post = get_post();
1282  
1283          $post                = get_post( $post );
1284          $this->current_level = $level;
1285  
1286          $GLOBALS['post'] = $post;
1287          setup_postdata( $post );
1288  
1289          $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
1290  
1291          $lock_holder = wp_check_post_lock( $post->ID );
1292          if ( $lock_holder ) {
1293              $classes .= ' wp-locked';
1294          }
1295  
1296          if ( $post->post_parent ) {
1297              $count    = count( get_post_ancestors( $post->ID ) );
1298              $classes .= ' level-' . $count;
1299          } else {
1300              $classes .= ' level-0';
1301          }
1302          ?>
1303          <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
1304              <?php $this->single_row_columns( $post ); ?>
1305          </tr>
1306          <?php
1307          $GLOBALS['post'] = $global_post;
1308      }
1309  
1310      /**
1311       * Gets the name of the default primary column.
1312       *
1313       * @since 4.3.0
1314       *
1315       * @return string Name of the default primary column, in this case, 'title'.
1316       */
1317  	protected function get_default_primary_column_name() {
1318          return 'title';
1319      }
1320  
1321      /**
1322       * Generates and displays row action links.
1323       *
1324       * @since 4.3.0
1325       *
1326       * @param object $post        Post being acted upon.
1327       * @param string $column_name Current column name.
1328       * @param string $primary     Primary column name.
1329       * @return string Row actions output for posts, or an empty string
1330       *                if the current column is not the primary column.
1331       */
1332  	protected function handle_row_actions( $post, $column_name, $primary ) {
1333          if ( $primary !== $column_name ) {
1334              return '';
1335          }
1336  
1337          $post_type_object = get_post_type_object( $post->post_type );
1338          $can_edit_post    = current_user_can( 'edit_post', $post->ID );
1339          $actions          = array();
1340          $title            = _draft_or_post_title();
1341  
1342          if ( $can_edit_post && 'trash' !== $post->post_status ) {
1343              $actions['edit'] = sprintf(
1344                  '<a href="%s" aria-label="%s">%s</a>',
1345                  get_edit_post_link( $post->ID ),
1346                  /* translators: %s: Post title. */
1347                  esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
1348                  __( 'Edit' )
1349              );
1350  
1351              if ( 'wp_block' !== $post->post_type ) {
1352                  $actions['inline hide-if-no-js'] = sprintf(
1353                      '<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
1354                      /* translators: %s: Post title. */
1355                      esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $title ) ),
1356                      __( 'Quick&nbsp;Edit' )
1357                  );
1358              }
1359          }
1360  
1361          if ( current_user_can( 'delete_post', $post->ID ) ) {
1362              if ( 'trash' === $post->post_status ) {
1363                  $actions['untrash'] = sprintf(
1364                      '<a href="%s" aria-label="%s">%s</a>',
1365                      wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
1366                      /* translators: %s: Post title. */
1367                      esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $title ) ),
1368                      __( 'Restore' )
1369                  );
1370              } elseif ( EMPTY_TRASH_DAYS ) {
1371                  $actions['trash'] = sprintf(
1372                      '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1373                      get_delete_post_link( $post->ID ),
1374                      /* translators: %s: Post title. */
1375                      esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $title ) ),
1376                      _x( 'Trash', 'verb' )
1377                  );
1378              }
1379              if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
1380                  $actions['delete'] = sprintf(
1381                      '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
1382                      get_delete_post_link( $post->ID, '', true ),
1383                      /* translators: %s: Post title. */
1384                      esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $title ) ),
1385                      __( 'Delete Permanently' )
1386                  );
1387              }
1388          }
1389  
1390          if ( is_post_type_viewable( $post_type_object ) ) {
1391              if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ), true ) ) {
1392                  if ( $can_edit_post ) {
1393                      $preview_link    = get_preview_post_link( $post );
1394                      $actions['view'] = sprintf(
1395                          '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1396                          esc_url( $preview_link ),
1397                          /* translators: %s: Post title. */
1398                          esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ),
1399                          __( 'Preview' )
1400                      );
1401                  }
1402              } elseif ( 'trash' !== $post->post_status ) {
1403                  $actions['view'] = sprintf(
1404                      '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
1405                      get_permalink( $post->ID ),
1406                      /* translators: %s: Post title. */
1407                      esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ),
1408                      __( 'View' )
1409                  );
1410              }
1411          }
1412  
1413          if ( 'wp_block' === $post->post_type ) {
1414              $actions['export'] = sprintf(
1415                  '<button type="button" class="wp-list-reusable-blocks__export button-link" data-id="%s" aria-label="%s">%s</button>',
1416                  $post->ID,
1417                  /* translators: %s: Post title. */
1418                  esc_attr( sprintf( __( 'Export &#8220;%s&#8221; as JSON' ), $title ) ),
1419                  __( 'Export as JSON' )
1420              );
1421          }
1422  
1423          if ( is_post_type_hierarchical( $post->post_type ) ) {
1424  
1425              /**
1426               * Filters the array of row action links on the Pages list table.
1427               *
1428               * The filter is evaluated only for hierarchical post types.
1429               *
1430               * @since 2.8.0
1431               *
1432               * @param string[] $actions An array of row action links. Defaults are
1433               *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1434               *                          'Delete Permanently', 'Preview', and 'View'.
1435               * @param WP_Post  $post    The post object.
1436               */
1437              $actions = apply_filters( 'page_row_actions', $actions, $post );
1438          } else {
1439  
1440              /**
1441               * Filters the array of row action links on the Posts list table.
1442               *
1443               * The filter is evaluated only for non-hierarchical post types.
1444               *
1445               * @since 2.8.0
1446               *
1447               * @param string[] $actions An array of row action links. Defaults are
1448               *                          'Edit', 'Quick Edit', 'Restore', 'Trash',
1449               *                          'Delete Permanently', 'Preview', and 'View'.
1450               * @param WP_Post  $post    The post object.
1451               */
1452              $actions = apply_filters( 'post_row_actions', $actions, $post );
1453          }
1454  
1455          return $this->row_actions( $actions );
1456      }
1457  
1458      /**
1459       * Outputs the hidden row displayed when inline editing
1460       *
1461       * @since 3.1.0
1462       *
1463       * @global string $mode List table view mode.
1464       */
1465  	public function inline_edit() {
1466          global $mode;
1467  
1468          $screen = $this->screen;
1469  
1470          $post             = get_default_post_to_edit( $screen->post_type );
1471          $post_type_object = get_post_type_object( $screen->post_type );
1472  
1473          $taxonomy_names          = get_object_taxonomies( $screen->post_type );
1474          $hierarchical_taxonomies = array();
1475          $flat_taxonomies         = array();
1476  
1477          foreach ( $taxonomy_names as $taxonomy_name ) {
1478  
1479              $taxonomy = get_taxonomy( $taxonomy_name );
1480  
1481              $show_in_quick_edit = $taxonomy->show_in_quick_edit;
1482  
1483              /**
1484               * Filters whether the current taxonomy should be shown in the Quick Edit panel.
1485               *
1486               * @since 4.2.0
1487               *
1488               * @param bool   $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
1489               * @param string $taxonomy_name      Taxonomy name.
1490               * @param string $post_type          Post type of current Quick Edit post.
1491               */
1492              if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
1493                  continue;
1494              }
1495  
1496              if ( $taxonomy->hierarchical ) {
1497                  $hierarchical_taxonomies[] = $taxonomy;
1498              } else {
1499                  $flat_taxonomies[] = $taxonomy;
1500              }
1501          }
1502  
1503          $m            = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
1504          $can_publish  = current_user_can( $post_type_object->cap->publish_posts );
1505          $core_columns = array(
1506              'cb'         => true,
1507              'date'       => true,
1508              'title'      => true,
1509              'categories' => true,
1510              'tags'       => true,
1511              'comments'   => true,
1512              'author'     => true,
1513          );
1514  
1515          ?>
1516  
1517          <form method="get">
1518          <table style="display: none"><tbody id="inlineedit">
1519          <?php
1520          $hclass              = count( $hierarchical_taxonomies ) ? 'post' : 'page';
1521          $inline_edit_classes = "inline-edit-row inline-edit-row-$hclass";
1522          $bulk_edit_classes   = "bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}";
1523          $quick_edit_classes  = "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}";
1524  
1525          $bulk = 0;
1526          while ( $bulk < 2 ) :
1527              $classes  = $inline_edit_classes . ' ';
1528              $classes .= $bulk ? $bulk_edit_classes : $quick_edit_classes;
1529              ?>
1530              <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="<?php echo $classes; ?>" style="display: none">
1531              <td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
1532  
1533              <fieldset class="inline-edit-col-left">
1534                  <legend class="inline-edit-legend"><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></legend>
1535                  <div class="inline-edit-col">
1536  
1537                  <?php if ( post_type_supports( $screen->post_type, 'title' ) ) : ?>
1538  
1539                      <?php if ( $bulk ) : ?>
1540  
1541                          <div id="bulk-title-div">
1542                              <div id="bulk-titles"></div>
1543                          </div>
1544  
1545                      <?php else : // $bulk ?>
1546  
1547                          <label>
1548                              <span class="title"><?php _e( 'Title' ); ?></span>
1549                              <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
1550                          </label>
1551  
1552                          <?php if ( is_post_type_viewable( $screen->post_type ) ) : ?>
1553  
1554                              <label>
1555                                  <span class="title"><?php _e( 'Slug' ); ?></span>
1556                                  <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
1557                              </label>
1558  
1559                          <?php endif; // is_post_type_viewable() ?>
1560  
1561                      <?php endif; // $bulk ?>
1562  
1563                  <?php endif; // post_type_supports( ... 'title' ) ?>
1564  
1565                  <?php if ( ! $bulk ) : ?>
1566                      <fieldset class="inline-edit-date">
1567                          <legend><span class="title"><?php _e( 'Date' ); ?></span></legend>
1568                          <?php touch_time( 1, 1, 0, 1 ); ?>
1569                      </fieldset>
1570                      <br class="clear" />
1571                  <?php endif; // $bulk ?>
1572  
1573                  <?php
1574                  if ( post_type_supports( $screen->post_type, 'author' ) ) :
1575                      $authors_dropdown = '';
1576  
1577                      if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) :
1578                          $users_opt = array(
1579                              'hide_if_only_one_author' => false,
1580                              'who'                     => 'authors',
1581                              'name'                    => 'post_author',
1582                              'class'                   => 'authors',
1583                              'multi'                   => 1,
1584                              'echo'                    => 0,
1585                              'show'                    => 'display_name_with_login',
1586                          );
1587  
1588                          if ( $bulk ) {
1589                              $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
1590                          }
1591  
1592                          $authors = wp_dropdown_users( $users_opt );
1593                          if ( $authors ) :
1594                              $authors_dropdown  = '<label class="inline-edit-author">';
1595                              $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
1596                              $authors_dropdown .= $authors;
1597                              $authors_dropdown .= '</label>';
1598                          endif;
1599                      endif; // current_user_can( 'edit_others_posts' )
1600                      ?>
1601  
1602                      <?php
1603                      if ( ! $bulk ) {
1604                          echo $authors_dropdown;
1605                      }
1606                  endif; // post_type_supports( ... 'author' )
1607                  ?>
1608  
1609                  <?php if ( ! $bulk && $can_publish ) : ?>
1610  
1611                      <div class="inline-edit-group wp-clearfix">
1612                          <label class="alignleft">
1613                              <span class="title"><?php _e( 'Password' ); ?></span>
1614                              <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
1615                          </label>
1616  
1617                          <span class="alignleft inline-edit-or">
1618                              <?php
1619                              /* translators: Between password field and private checkbox on post quick edit interface. */
1620                              _e( '&ndash;OR&ndash;' );
1621                              ?>
1622                          </span>
1623                          <label class="alignleft inline-edit-private">
1624                              <input type="checkbox" name="keep_private" value="private" />
1625                              <span class="checkbox-title"><?php _e( 'Private' ); ?></span>
1626                          </label>
1627                      </div>
1628  
1629                  <?php endif; ?>
1630  
1631                  </div>
1632              </fieldset>
1633  
1634              <?php if ( count( $hierarchical_taxonomies ) && ! $bulk ) : ?>
1635  
1636                  <fieldset class="inline-edit-col-center inline-edit-categories">
1637                      <div class="inline-edit-col">
1638  
1639                      <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
1640  
1641                          <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ); ?></span>
1642                          <input type="hidden" name="<?php echo ( 'category' === $taxonomy->name ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
1643                          <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name ); ?>-checklist">
1644                              <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ); ?>
1645                          </ul>
1646  
1647                      <?php endforeach; // $hierarchical_taxonomies as $taxonomy ?>
1648  
1649                      </div>
1650                  </fieldset>
1651  
1652              <?php endif; // count( $hierarchical_taxonomies ) && ! $bulk ?>
1653  
1654              <fieldset class="inline-edit-col-right">
1655                  <div class="inline-edit-col">
1656  
1657                  <?php
1658                  if ( post_type_supports( $screen->post_type, 'author' ) && $bulk ) {
1659                      echo $authors_dropdown;
1660                  }
1661                  ?>
1662  
1663                  <?php if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) : ?>
1664  
1665                      <?php if ( $post_type_object->hierarchical ) : ?>
1666  
1667                          <label>
1668                              <span class="title"><?php _e( 'Parent' ); ?></span>
1669                              <?php
1670                              $dropdown_args = array(
1671                                  'post_type'         => $post_type_object->name,
1672                                  'selected'          => $post->post_parent,
1673                                  'name'              => 'post_parent',
1674                                  'show_option_none'  => __( 'Main Page (no parent)' ),
1675                                  'option_none_value' => 0,
1676                                  'sort_column'       => 'menu_order, post_title',
1677                              );
1678  
1679                              if ( $bulk ) {
1680                                  $dropdown_args['show_option_no_change'] = __( '&mdash; No Change &mdash;' );
1681                              }
1682  
1683                              /**
1684                               * Filters the arguments used to generate the Quick Edit page-parent drop-down.
1685                               *
1686                               * @since 2.7.0
1687                               *
1688                               * @see wp_dropdown_pages()
1689                               *
1690                               * @param array $dropdown_args An array of arguments.
1691                               */
1692                              $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
1693  
1694                              wp_dropdown_pages( $dropdown_args );
1695                              ?>
1696                          </label>
1697  
1698                      <?php endif; // hierarchical ?>
1699  
1700                      <?php if ( ! $bulk ) : ?>
1701  
1702                          <label>
1703                              <span class="title"><?php _e( 'Order' ); ?></span>
1704                              <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order; ?>" /></span>
1705                          </label>
1706  
1707                      <?php endif; // ! $bulk ?>
1708  
1709                  <?php endif; // post_type_supports( ... 'page-attributes' ) ?>
1710  
1711                  <?php if ( 0 < count( get_page_templates( null, $screen->post_type ) ) ) : ?>
1712  
1713                      <label>
1714                          <span class="title"><?php _e( 'Template' ); ?></span>
1715                          <select name="page_template">
1716                              <?php if ( $bulk ) : ?>
1717                              <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1718                              <?php endif; // $bulk ?>
1719                              <?php
1720                              /** This filter is documented in wp-admin/includes/meta-boxes.php */
1721                              $default_title = apply_filters( 'default_page_template_title', __( 'Default template' ), 'quick-edit' );
1722                              ?>
1723                              <option value="default"><?php echo esc_html( $default_title ); ?></option>
1724                              <?php page_template_dropdown( '', $screen->post_type ); ?>
1725                          </select>
1726                      </label>
1727  
1728                  <?php endif; ?>
1729  
1730                  <?php if ( count( $flat_taxonomies ) && ! $bulk ) : ?>
1731  
1732                      <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
1733  
1734                          <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) : ?>
1735                              <?php $taxonomy_name = esc_attr( $taxonomy->name ); ?>
1736  
1737                              <label class="inline-edit-tags">
1738                                  <span class="title"><?php echo esc_html( $taxonomy->labels->name ); ?></span>
1739                                  <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>
1740                              </label>
1741  
1742                          <?php endif; // current_user_can( 'assign_terms' ) ?>
1743  
1744                      <?php endforeach; // $flat_taxonomies as $taxonomy ?>
1745  
1746                  <?php endif; // count( $flat_taxonomies ) && ! $bulk ?>
1747  
1748                  <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1749  
1750                      <?php if ( $bulk ) : ?>
1751  
1752                          <div class="inline-edit-group wp-clearfix">
1753  
1754                          <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1755  
1756                              <label class="alignleft">
1757                                  <span class="title"><?php _e( 'Comments' ); ?></span>
1758                                  <select name="comment_status">
1759                                      <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1760                                      <option value="open"><?php _e( 'Allow' ); ?></option>
1761                                      <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1762                                  </select>
1763                              </label>
1764  
1765                          <?php endif; ?>
1766  
1767                          <?php if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1768  
1769                              <label class="alignright">
1770                                  <span class="title"><?php _e( 'Pings' ); ?></span>
1771                                  <select name="ping_status">
1772                                      <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1773                                      <option value="open"><?php _e( 'Allow' ); ?></option>
1774                                      <option value="closed"><?php _e( 'Do not allow' ); ?></option>
1775                                  </select>
1776                              </label>
1777  
1778                          <?php endif; ?>
1779  
1780                          </div>
1781  
1782                      <?php else : // $bulk ?>
1783  
1784                          <div class="inline-edit-group wp-clearfix">
1785  
1786                          <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
1787  
1788                              <label class="alignleft">
1789                                  <input type="checkbox" name="comment_status" value="open" />
1790                                  <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
1791                              </label>
1792  
1793                          <?php endif; ?>
1794  
1795                          <?php if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
1796  
1797                              <label class="alignleft">
1798                                  <input type="checkbox" name="ping_status" value="open" />
1799                                  <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
1800                              </label>
1801  
1802                          <?php endif; ?>
1803  
1804                          </div>
1805  
1806                      <?php endif; // $bulk ?>
1807  
1808                  <?php endif; // post_type_supports( ... comments or pings ) ?>
1809  
1810                      <div class="inline-edit-group wp-clearfix">
1811  
1812                          <label class="inline-edit-status alignleft">
1813                              <span class="title"><?php _e( 'Status' ); ?></span>
1814                              <select name="_status">
1815                                  <?php if ( $bulk ) : ?>
1816                                      <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1817                                  <?php endif; // $bulk ?>
1818  
1819                                  <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review". ?>
1820                                      <option value="publish"><?php _e( 'Published' ); ?></option>
1821                                      <option value="future"><?php _e( 'Scheduled' ); ?></option>
1822                                      <?php if ( $bulk ) : ?>
1823                                          <option value="private"><?php _e( 'Private' ); ?></option>
1824                                      <?php endif; // $bulk ?>
1825                                  <?php endif; ?>
1826  
1827                                  <option value="pending"><?php _e( 'Pending Review' ); ?></option>
1828                                  <option value="draft"><?php _e( 'Draft' ); ?></option>
1829                              </select>
1830                          </label>
1831  
1832                          <?php if ( 'post' === $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
1833  
1834                              <?php if ( $bulk ) : ?>
1835  
1836                                  <label class="alignright">
1837                                      <span class="title"><?php _e( 'Sticky' ); ?></span>
1838                                      <select name="sticky">
1839                                          <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1840                                          <option value="sticky"><?php _e( 'Sticky' ); ?></option>
1841                                          <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
1842                                      </select>
1843                                  </label>
1844  
1845                              <?php else : // $bulk ?>
1846  
1847                                  <label class="alignleft">
1848                                      <input type="checkbox" name="sticky" value="sticky" />
1849                                      <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
1850                                  </label>
1851  
1852                              <?php endif; // $bulk ?>
1853  
1854                          <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_posts' ) ?>
1855  
1856                      </div>
1857  
1858                  <?php if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) : ?>
1859                      <?php $post_formats = get_theme_support( 'post-formats' ); ?>
1860  
1861                      <label class="alignleft">
1862                          <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
1863                          <select name="post_format">
1864                              <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
1865                              <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
1866                              <?php if ( is_array( $post_formats[0] ) ) : ?>
1867                                  <?php foreach ( $post_formats[0] as $format ) : ?>
1868                                      <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
1869                                  <?php endforeach; ?>
1870                              <?php endif; ?>
1871                          </select>
1872                      </label>
1873  
1874                  <?php endif; ?>
1875  
1876                  </div>
1877              </fieldset>
1878  
1879              <?php
1880              list( $columns ) = $this->get_column_info();
1881  
1882              foreach ( $columns as $column_name => $column_display_name ) {
1883                  if ( isset( $core_columns[ $column_name ] ) ) {
1884                      continue;
1885                  }
1886  
1887                  if ( $bulk ) {
1888  
1889                      /**
1890                       * Fires once for each column in Bulk Edit mode.
1891                       *
1892                       * @since 2.7.0
1893                       *
1894                       * @param string $column_name Name of the column to edit.
1895                       * @param string $post_type   The post type slug.
1896                       */
1897                      do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
1898                  } else {
1899  
1900                      /**
1901                       * Fires once for each column in Quick Edit mode.
1902                       *
1903                       * @since 2.7.0
1904                       *
1905                       * @param string $column_name Name of the column to edit.
1906                       * @param string $post_type   The post type slug, or current screen name if this is a taxonomy list table.
1907                       * @param string $taxonomy    The taxonomy name, if any.
1908                       */
1909                      do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' );
1910                  }
1911              }
1912              ?>
1913  
1914              <div class="submit inline-edit-save">
1915                  <button type="button" class="button cancel alignleft"><?php _e( 'Cancel' ); ?></button>
1916  
1917                  <?php if ( ! $bulk ) : ?>
1918                      <?php wp_nonce_field( 'inlineeditnonce', '_inline_edit', false ); ?>
1919                      <button type="button" class="button button-primary save alignright"><?php _e( 'Update' ); ?></button>
1920                      <span class="spinner"></span>
1921                  <?php else : ?>
1922                      <?php submit_button( __( 'Update' ), 'primary alignright', 'bulk_edit', false ); ?>
1923                  <?php endif; ?>
1924  
1925                  <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
1926                  <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
1927                  <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) : ?>
1928                      <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
1929                  <?php endif; ?>
1930                  <br class="clear" />
1931  
1932                  <div class="notice notice-error notice-alt inline hidden">
1933                      <p class="error"></p>
1934                  </div>
1935              </div>
1936  
1937              </td></tr>
1938  
1939              <?php
1940              $bulk++;
1941          endwhile;
1942          ?>
1943          </tbody></table>
1944          </form>
1945          <?php
1946      }
1947  }


Generated: Sun Sep 20 01:00:03 2020 Cross-referenced by PHPXref 0.7.1