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


Generated: Mon Jul 22 01:00:03 2019 Cross-referenced by PHPXref 0.7.1