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


Generated: Sun Jul 5 01:00:04 2020 Cross-referenced by PHPXref 0.7.1