3 * Base class for displaying a list of items in an ajaxified HTML table.
9 * @subpackage List_Table
14 * The current list of items
23 * Various information about the current table
32 * Various information needed for displaying the pagination
38 private $_pagination_args = array();
59 * Cached pagination output
68 * The view switcher modes.
74 protected $modes = array();
79 * The child class should call this constructor from its own constructor to override
85 * @param array|string $args {
86 * Array or string of arguments.
88 * @type string $plural Plural value used for labels and the objects being listed.
89 * This affects things such as CSS class-names and nonces used
90 * in the list table, e.g. 'posts'. Default empty.
91 * @type string $singular Singular label for an object being listed, e.g. 'post'.
93 * @type bool $ajax Whether the list table supports AJAX. This includes loading
94 * and sorting data, for example. If true, the class will call
95 * the {@see _js_vars()} method in the footer to provide variables
96 * to any scripts handling AJAX events. Default false.
97 * @type string $screen String containing the hook name used to determine the current
98 * screen. If left null, the current screen will be automatically set.
102 public function __construct( $args = array() ) {
103 $args = wp_parse_args( $args, array(
110 $this->screen = convert_to_screen( $args['screen'] );
112 add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
114 if ( !$args['plural'] )
115 $args['plural'] = $this->screen->base;
117 $args['plural'] = sanitize_key( $args['plural'] );
118 $args['singular'] = sanitize_key( $args['singular'] );
120 $this->_args = $args;
122 if ( $args['ajax'] ) {
123 // wp_enqueue_script( 'list-table' );
124 add_action( 'admin_footer', array( $this, '_js_vars' ) );
127 if ( empty( $this->modes ) ) {
128 $this->modes = array(
129 'list' => __( 'List View' ),
130 'excerpt' => __( 'Excerpt View' )
136 * Make private properties readable for backwards compatibility.
141 * @param string $name Property to get.
142 * @return mixed Property.
144 public function __get( $name ) {
149 * Make private properties settable for backwards compatibility.
154 * @param string $name Property to set.
155 * @param mixed $value Property value.
156 * @return mixed Newly-set property.
158 public function __set( $name, $value ) {
159 return $this->$name = $value;
163 * Make private properties checkable for backwards compatibility.
168 * @param string $name Property to check if set.
169 * @return bool Whether the property is set.
171 public function __isset( $name ) {
172 return isset( $this->$name );
176 * Make private properties un-settable for backwards compatibility.
181 * @param string $name Property to unset.
183 public function __unset( $name ) {
184 unset( $this->$name );
188 * Make private/protected methods readable for backwards compatibility.
193 * @param callable $name Method to call.
194 * @param array $arguments Arguments to pass when calling.
195 * @return mixed|bool Return value of the callback, false otherwise.
197 public function __call( $name, $arguments ) {
198 return call_user_func_array( array( $this, $name ), $arguments );
202 * Checks the current user's permissions
208 public function ajax_user_can() {
209 die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
213 * Prepares the list of items for displaying.
214 * @uses WP_List_Table::set_pagination_args()
220 public function prepare_items() {
221 die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
225 * An internal method that sets all the necessary pagination arguments
227 * @param array $args An associative array with information about the pagination
230 protected function set_pagination_args( $args ) {
231 $args = wp_parse_args( $args, array(
237 if ( !$args['total_pages'] && $args['per_page'] > 0 )
238 $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
240 // Redirect if page number is invalid and headers are not already sent.
241 if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
242 wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
246 $this->_pagination_args = $args;
250 * Access the pagination args.
255 * @param string $key Pagination argument to retrieve. Common values include 'total_items',
256 * 'total_pages', 'per_page', or 'infinite_scroll'.
257 * @return int Number of items that correspond to the given pagination argument.
259 public function get_pagination_arg( $key ) {
260 if ( 'page' == $key )
261 return $this->get_pagenum();
263 if ( isset( $this->_pagination_args[$key] ) )
264 return $this->_pagination_args[$key];
268 * Whether the table has items to display or not
275 public function has_items() {
276 return !empty( $this->items );
280 * Message to be displayed when there are no items
285 public function no_items() {
286 _e( 'No items found.' );
290 * Display the search box.
295 * @param string $text The search button text
296 * @param string $input_id The search input id
298 public function search_box( $text, $input_id ) {
299 if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
302 $input_id = $input_id . '-search-input';
304 if ( ! empty( $_REQUEST['orderby'] ) )
305 echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
306 if ( ! empty( $_REQUEST['order'] ) )
307 echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
308 if ( ! empty( $_REQUEST['post_mime_type'] ) )
309 echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
310 if ( ! empty( $_REQUEST['detached'] ) )
311 echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
313 <p class="search-box">
314 <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
315 <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
316 <?php submit_button( $text, 'button', false, false, array('id' => 'search-submit') ); ?>
322 * Get an associative array ( id => link ) with the list
323 * of views available on this table.
330 protected function get_views() {
335 * Display the list of views available on this table.
340 public function views() {
341 $views = $this->get_views();
343 * Filter the list of available list table views.
345 * The dynamic portion of the hook name, `$this->screen->id`, refers
346 * to the ID of the current screen, usually a string.
350 * @param array $views An array of available list table views.
352 $views = apply_filters( "views_{$this->screen->id}", $views );
354 if ( empty( $views ) )
357 echo "<ul class='subsubsub'>\n";
358 foreach ( $views as $class => $view ) {
359 $views[ $class ] = "\t<li class='$class'>$view";
361 echo implode( " |</li>\n", $views ) . "</li>\n";
366 * Get an associative array ( option_name => option_title ) with the list
367 * of bulk actions available on this table.
374 protected function get_bulk_actions() {
379 * Display the bulk actions dropdown.
384 * @param string $which The location of the bulk actions: 'top' or 'bottom'.
385 * This is designated as optional for backwards-compatibility.
387 protected function bulk_actions( $which = '' ) {
388 if ( is_null( $this->_actions ) ) {
389 $no_new_actions = $this->_actions = $this->get_bulk_actions();
391 * Filter the list table Bulk Actions drop-down.
393 * The dynamic portion of the hook name, `$this->screen->id`, refers
394 * to the ID of the current screen, usually a string.
396 * This filter can currently only be used to remove bulk actions.
400 * @param array $actions An array of the available bulk actions.
402 $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
403 $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
409 if ( empty( $this->_actions ) )
412 echo "<label for='bulk-action-selector-" . esc_attr( $which ) . "' class='screen-reader-text'>" . __( 'Select bulk action' ) . "</label>";
413 echo "<select name='action$two' id='bulk-action-selector-" . esc_attr( $which ) . "'>\n";
414 echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
416 foreach ( $this->_actions as $name => $title ) {
417 $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
419 echo "\t<option value='$name'$class>$title</option>\n";
424 submit_button( __( 'Apply' ), 'action', false, false, array( 'id' => "doaction$two" ) );
429 * Get the current action selected from the bulk actions dropdown.
434 * @return string|bool The action name or False if no action was selected
436 public function current_action() {
437 if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
440 if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
441 return $_REQUEST['action'];
443 if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
444 return $_REQUEST['action2'];
450 * Generate row actions div
455 * @param array $actions The list of actions
456 * @param bool $always_visible Whether the actions should be always visible
459 protected function row_actions( $actions, $always_visible = false ) {
460 $action_count = count( $actions );
463 if ( !$action_count )
466 $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
467 foreach ( $actions as $action => $link ) {
469 ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
470 $out .= "<span class='$action'>$link$sep</span>";
478 * Display a monthly dropdown for filtering items
483 * @param string $post_type
485 protected function months_dropdown( $post_type ) {
486 global $wpdb, $wp_locale;
488 $months = $wpdb->get_results( $wpdb->prepare( "
489 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
492 ORDER BY post_date DESC
496 * Filter the 'Months' drop-down results.
500 * @param object $months The months drop-down query results.
501 * @param string $post_type The post type.
503 $months = apply_filters( 'months_dropdown_results', $months, $post_type );
505 $month_count = count( $months );
507 if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
510 $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
512 <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
513 <select name="m" id="filter-by-date">
514 <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
516 foreach ( $months as $arc_row ) {
517 if ( 0 == $arc_row->year )
520 $month = zeroise( $arc_row->month, 2 );
521 $year = $arc_row->year;
523 printf( "<option %s value='%s'>%s</option>\n",
524 selected( $m, $year . $month, false ),
525 esc_attr( $arc_row->year . $month ),
526 /* translators: 1: month name, 2: 4-digit year */
527 sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
536 * Display a view switcher
541 * @param string $current_mode
543 protected function view_switcher( $current_mode ) {
545 <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
546 <div class="view-switch">
548 foreach ( $this->modes as $mode => $title ) {
549 $classes = array( 'view-' . $mode );
550 if ( $current_mode == $mode )
551 $classes[] = 'current';
553 "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
554 esc_url( add_query_arg( 'mode', $mode ) ),
555 implode( ' ', $classes ),
565 * Display a comment count bubble
570 * @param int $post_id The post ID.
571 * @param int $pending_comments Number of pending comments.
573 protected function comments_bubble( $post_id, $pending_comments ) {
574 $pending_phrase = sprintf( __( '%s pending' ), number_format( $pending_comments ) );
576 if ( $pending_comments )
579 echo "<a href='" . esc_url( add_query_arg( 'p', $post_id, admin_url( 'edit-comments.php' ) ) ) . "' title='" . esc_attr( $pending_phrase ) . "' class='post-com-count'><span class='comment-count'>" . number_format_i18n( get_comments_number() ) . "</span></a>";
581 if ( $pending_comments )
586 * Get the current page number
593 public function get_pagenum() {
594 $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
596 if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
597 $pagenum = $this->_pagination_args['total_pages'];
599 return max( 1, $pagenum );
603 * Get number of items to display on a single page
608 * @param string $option
609 * @param int $default
612 protected function get_items_per_page( $option, $default = 20 ) {
613 $per_page = (int) get_user_option( $option );
614 if ( empty( $per_page ) || $per_page < 1 )
615 $per_page = $default;
618 * Filter the number of items to be displayed on each page of the list table.
620 * The dynamic hook name, $option, refers to the `per_page` option depending
621 * on the type of list table in use. Possible values include: 'edit_comments_per_page',
622 * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
623 * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
624 * 'edit_{$post_type}_per_page', etc.
628 * @param int $per_page Number of items to be displayed. Default 20.
630 return (int) apply_filters( $option, $per_page );
634 * Display the pagination.
639 * @param string $which
641 protected function pagination( $which ) {
642 if ( empty( $this->_pagination_args ) ) {
646 $total_items = $this->_pagination_args['total_items'];
647 $total_pages = $this->_pagination_args['total_pages'];
648 $infinite_scroll = false;
649 if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
650 $infinite_scroll = $this->_pagination_args['infinite_scroll'];
653 $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
655 $current = $this->get_pagenum();
657 $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
659 $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
661 $page_links = array();
663 $disable_first = $disable_last = '';
664 if ( $current == 1 ) {
665 $disable_first = ' disabled';
667 if ( $current == $total_pages ) {
668 $disable_last = ' disabled';
670 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
671 'first-page' . $disable_first,
672 esc_attr__( 'Go to the first page' ),
673 esc_url( remove_query_arg( 'paged', $current_url ) ),
677 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
678 'prev-page' . $disable_first,
679 esc_attr__( 'Go to the previous page' ),
680 esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
684 if ( 'bottom' == $which ) {
685 $html_current_page = $current;
687 $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' title='%s' type='text' name='paged' value='%s' size='%d' />",
688 '<label for="current-page-selector" class="screen-reader-text">' . __( 'Select Page' ) . '</label>',
689 esc_attr__( 'Current page' ),
691 strlen( $total_pages )
694 $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
695 $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
697 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
698 'next-page' . $disable_last,
699 esc_attr__( 'Go to the next page' ),
700 esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
704 $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
705 'last-page' . $disable_last,
706 esc_attr__( 'Go to the last page' ),
707 esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
711 $pagination_links_class = 'pagination-links';
712 if ( ! empty( $infinite_scroll ) ) {
713 $pagination_links_class = ' hide-if-js';
715 $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
717 if ( $total_pages ) {
718 $page_class = $total_pages < 2 ? ' one-page' : '';
720 $page_class = ' no-pages';
722 $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
724 echo $this->_pagination;
728 * Get a list of columns. The format is:
729 * 'internal-name' => 'Title'
737 public function get_columns() {
738 die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
742 * Get a list of sortable columns. The format is:
743 * 'internal-name' => 'orderby'
745 * 'internal-name' => array( 'orderby', true )
747 * The second format will make the initial sorting order be descending
754 protected function get_sortable_columns() {
759 * Get a list of all, hidden and sortable columns, with filter applied
766 protected function get_column_info() {
767 if ( isset( $this->_column_headers ) )
768 return $this->_column_headers;
770 $columns = get_column_headers( $this->screen );
771 $hidden = get_hidden_columns( $this->screen );
773 $sortable_columns = $this->get_sortable_columns();
775 * Filter the list table sortable columns for a specific screen.
777 * The dynamic portion of the hook name, `$this->screen->id`, refers
778 * to the ID of the current screen, usually a string.
782 * @param array $sortable_columns An array of sortable columns.
784 $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
787 foreach ( $_sortable as $id => $data ) {
788 if ( empty( $data ) )
791 $data = (array) $data;
792 if ( !isset( $data[1] ) )
795 $sortable[$id] = $data;
798 $this->_column_headers = array( $columns, $hidden, $sortable );
800 return $this->_column_headers;
804 * Return number of visible columns
811 public function get_column_count() {
812 list ( $columns, $hidden ) = $this->get_column_info();
813 $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
814 return count( $columns ) - count( $hidden );
818 * Print column headers, accounting for hidden and sortable columns.
823 * @param bool $with_id Whether to set the id attribute or not
825 public function print_column_headers( $with_id = true ) {
826 list( $columns, $hidden, $sortable ) = $this->get_column_info();
828 $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
829 $current_url = remove_query_arg( 'paged', $current_url );
831 if ( isset( $_GET['orderby'] ) )
832 $current_orderby = $_GET['orderby'];
834 $current_orderby = '';
836 if ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] )
837 $current_order = 'desc';
839 $current_order = 'asc';
841 if ( ! empty( $columns['cb'] ) ) {
842 static $cb_counter = 1;
843 $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
844 . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
848 foreach ( $columns as $column_key => $column_display_name ) {
849 $class = array( 'manage-column', "column-$column_key" );
852 if ( in_array( $column_key, $hidden ) )
853 $style = 'display:none;';
855 $style = ' style="' . $style . '"';
857 if ( 'cb' == $column_key )
858 $class[] = 'check-column';
859 elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
862 if ( isset( $sortable[$column_key] ) ) {
863 list( $orderby, $desc_first ) = $sortable[$column_key];
865 if ( $current_orderby == $orderby ) {
866 $order = 'asc' == $current_order ? 'desc' : 'asc';
868 $class[] = $current_order;
870 $order = $desc_first ? 'desc' : 'asc';
871 $class[] = 'sortable';
872 $class[] = $desc_first ? 'asc' : 'desc';
875 $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>';
878 $id = $with_id ? "id='$column_key'" : '';
880 if ( !empty( $class ) )
881 $class = "class='" . join( ' ', $class ) . "'";
883 echo "<th scope='col' $id $class $style>$column_display_name</th>";
893 public function display() {
894 $singular = $this->_args['singular'];
896 $this->display_tablenav( 'top' );
899 <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
902 <?php $this->print_column_headers(); ?>
908 <?php $this->print_column_headers( false ); ?>
912 <tbody id="the-list"<?php
914 echo " data-wp-lists='list:$singular'";
916 <?php $this->display_rows_or_placeholder(); ?>
920 $this->display_tablenav( 'bottom' );
924 * Get a list of CSS classes for the list table table tag.
929 * @return array List of CSS classes for the table tag.
931 protected function get_table_classes() {
932 return array( 'widefat', 'fixed', $this->_args['plural'] );
936 * Generate the table navigation above or below the table
940 * @param string $which
942 protected function display_tablenav( $which ) {
943 if ( 'top' == $which )
944 wp_nonce_field( 'bulk-' . $this->_args['plural'] );
946 <div class="tablenav <?php echo esc_attr( $which ); ?>">
948 <div class="alignleft actions bulkactions">
949 <?php $this->bulk_actions( $which ); ?>
952 $this->extra_tablenav( $which );
953 $this->pagination( $which );
962 * Extra controls to be displayed between bulk actions and pagination
967 * @param string $which
969 protected function extra_tablenav( $which ) {}
972 * Generate the tbody element for the list table.
977 public function display_rows_or_placeholder() {
978 if ( $this->has_items() ) {
979 $this->display_rows();
981 echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
988 * Generate the table rows
993 public function display_rows() {
994 foreach ( $this->items as $item )
995 $this->single_row( $item );
999 * Generates content for a single row of the table
1004 * @param object $item The current item
1006 public function single_row( $item ) {
1007 static $row_class = '';
1008 $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
1010 echo '<tr' . $row_class . '>';
1011 $this->single_row_columns( $item );
1016 * Generates the columns for a single row of the table
1021 * @param object $item The current item
1023 protected function single_row_columns( $item ) {
1024 list( $columns, $hidden ) = $this->get_column_info();
1026 foreach ( $columns as $column_name => $column_display_name ) {
1027 $class = "class='$column_name column-$column_name'";
1030 if ( in_array( $column_name, $hidden ) )
1031 $style = ' style="display:none;"';
1033 $attributes = "$class$style";
1035 if ( 'cb' == $column_name ) {
1036 echo '<th scope="row" class="check-column">';
1037 echo $this->column_cb( $item );
1040 elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1041 echo "<td $attributes>";
1042 echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1046 echo "<td $attributes>";
1047 echo $this->column_default( $item, $column_name );
1054 * Handle an incoming ajax request (called from admin-ajax.php)
1059 public function ajax_response() {
1060 $this->prepare_items();
1063 if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1064 $this->display_rows();
1066 $this->display_rows_or_placeholder();
1069 $rows = ob_get_clean();
1071 $response = array( 'rows' => $rows );
1073 if ( isset( $this->_pagination_args['total_items'] ) ) {
1074 $response['total_items_i18n'] = sprintf(
1075 _n( '1 item', '%s items', $this->_pagination_args['total_items'] ),
1076 number_format_i18n( $this->_pagination_args['total_items'] )
1079 if ( isset( $this->_pagination_args['total_pages'] ) ) {
1080 $response['total_pages'] = $this->_pagination_args['total_pages'];
1081 $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1084 die( wp_json_encode( $response ) );
1088 * Send required variables to JavaScript land
1092 public function _js_vars() {
1094 'class' => get_class( $this ),
1096 'id' => $this->screen->id,
1097 'base' => $this->screen->base,
1101 printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );