[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Administration API: WP_List_Table class
   4   *
   5   * @package WordPress
   6   * @subpackage List_Table
   7   * @since 3.1.0
   8   */
   9  
  10  /**
  11   * Base class for displaying a list of items in an ajaxified HTML table.
  12   *
  13   * @since 3.1.0
  14   * @access private
  15   */
  16  class WP_List_Table {
  17  
  18      /**
  19       * The current list of items.
  20       *
  21       * @since 3.1.0
  22       * @var array
  23       */
  24      public $items;
  25  
  26      /**
  27       * Various information about the current table.
  28       *
  29       * @since 3.1.0
  30       * @var array
  31       */
  32      protected $_args;
  33  
  34      /**
  35       * Various information needed for displaying the pagination.
  36       *
  37       * @since 3.1.0
  38       * @var array
  39       */
  40      protected $_pagination_args = array();
  41  
  42      /**
  43       * The current screen.
  44       *
  45       * @since 3.1.0
  46       * @var WP_Screen
  47       */
  48      protected $screen;
  49  
  50      /**
  51       * Cached bulk actions.
  52       *
  53       * @since 3.1.0
  54       * @var array
  55       */
  56      private $_actions;
  57  
  58      /**
  59       * Cached pagination output.
  60       *
  61       * @since 3.1.0
  62       * @var string
  63       */
  64      private $_pagination;
  65  
  66      /**
  67       * The view switcher modes.
  68       *
  69       * @since 4.1.0
  70       * @var array
  71       */
  72      protected $modes = array();
  73  
  74      /**
  75       * Stores the value returned by ->get_column_info().
  76       *
  77       * @since 4.1.0
  78       * @var array
  79       */
  80      protected $_column_headers;
  81  
  82      /**
  83       * {@internal Missing Summary}
  84       *
  85       * @var array
  86       */
  87      protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
  88  
  89      /**
  90       * {@internal Missing Summary}
  91       *
  92       * @var array
  93       */
  94      protected $compat_methods = array(
  95          'set_pagination_args',
  96          'get_views',
  97          'get_bulk_actions',
  98          'bulk_actions',
  99          'row_actions',
 100          'months_dropdown',
 101          'view_switcher',
 102          'comments_bubble',
 103          'get_items_per_page',
 104          'pagination',
 105          'get_sortable_columns',
 106          'get_column_info',
 107          'get_table_classes',
 108          'display_tablenav',
 109          'extra_tablenav',
 110          'single_row_columns',
 111      );
 112  
 113      /**
 114       * Constructor.
 115       *
 116       * The child class should call this constructor from its own constructor to override
 117       * the default $args.
 118       *
 119       * @since 3.1.0
 120       *
 121       * @param array|string $args {
 122       *     Array or string of arguments.
 123       *
 124       *     @type string $plural   Plural value used for labels and the objects being listed.
 125       *                            This affects things such as CSS class-names and nonces used
 126       *                            in the list table, e.g. 'posts'. Default empty.
 127       *     @type string $singular Singular label for an object being listed, e.g. 'post'.
 128       *                            Default empty
 129       *     @type bool   $ajax     Whether the list table supports Ajax. This includes loading
 130       *                            and sorting data, for example. If true, the class will call
 131       *                            the _js_vars() method in the footer to provide variables
 132       *                            to any scripts handling Ajax events. Default false.
 133       *     @type string $screen   String containing the hook name used to determine the current
 134       *                            screen. If left null, the current screen will be automatically set.
 135       *                            Default null.
 136       * }
 137       */
 138  	public function __construct( $args = array() ) {
 139          $args = wp_parse_args(
 140              $args,
 141              array(
 142                  'plural'   => '',
 143                  'singular' => '',
 144                  'ajax'     => false,
 145                  'screen'   => null,
 146              )
 147          );
 148  
 149          $this->screen = convert_to_screen( $args['screen'] );
 150  
 151          add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
 152  
 153          if ( ! $args['plural'] ) {
 154              $args['plural'] = $this->screen->base;
 155          }
 156  
 157          $args['plural']   = sanitize_key( $args['plural'] );
 158          $args['singular'] = sanitize_key( $args['singular'] );
 159  
 160          $this->_args = $args;
 161  
 162          if ( $args['ajax'] ) {
 163              // wp_enqueue_script( 'list-table' );
 164              add_action( 'admin_footer', array( $this, '_js_vars' ) );
 165          }
 166  
 167          if ( empty( $this->modes ) ) {
 168              $this->modes = array(
 169                  'list'    => __( 'Compact view' ),
 170                  'excerpt' => __( 'Extended view' ),
 171              );
 172          }
 173      }
 174  
 175      /**
 176       * Make private properties readable for backward compatibility.
 177       *
 178       * @since 4.0.0
 179       *
 180       * @param string $name Property to get.
 181       * @return mixed Property.
 182       */
 183  	public function __get( $name ) {
 184          if ( in_array( $name, $this->compat_fields, true ) ) {
 185              return $this->$name;
 186          }
 187      }
 188  
 189      /**
 190       * Make private properties settable for backward compatibility.
 191       *
 192       * @since 4.0.0
 193       *
 194       * @param string $name  Property to check if set.
 195       * @param mixed  $value Property value.
 196       * @return mixed Newly-set property.
 197       */
 198  	public function __set( $name, $value ) {
 199          if ( in_array( $name, $this->compat_fields, true ) ) {
 200              return $this->$name = $value;
 201          }
 202      }
 203  
 204      /**
 205       * Make private properties checkable for backward compatibility.
 206       *
 207       * @since 4.0.0
 208       *
 209       * @param string $name Property to check if set.
 210       * @return bool Whether the property is set.
 211       */
 212  	public function __isset( $name ) {
 213          if ( in_array( $name, $this->compat_fields, true ) ) {
 214              return isset( $this->$name );
 215          }
 216      }
 217  
 218      /**
 219       * Make private properties un-settable for backward compatibility.
 220       *
 221       * @since 4.0.0
 222       *
 223       * @param string $name Property to unset.
 224       */
 225  	public function __unset( $name ) {
 226          if ( in_array( $name, $this->compat_fields, true ) ) {
 227              unset( $this->$name );
 228          }
 229      }
 230  
 231      /**
 232       * Make private/protected methods readable for backward compatibility.
 233       *
 234       * @since 4.0.0
 235       *
 236       * @param string $name      Method to call.
 237       * @param array  $arguments Arguments to pass when calling.
 238       * @return mixed|bool Return value of the callback, false otherwise.
 239       */
 240  	public function __call( $name, $arguments ) {
 241          if ( in_array( $name, $this->compat_methods, true ) ) {
 242              return $this->$name( ...$arguments );
 243          }
 244          return false;
 245      }
 246  
 247      /**
 248       * Checks the current user's permissions
 249       *
 250       * @since 3.1.0
 251       * @abstract
 252       */
 253  	public function ajax_user_can() {
 254          die( 'function WP_List_Table::ajax_user_can() must be overridden in a subclass.' );
 255      }
 256  
 257      /**
 258       * Prepares the list of items for displaying.
 259       *
 260       * @uses WP_List_Table::set_pagination_args()
 261       *
 262       * @since 3.1.0
 263       * @abstract
 264       */
 265  	public function prepare_items() {
 266          die( 'function WP_List_Table::prepare_items() must be overridden in a subclass.' );
 267      }
 268  
 269      /**
 270       * An internal method that sets all the necessary pagination arguments
 271       *
 272       * @since 3.1.0
 273       *
 274       * @param array|string $args Array or string of arguments with information about the pagination.
 275       */
 276  	protected function set_pagination_args( $args ) {
 277          $args = wp_parse_args(
 278              $args,
 279              array(
 280                  'total_items' => 0,
 281                  'total_pages' => 0,
 282                  'per_page'    => 0,
 283              )
 284          );
 285  
 286          if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
 287              $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
 288          }
 289  
 290          // Redirect if page number is invalid and headers are not already sent.
 291          if ( ! headers_sent() && ! wp_doing_ajax() && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
 292              wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
 293              exit;
 294          }
 295  
 296          $this->_pagination_args = $args;
 297      }
 298  
 299      /**
 300       * Access the pagination args.
 301       *
 302       * @since 3.1.0
 303       *
 304       * @param string $key Pagination argument to retrieve. Common values include 'total_items',
 305       *                    'total_pages', 'per_page', or 'infinite_scroll'.
 306       * @return int Number of items that correspond to the given pagination argument.
 307       */
 308  	public function get_pagination_arg( $key ) {
 309          if ( 'page' === $key ) {
 310              return $this->get_pagenum();
 311          }
 312  
 313          if ( isset( $this->_pagination_args[ $key ] ) ) {
 314              return $this->_pagination_args[ $key ];
 315          }
 316      }
 317  
 318      /**
 319       * Whether the table has items to display or not
 320       *
 321       * @since 3.1.0
 322       *
 323       * @return bool
 324       */
 325  	public function has_items() {
 326          return ! empty( $this->items );
 327      }
 328  
 329      /**
 330       * Message to be displayed when there are no items
 331       *
 332       * @since 3.1.0
 333       */
 334  	public function no_items() {
 335          _e( 'No items found.' );
 336      }
 337  
 338      /**
 339       * Displays the search box.
 340       *
 341       * @since 3.1.0
 342       *
 343       * @param string $text     The 'submit' button label.
 344       * @param string $input_id ID attribute value for the search input field.
 345       */
 346  	public function search_box( $text, $input_id ) {
 347          if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
 348              return;
 349          }
 350  
 351          $input_id = $input_id . '-search-input';
 352  
 353          if ( ! empty( $_REQUEST['orderby'] ) ) {
 354              echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
 355          }
 356          if ( ! empty( $_REQUEST['order'] ) ) {
 357              echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
 358          }
 359          if ( ! empty( $_REQUEST['post_mime_type'] ) ) {
 360              echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
 361          }
 362          if ( ! empty( $_REQUEST['detached'] ) ) {
 363              echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
 364          }
 365          ?>
 366  <p class="search-box">
 367      <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php echo $text; ?>:</label>
 368      <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s" value="<?php _admin_search_query(); ?>" />
 369          <?php submit_button( $text, '', '', false, array( 'id' => 'search-submit' ) ); ?>
 370  </p>
 371          <?php
 372      }
 373  
 374      /**
 375       * Gets the list of views available on this table.
 376       *
 377       * The format is an associative array:
 378       * - `'id' => 'link'`
 379       *
 380       * @since 3.1.0
 381       *
 382       * @return array
 383       */
 384  	protected function get_views() {
 385          return array();
 386      }
 387  
 388      /**
 389       * Displays the list of views available on this table.
 390       *
 391       * @since 3.1.0
 392       */
 393  	public function views() {
 394          $views = $this->get_views();
 395          /**
 396           * Filters the list of available list table views.
 397           *
 398           * The dynamic portion of the hook name, `$this->screen->id`, refers
 399           * to the ID of the current screen, usually a string.
 400           *
 401           * @since 3.1.0
 402           *
 403           * @param string[] $views An array of available list table views.
 404           */
 405          $views = apply_filters( "views_{$this->screen->id}", $views );
 406  
 407          if ( empty( $views ) ) {
 408              return;
 409          }
 410  
 411          $this->screen->render_screen_reader_content( 'heading_views' );
 412  
 413          echo "<ul class='subsubsub'>\n";
 414          foreach ( $views as $class => $view ) {
 415              $views[ $class ] = "\t<li class='$class'>$view";
 416          }
 417          echo implode( " |</li>\n", $views ) . "</li>\n";
 418          echo '</ul>';
 419      }
 420  
 421      /**
 422       * Retrieves the list of bulk actions available for this table.
 423       *
 424       * The format is an associative array where each element represents either a top level option value and label, or
 425       * an array representing an optgroup and its options.
 426       *
 427       * For a standard option, the array element key is the field value and the array element value is the field label.
 428       *
 429       * For an optgroup, the array element key is the label and the array element value is an associative array of
 430       * options as above.
 431       *
 432       * Example:
 433       *
 434       *     [
 435       *         'edit'         => 'Edit',
 436       *         'delete'       => 'Delete',
 437       *         'Change State' => [
 438       *             'feature' => 'Featured',
 439       *             'sale'    => 'On Sale',
 440       *         ]
 441       *     ]
 442       *
 443       * @since 3.1.0
 444       * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup.
 445       *
 446       * @return array
 447       */
 448  	protected function get_bulk_actions() {
 449          return array();
 450      }
 451  
 452      /**
 453       * Displays the bulk actions dropdown.
 454       *
 455       * @since 3.1.0
 456       *
 457       * @param string $which The location of the bulk actions: 'top' or 'bottom'.
 458       *                      This is designated as optional for backward compatibility.
 459       */
 460  	protected function bulk_actions( $which = '' ) {
 461          if ( is_null( $this->_actions ) ) {
 462              $this->_actions = $this->get_bulk_actions();
 463  
 464              /**
 465               * Filters the items in the bulk actions menu of the list table.
 466               *
 467               * The dynamic portion of the hook name, `$this->screen->id`, refers
 468               * to the ID of the current screen.
 469               *
 470               * @since 3.1.0
 471               * @since 5.6.0 A bulk action can now contain an array of options in order to create an optgroup.
 472               *
 473               * @param array $actions An array of the available bulk actions.
 474               */
 475              $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 476  
 477              $two = '';
 478          } else {
 479              $two = '2';
 480          }
 481  
 482          if ( empty( $this->_actions ) ) {
 483              return;
 484          }
 485  
 486          echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
 487          echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
 488          echo '<option value="-1">' . __( 'Bulk actions' ) . "</option>\n";
 489  
 490          foreach ( $this->_actions as $key => $value ) {
 491              if ( is_array( $value ) ) {
 492                  echo "\t" . '<optgroup label="' . esc_attr( $key ) . '">' . "\n";
 493  
 494                  foreach ( $value as $name => $title ) {
 495                      $class = ( 'edit' === $name ) ? ' class="hide-if-no-js"' : '';
 496  
 497                      echo "\t\t" . '<option value="' . esc_attr( $name ) . '"' . $class . '>' . $title . "</option>\n";
 498                  }
 499                  echo "\t" . "</optgroup>\n";
 500              } else {
 501                  $class = ( 'edit' === $key ) ? ' class="hide-if-no-js"' : '';
 502  
 503                  echo "\t" . '<option value="' . esc_attr( $key ) . '"' . $class . '>' . $value . "</option>\n";
 504              }
 505          }
 506  
 507          echo "</select>\n";
 508  
 509          submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
 510          echo "\n";
 511      }
 512  
 513      /**
 514       * Gets the current action selected from the bulk actions dropdown.
 515       *
 516       * @since 3.1.0
 517       *
 518       * @return string|false The action name. False if no action was selected.
 519       */
 520  	public function current_action() {
 521          if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
 522              return false;
 523          }
 524  
 525          if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
 526              return $_REQUEST['action'];
 527          }
 528  
 529          if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) {
 530              return $_REQUEST['action2'];
 531          }
 532  
 533          return false;
 534      }
 535  
 536      /**
 537       * Generates the required HTML for a list of row action links.
 538       *
 539       * @since 3.1.0
 540       *
 541       * @param string[] $actions        An array of action links.
 542       * @param bool     $always_visible Whether the actions should be always visible.
 543       * @return string The HTML for the row actions.
 544       */
 545  	protected function row_actions( $actions, $always_visible = false ) {
 546          $action_count = count( $actions );
 547  
 548          if ( ! $action_count ) {
 549              return '';
 550          }
 551  
 552          $mode = get_user_setting( 'posts_list_mode', 'list' );
 553  
 554          if ( 'excerpt' === $mode ) {
 555              $always_visible = true;
 556          }
 557  
 558          $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
 559  
 560          $i = 0;
 561  
 562          foreach ( $actions as $action => $link ) {
 563              ++$i;
 564  
 565              $sep = ( $i < $action_count ) ? ' | ' : '';
 566  
 567              $out .= "<span class='$action'>$link$sep</span>";
 568          }
 569  
 570          $out .= '</div>';
 571  
 572          $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
 573  
 574          return $out;
 575      }
 576  
 577      /**
 578       * Displays a dropdown for filtering items in the list table by month.
 579       *
 580       * @since 3.1.0
 581       *
 582       * @global wpdb      $wpdb      WordPress database abstraction object.
 583       * @global WP_Locale $wp_locale WordPress date and time locale object.
 584       *
 585       * @param string $post_type The post type.
 586       */
 587  	protected function months_dropdown( $post_type ) {
 588          global $wpdb, $wp_locale;
 589  
 590          /**
 591           * Filters whether to remove the 'Months' drop-down from the post list table.
 592           *
 593           * @since 4.2.0
 594           *
 595           * @param bool   $disable   Whether to disable the drop-down. Default false.
 596           * @param string $post_type The post type.
 597           */
 598          if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
 599              return;
 600          }
 601  
 602          $extra_checks = "AND post_status != 'auto-draft'";
 603          if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
 604              $extra_checks .= " AND post_status != 'trash'";
 605          } elseif ( isset( $_GET['post_status'] ) ) {
 606              $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
 607          }
 608  
 609          $months = $wpdb->get_results(
 610              $wpdb->prepare(
 611                  "
 612              SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
 613              FROM $wpdb->posts
 614              WHERE post_type = %s
 615              $extra_checks
 616              ORDER BY post_date DESC
 617          ",
 618                  $post_type
 619              )
 620          );
 621  
 622          /**
 623           * Filters the 'Months' drop-down results.
 624           *
 625           * @since 3.7.0
 626           *
 627           * @param object[] $months    Array of the months drop-down query results.
 628           * @param string   $post_type The post type.
 629           */
 630          $months = apply_filters( 'months_dropdown_results', $months, $post_type );
 631  
 632          $month_count = count( $months );
 633  
 634          if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
 635              return;
 636          }
 637  
 638          $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
 639          ?>
 640          <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
 641          <select name="m" id="filter-by-date">
 642              <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
 643          <?php
 644          foreach ( $months as $arc_row ) {
 645              if ( 0 == $arc_row->year ) {
 646                  continue;
 647              }
 648  
 649              $month = zeroise( $arc_row->month, 2 );
 650              $year  = $arc_row->year;
 651  
 652              printf(
 653                  "<option %s value='%s'>%s</option>\n",
 654                  selected( $m, $year . $month, false ),
 655                  esc_attr( $arc_row->year . $month ),
 656                  /* translators: 1: Month name, 2: 4-digit year. */
 657                  sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
 658              );
 659          }
 660          ?>
 661          </select>
 662          <?php
 663      }
 664  
 665      /**
 666       * Displays a view switcher.
 667       *
 668       * @since 3.1.0
 669       *
 670       * @param string $current_mode
 671       */
 672  	protected function view_switcher( $current_mode ) {
 673          ?>
 674          <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
 675          <div class="view-switch">
 676          <?php
 677          foreach ( $this->modes as $mode => $title ) {
 678              $classes      = array( 'view-' . $mode );
 679              $aria_current = '';
 680  
 681              if ( $current_mode === $mode ) {
 682                  $classes[]    = 'current';
 683                  $aria_current = ' aria-current="page"';
 684              }
 685  
 686              printf(
 687                  "<a href='%s' class='%s' id='view-switch-$mode'$aria_current><span class='screen-reader-text'>%s</span></a>\n",
 688                  esc_url( remove_query_arg( 'attachment-filter', add_query_arg( 'mode', $mode ) ) ),
 689                  implode( ' ', $classes ),
 690                  $title
 691              );
 692          }
 693          ?>
 694          </div>
 695          <?php
 696      }
 697  
 698      /**
 699       * Displays a comment count bubble.
 700       *
 701       * @since 3.1.0
 702       *
 703       * @param int $post_id          The post ID.
 704       * @param int $pending_comments Number of pending comments.
 705       */
 706  	protected function comments_bubble( $post_id, $pending_comments ) {
 707          $approved_comments = get_comments_number();
 708  
 709          $approved_comments_number = number_format_i18n( $approved_comments );
 710          $pending_comments_number  = number_format_i18n( $pending_comments );
 711  
 712          $approved_only_phrase = sprintf(
 713              /* translators: %s: Number of comments. */
 714              _n( '%s comment', '%s comments', $approved_comments ),
 715              $approved_comments_number
 716          );
 717  
 718          $approved_phrase = sprintf(
 719              /* translators: %s: Number of comments. */
 720              _n( '%s approved comment', '%s approved comments', $approved_comments ),
 721              $approved_comments_number
 722          );
 723  
 724          $pending_phrase = sprintf(
 725              /* translators: %s: Number of comments. */
 726              _n( '%s pending comment', '%s pending comments', $pending_comments ),
 727              $pending_comments_number
 728          );
 729  
 730          if ( ! $approved_comments && ! $pending_comments ) {
 731              // No comments at all.
 732              printf(
 733                  '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
 734                  __( 'No comments' )
 735              );
 736          } elseif ( $approved_comments && 'trash' === get_post_status( $post_id ) ) {
 737              // Don't link the comment bubble for a trashed post.
 738              printf(
 739                  '<span class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
 740                  $approved_comments_number,
 741                  $pending_comments ? $approved_phrase : $approved_only_phrase
 742              );
 743          } elseif ( $approved_comments ) {
 744              // Link the comment bubble to approved comments.
 745              printf(
 746                  '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
 747                  esc_url(
 748                      add_query_arg(
 749                          array(
 750                              'p'              => $post_id,
 751                              'comment_status' => 'approved',
 752                          ),
 753                          admin_url( 'edit-comments.php' )
 754                      )
 755                  ),
 756                  $approved_comments_number,
 757                  $pending_comments ? $approved_phrase : $approved_only_phrase
 758              );
 759          } else {
 760              // Don't link the comment bubble when there are no approved comments.
 761              printf(
 762                  '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
 763                  $approved_comments_number,
 764                  $pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
 765              );
 766          }
 767  
 768          if ( $pending_comments ) {
 769              printf(
 770                  '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
 771                  esc_url(
 772                      add_query_arg(
 773                          array(
 774                              'p'              => $post_id,
 775                              'comment_status' => 'moderated',
 776                          ),
 777                          admin_url( 'edit-comments.php' )
 778                      )
 779                  ),
 780                  $pending_comments_number,
 781                  $pending_phrase
 782              );
 783          } else {
 784              printf(
 785                  '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
 786                  $pending_comments_number,
 787                  $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
 788              );
 789          }
 790      }
 791  
 792      /**
 793       * Gets the current page number.
 794       *
 795       * @since 3.1.0
 796       *
 797       * @return int
 798       */
 799  	public function get_pagenum() {
 800          $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
 801  
 802          if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
 803              $pagenum = $this->_pagination_args['total_pages'];
 804          }
 805  
 806          return max( 1, $pagenum );
 807      }
 808  
 809      /**
 810       * Gets the number of items to display on a single page.
 811       *
 812       * @since 3.1.0
 813       *
 814       * @param string $option
 815       * @param int    $default
 816       * @return int
 817       */
 818  	protected function get_items_per_page( $option, $default = 20 ) {
 819          $per_page = (int) get_user_option( $option );
 820          if ( empty( $per_page ) || $per_page < 1 ) {
 821              $per_page = $default;
 822          }
 823  
 824          /**
 825           * Filters the number of items to be displayed on each page of the list table.
 826           *
 827           * The dynamic hook name, `$option`, refers to the `per_page` option depending
 828           * on the type of list table in use. Possible filter names include:
 829           *
 830           *  - `edit_comments_per_page`
 831           *  - `sites_network_per_page`
 832           *  - `site_themes_network_per_page`
 833           *  - `themes_network_per_page'`
 834           *  - `users_network_per_page`
 835           *  - `edit_post_per_page`
 836           *  - `edit_page_per_page'`
 837           *  - `edit_{$post_type}_per_page`
 838           *  - `edit_post_tag_per_page`
 839           *  - `edit_category_per_page`
 840           *  - `edit_{$taxonomy}_per_page`
 841           *  - `site_users_network_per_page`
 842           *  - `users_per_page`
 843           *
 844           * @since 2.9.0
 845           *
 846           * @param int $per_page Number of items to be displayed. Default 20.
 847           */
 848          return (int) apply_filters( "{$option}", $per_page );
 849      }
 850  
 851      /**
 852       * Displays the pagination.
 853       *
 854       * @since 3.1.0
 855       *
 856       * @param string $which
 857       */
 858  	protected function pagination( $which ) {
 859          if ( empty( $this->_pagination_args ) ) {
 860              return;
 861          }
 862  
 863          $total_items     = $this->_pagination_args['total_items'];
 864          $total_pages     = $this->_pagination_args['total_pages'];
 865          $infinite_scroll = false;
 866          if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
 867              $infinite_scroll = $this->_pagination_args['infinite_scroll'];
 868          }
 869  
 870          if ( 'top' === $which && $total_pages > 1 ) {
 871              $this->screen->render_screen_reader_content( 'heading_pagination' );
 872          }
 873  
 874          $output = '<span class="displaying-num">' . sprintf(
 875              /* translators: %s: Number of items. */
 876              _n( '%s item', '%s items', $total_items ),
 877              number_format_i18n( $total_items )
 878          ) . '</span>';
 879  
 880          $current              = $this->get_pagenum();
 881          $removable_query_args = wp_removable_query_args();
 882  
 883          $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 884  
 885          $current_url = remove_query_arg( $removable_query_args, $current_url );
 886  
 887          $page_links = array();
 888  
 889          $total_pages_before = '<span class="paging-input">';
 890          $total_pages_after  = '</span></span>';
 891  
 892          $disable_first = false;
 893          $disable_last  = false;
 894          $disable_prev  = false;
 895          $disable_next  = false;
 896  
 897          if ( 1 == $current ) {
 898              $disable_first = true;
 899              $disable_prev  = true;
 900          }
 901          if ( 2 == $current ) {
 902              $disable_first = true;
 903          }
 904          if ( $total_pages == $current ) {
 905              $disable_last = true;
 906              $disable_next = true;
 907          }
 908          if ( $total_pages - 1 == $current ) {
 909              $disable_last = true;
 910          }
 911  
 912          if ( $disable_first ) {
 913              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
 914          } else {
 915              $page_links[] = sprintf(
 916                  "<a class='first-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
 917                  esc_url( remove_query_arg( 'paged', $current_url ) ),
 918                  __( 'First page' ),
 919                  '&laquo;'
 920              );
 921          }
 922  
 923          if ( $disable_prev ) {
 924              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
 925          } else {
 926              $page_links[] = sprintf(
 927                  "<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
 928                  esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
 929                  __( 'Previous page' ),
 930                  '&lsaquo;'
 931              );
 932          }
 933  
 934          if ( 'bottom' === $which ) {
 935              $html_current_page  = $current;
 936              $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
 937          } else {
 938              $html_current_page = sprintf(
 939                  "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
 940                  '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
 941                  $current,
 942                  strlen( $total_pages )
 943              );
 944          }
 945          $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
 946          $page_links[]     = $total_pages_before . sprintf(
 947              /* translators: 1: Current page, 2: Total pages. */
 948              _x( '%1$s of %2$s', 'paging' ),
 949              $html_current_page,
 950              $html_total_pages
 951          ) . $total_pages_after;
 952  
 953          if ( $disable_next ) {
 954              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
 955          } else {
 956              $page_links[] = sprintf(
 957                  "<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
 958                  esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
 959                  __( 'Next page' ),
 960                  '&rsaquo;'
 961              );
 962          }
 963  
 964          if ( $disable_last ) {
 965              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
 966          } else {
 967              $page_links[] = sprintf(
 968                  "<a class='last-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
 969                  esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
 970                  __( 'Last page' ),
 971                  '&raquo;'
 972              );
 973          }
 974  
 975          $pagination_links_class = 'pagination-links';
 976          if ( ! empty( $infinite_scroll ) ) {
 977              $pagination_links_class .= ' hide-if-js';
 978          }
 979          $output .= "\n<span class='$pagination_links_class'>" . implode( "\n", $page_links ) . '</span>';
 980  
 981          if ( $total_pages ) {
 982              $page_class = $total_pages < 2 ? ' one-page' : '';
 983          } else {
 984              $page_class = ' no-pages';
 985          }
 986          $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
 987  
 988          echo $this->_pagination;
 989      }
 990  
 991      /**
 992       * Gets a list of columns.
 993       *
 994       * The format is:
 995       * - `'internal-name' => 'Title'`
 996       *
 997       * @since 3.1.0
 998       * @abstract
 999       *
1000       * @return array
1001       */
1002  	public function get_columns() {
1003          die( 'function WP_List_Table::get_columns() must be overridden in a subclass.' );
1004      }
1005  
1006      /**
1007       * Gets a list of sortable columns.
1008       *
1009       * The format is:
1010       * - `'internal-name' => 'orderby'`
1011       * - `'internal-name' => array( 'orderby', 'asc' )` - The second element sets the initial sorting order.
1012       * - `'internal-name' => array( 'orderby', true )`  - The second element makes the initial order descending.
1013       *
1014       * @since 3.1.0
1015       *
1016       * @return array
1017       */
1018  	protected function get_sortable_columns() {
1019          return array();
1020      }
1021  
1022      /**
1023       * Gets the name of the default primary column.
1024       *
1025       * @since 4.3.0
1026       *
1027       * @return string Name of the default primary column, in this case, an empty string.
1028       */
1029  	protected function get_default_primary_column_name() {
1030          $columns = $this->get_columns();
1031          $column  = '';
1032  
1033          if ( empty( $columns ) ) {
1034              return $column;
1035          }
1036  
1037          // We need a primary defined so responsive views show something,
1038          // so let's fall back to the first non-checkbox column.
1039          foreach ( $columns as $col => $column_name ) {
1040              if ( 'cb' === $col ) {
1041                  continue;
1042              }
1043  
1044              $column = $col;
1045              break;
1046          }
1047  
1048          return $column;
1049      }
1050  
1051      /**
1052       * Public wrapper for WP_List_Table::get_default_primary_column_name().
1053       *
1054       * @since 4.4.0
1055       *
1056       * @return string Name of the default primary column.
1057       */
1058  	public function get_primary_column() {
1059          return $this->get_primary_column_name();
1060      }
1061  
1062      /**
1063       * Gets the name of the primary column.
1064       *
1065       * @since 4.3.0
1066       *
1067       * @return string The name of the primary column.
1068       */
1069  	protected function get_primary_column_name() {
1070          $columns = get_column_headers( $this->screen );
1071          $default = $this->get_default_primary_column_name();
1072  
1073          // If the primary column doesn't exist,
1074          // fall back to the first non-checkbox column.
1075          if ( ! isset( $columns[ $default ] ) ) {
1076              $default = self::get_default_primary_column_name();
1077          }
1078  
1079          /**
1080           * Filters the name of the primary column for the current list table.
1081           *
1082           * @since 4.3.0
1083           *
1084           * @param string $default Column name default for the specific list table, e.g. 'name'.
1085           * @param string $context Screen ID for specific list table, e.g. 'plugins'.
1086           */
1087          $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
1088  
1089          if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
1090              $column = $default;
1091          }
1092  
1093          return $column;
1094      }
1095  
1096      /**
1097       * Gets a list of all, hidden and sortable columns, with filter applied.
1098       *
1099       * @since 3.1.0
1100       *
1101       * @return array
1102       */
1103  	protected function get_column_info() {
1104          // $_column_headers is already set / cached.
1105          if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
1106              // Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
1107              // In 4.3, we added a fourth argument for primary column.
1108              $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
1109              foreach ( $this->_column_headers as $key => $value ) {
1110                  $column_headers[ $key ] = $value;
1111              }
1112  
1113              return $column_headers;
1114          }
1115  
1116          $columns = get_column_headers( $this->screen );
1117          $hidden  = get_hidden_columns( $this->screen );
1118  
1119          $sortable_columns = $this->get_sortable_columns();
1120          /**
1121           * Filters the list table sortable columns for a specific screen.
1122           *
1123           * The dynamic portion of the hook name, `$this->screen->id`, refers
1124           * to the ID of the current screen.
1125           *
1126           * @since 3.1.0
1127           *
1128           * @param array $sortable_columns An array of sortable columns.
1129           */
1130          $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
1131  
1132          $sortable = array();
1133          foreach ( $_sortable as $id => $data ) {
1134              if ( empty( $data ) ) {
1135                  continue;
1136              }
1137  
1138              $data = (array) $data;
1139              if ( ! isset( $data[1] ) ) {
1140                  $data[1] = false;
1141              }
1142  
1143              $sortable[ $id ] = $data;
1144          }
1145  
1146          $primary               = $this->get_primary_column_name();
1147          $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
1148  
1149          return $this->_column_headers;
1150      }
1151  
1152      /**
1153       * Returns the number of visible columns.
1154       *
1155       * @since 3.1.0
1156       *
1157       * @return int
1158       */
1159  	public function get_column_count() {
1160          list ( $columns, $hidden ) = $this->get_column_info();
1161          $hidden                    = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
1162          return count( $columns ) - count( $hidden );
1163      }
1164  
1165      /**
1166       * Prints column headers, accounting for hidden and sortable columns.
1167       *
1168       * @since 3.1.0
1169       *
1170       * @param bool $with_id Whether to set the ID attribute or not
1171       */
1172  	public function print_column_headers( $with_id = true ) {
1173          list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1174  
1175          $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1176          $current_url = remove_query_arg( 'paged', $current_url );
1177  
1178          if ( isset( $_GET['orderby'] ) ) {
1179              $current_orderby = $_GET['orderby'];
1180          } else {
1181              $current_orderby = '';
1182          }
1183  
1184          if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
1185              $current_order = 'desc';
1186          } else {
1187              $current_order = 'asc';
1188          }
1189  
1190          if ( ! empty( $columns['cb'] ) ) {
1191              static $cb_counter = 1;
1192              $columns['cb']     = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
1193                  . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
1194              $cb_counter++;
1195          }
1196  
1197          foreach ( $columns as $column_key => $column_display_name ) {
1198              $class = array( 'manage-column', "column-$column_key" );
1199  
1200              if ( in_array( $column_key, $hidden, true ) ) {
1201                  $class[] = 'hidden';
1202              }
1203  
1204              if ( 'cb' === $column_key ) {
1205                  $class[] = 'check-column';
1206              } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) {
1207                  $class[] = 'num';
1208              }
1209  
1210              if ( $column_key === $primary ) {
1211                  $class[] = 'column-primary';
1212              }
1213  
1214              if ( isset( $sortable[ $column_key ] ) ) {
1215                  list( $orderby, $desc_first ) = $sortable[ $column_key ];
1216  
1217                  if ( $current_orderby === $orderby ) {
1218                      $order = 'asc' === $current_order ? 'desc' : 'asc';
1219  
1220                      $class[] = 'sorted';
1221                      $class[] = $current_order;
1222                  } else {
1223                      $order = strtolower( $desc_first );
1224  
1225                      if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) {
1226                          $order = $desc_first ? 'desc' : 'asc';
1227                      }
1228  
1229                      $class[] = 'sortable';
1230                      $class[] = 'desc' === $order ? 'asc' : 'desc';
1231                  }
1232  
1233                  $column_display_name = sprintf(
1234                      '<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>',
1235                      esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ),
1236                      $column_display_name
1237                  );
1238              }
1239  
1240              $tag   = ( 'cb' === $column_key ) ? 'td' : 'th';
1241              $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1242              $id    = $with_id ? "id='$column_key'" : '';
1243  
1244              if ( ! empty( $class ) ) {
1245                  $class = "class='" . implode( ' ', $class ) . "'";
1246              }
1247  
1248              echo "<$tag $scope $id $class>$column_display_name</$tag>";
1249          }
1250      }
1251  
1252      /**
1253       * Displays the table.
1254       *
1255       * @since 3.1.0
1256       */
1257  	public function display() {
1258          $singular = $this->_args['singular'];
1259  
1260          $this->display_tablenav( 'top' );
1261  
1262          $this->screen->render_screen_reader_content( 'heading_list' );
1263          ?>
1264  <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
1265      <thead>
1266      <tr>
1267          <?php $this->print_column_headers(); ?>
1268      </tr>
1269      </thead>
1270  
1271      <tbody id="the-list"
1272          <?php
1273          if ( $singular ) {
1274              echo " data-wp-lists='list:$singular'";
1275          }
1276          ?>
1277          >
1278          <?php $this->display_rows_or_placeholder(); ?>
1279      </tbody>
1280  
1281      <tfoot>
1282      <tr>
1283          <?php $this->print_column_headers( false ); ?>
1284      </tr>
1285      </tfoot>
1286  
1287  </table>
1288          <?php
1289          $this->display_tablenav( 'bottom' );
1290      }
1291  
1292      /**
1293       * Gets a list of CSS classes for the WP_List_Table table tag.
1294       *
1295       * @since 3.1.0
1296       *
1297       * @return string[] Array of CSS classes for the table tag.
1298       */
1299  	protected function get_table_classes() {
1300          $mode = get_user_setting( 'posts_list_mode', 'list' );
1301  
1302          $mode_class = esc_attr( 'table-view-' . $mode );
1303  
1304          return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] );
1305      }
1306  
1307      /**
1308       * Generates the table navigation above or below the table
1309       *
1310       * @since 3.1.0
1311       * @param string $which
1312       */
1313  	protected function display_tablenav( $which ) {
1314          if ( 'top' === $which ) {
1315              wp_nonce_field( 'bulk-' . $this->_args['plural'] );
1316          }
1317          ?>
1318      <div class="tablenav <?php echo esc_attr( $which ); ?>">
1319  
1320          <?php if ( $this->has_items() ) : ?>
1321          <div class="alignleft actions bulkactions">
1322              <?php $this->bulk_actions( $which ); ?>
1323          </div>
1324              <?php
1325          endif;
1326          $this->extra_tablenav( $which );
1327          $this->pagination( $which );
1328          ?>
1329  
1330          <br class="clear" />
1331      </div>
1332          <?php
1333      }
1334  
1335      /**
1336       * Extra controls to be displayed between bulk actions and pagination.
1337       *
1338       * @since 3.1.0
1339       *
1340       * @param string $which
1341       */
1342  	protected function extra_tablenav( $which ) {}
1343  
1344      /**
1345       * Generates the tbody element for the list table.
1346       *
1347       * @since 3.1.0
1348       */
1349  	public function display_rows_or_placeholder() {
1350          if ( $this->has_items() ) {
1351              $this->display_rows();
1352          } else {
1353              echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1354              $this->no_items();
1355              echo '</td></tr>';
1356          }
1357      }
1358  
1359      /**
1360       * Generates the table rows.
1361       *
1362       * @since 3.1.0
1363       */
1364  	public function display_rows() {
1365          foreach ( $this->items as $item ) {
1366              $this->single_row( $item );
1367          }
1368      }
1369  
1370      /**
1371       * Generates content for a single row of the table.
1372       *
1373       * @since 3.1.0
1374       *
1375       * @param object|array $item The current item
1376       */
1377  	public function single_row( $item ) {
1378          echo '<tr>';
1379          $this->single_row_columns( $item );
1380          echo '</tr>';
1381      }
1382  
1383      /**
1384       * @param object|array $item
1385       * @param string $column_name
1386       */
1387  	protected function column_default( $item, $column_name ) {}
1388  
1389      /**
1390       * @param object|array $item
1391       */
1392  	protected function column_cb( $item ) {}
1393  
1394      /**
1395       * Generates the columns for a single row of the table.
1396       *
1397       * @since 3.1.0
1398       *
1399       * @param object|array $item The current item.
1400       */
1401  	protected function single_row_columns( $item ) {
1402          list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1403  
1404          foreach ( $columns as $column_name => $column_display_name ) {
1405              $classes = "$column_name column-$column_name";
1406              if ( $primary === $column_name ) {
1407                  $classes .= ' has-row-actions column-primary';
1408              }
1409  
1410              if ( in_array( $column_name, $hidden, true ) ) {
1411                  $classes .= ' hidden';
1412              }
1413  
1414              // Comments column uses HTML in the display name with screen reader text.
1415              // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1416              $data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
1417  
1418              $attributes = "class='$classes' $data";
1419  
1420              if ( 'cb' === $column_name ) {
1421                  echo '<th scope="row" class="check-column">';
1422                  echo $this->column_cb( $item );
1423                  echo '</th>';
1424              } elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1425                  echo call_user_func(
1426                      array( $this, '_column_' . $column_name ),
1427                      $item,
1428                      $classes,
1429                      $data,
1430                      $primary
1431                  );
1432              } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1433                  echo "<td $attributes>";
1434                  echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1435                  echo $this->handle_row_actions( $item, $column_name, $primary );
1436                  echo '</td>';
1437              } else {
1438                  echo "<td $attributes>";
1439                  echo $this->column_default( $item, $column_name );
1440                  echo $this->handle_row_actions( $item, $column_name, $primary );
1441                  echo '</td>';
1442              }
1443          }
1444      }
1445  
1446      /**
1447       * Generates and display row actions links for the list table.
1448       *
1449       * @since 4.3.0
1450       *
1451       * @param object|array $item        The item being acted upon.
1452       * @param string       $column_name Current column name.
1453       * @param string       $primary     Primary column name.
1454       * @return string The row actions HTML, or an empty string
1455       *                if the current column is not the primary column.
1456       */
1457  	protected function handle_row_actions( $item, $column_name, $primary ) {
1458          return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
1459      }
1460  
1461      /**
1462       * Handles an incoming ajax request (called from admin-ajax.php)
1463       *
1464       * @since 3.1.0
1465       */
1466  	public function ajax_response() {
1467          $this->prepare_items();
1468  
1469          ob_start();
1470          if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1471              $this->display_rows();
1472          } else {
1473              $this->display_rows_or_placeholder();
1474          }
1475  
1476          $rows = ob_get_clean();
1477  
1478          $response = array( 'rows' => $rows );
1479  
1480          if ( isset( $this->_pagination_args['total_items'] ) ) {
1481              $response['total_items_i18n'] = sprintf(
1482                  /* translators: Number of items. */
1483                  _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
1484                  number_format_i18n( $this->_pagination_args['total_items'] )
1485              );
1486          }
1487          if ( isset( $this->_pagination_args['total_pages'] ) ) {
1488              $response['total_pages']      = $this->_pagination_args['total_pages'];
1489              $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1490          }
1491  
1492          die( wp_json_encode( $response ) );
1493      }
1494  
1495      /**
1496       * Sends required variables to JavaScript land.
1497       *
1498       * @since 3.1.0
1499       */
1500  	public function _js_vars() {
1501          $args = array(
1502              'class'  => get_class( $this ),
1503              'screen' => array(
1504                  'id'   => $this->screen->id,
1505                  'base' => $this->screen->base,
1506              ),
1507          );
1508  
1509          printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1510      }
1511  }


Generated: Fri Oct 30 01:00:03 2020 Cross-referenced by PHPXref 0.7.1