home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-admin / includes / class-wp-list-table.php < prev    next >
Encoding:
PHP Script  |  2017-07-26  |  36.5 KB  |  1,324 lines

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