class-wp-list-table.php 38 KB

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