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