[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Tue Nov 19 01:00:03 2019 Cross-referenced by PHPXref 0.7.1