author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
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( |
|
16 | 169 |
'list' => __( 'Compact view' ), |
170 |
'excerpt' => __( 'Extended 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 ) { |
|
16 | 184 |
if ( in_array( $name, $this->compat_fields, true ) ) { |
5 | 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 ) { |
|
16 | 199 |
if ( in_array( $name, $this->compat_fields, true ) ) { |
5 | 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 ) { |
|
16 | 213 |
if ( in_array( $name, $this->compat_fields, true ) ) { |
5 | 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 ) { |
|
16 | 226 |
if ( in_array( $name, $this->compat_fields, true ) ) { |
5 | 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 |
* |
|
16 | 236 |
* @param string $name Method to call. |
237 |
* @param array $arguments Arguments to pass when calling. |
|
5 | 238 |
* @return mixed|bool Return value of the callback, false otherwise. |
239 |
*/ |
|
240 |
public function __call( $name, $arguments ) { |
|
16 | 241 |
if ( in_array( $name, $this->compat_methods, true ) ) { |
242 |
return $this->$name( ...$arguments ); |
|
5 | 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() { |
16 | 254 |
die( 'function WP_List_Table::ajax_user_can() must be overridden in a subclass.' ); |
0 | 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() { |
16 | 266 |
die( 'function WP_List_Table::prepare_items() must be overridden in a subclass.' ); |
0 | 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 |
/** |
|
16 | 375 |
* Gets the list of views available on this table. |
376 |
* |
|
377 |
* The format is an associative array: |
|
378 |
* - `'id' => 'link'` |
|
0 | 379 |
* |
380 |
* @since 3.1.0 |
|
381 |
* |
|
382 |
* @return array |
|
383 |
*/ |
|
5 | 384 |
protected function get_views() { |
0 | 385 |
return array(); |
386 |
} |
|
387 |
||
388 |
/** |
|
16 | 389 |
* Displays the list of views available on this table. |
0 | 390 |
* |
391 |
* @since 3.1.0 |
|
392 |
*/ |
|
5 | 393 |
public function views() { |
0 | 394 |
$views = $this->get_views(); |
5 | 395 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* Filters the list of available list table views. |
5 | 397 |
* |
398 |
* The dynamic portion of the hook name, `$this->screen->id`, refers |
|
399 |
* to the ID of the current screen, usually a string. |
|
400 |
* |
|
16 | 401 |
* @since 3.1.0 |
5 | 402 |
* |
9 | 403 |
* @param string[] $views An array of available list table views. |
5 | 404 |
*/ |
405 |
$views = apply_filters( "views_{$this->screen->id}", $views ); |
|
0 | 406 |
|
9 | 407 |
if ( empty( $views ) ) { |
0 | 408 |
return; |
9 | 409 |
} |
0 | 410 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
$this->screen->render_screen_reader_content( 'heading_views' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
|
0 | 413 |
echo "<ul class='subsubsub'>\n"; |
414 |
foreach ( $views as $class => $view ) { |
|
415 |
$views[ $class ] = "\t<li class='$class'>$view"; |
|
416 |
} |
|
417 |
echo implode( " |</li>\n", $views ) . "</li>\n"; |
|
9 | 418 |
echo '</ul>'; |
0 | 419 |
} |
420 |
||
421 |
/** |
|
16 | 422 |
* Gets the list of bulk actions available on this table. |
423 |
* |
|
424 |
* The format is an associative array: |
|
425 |
* - `'option_name' => 'option_title'` |
|
0 | 426 |
* |
427 |
* @since 3.1.0 |
|
428 |
* |
|
429 |
* @return array |
|
430 |
*/ |
|
5 | 431 |
protected function get_bulk_actions() { |
0 | 432 |
return array(); |
433 |
} |
|
434 |
||
435 |
/** |
|
16 | 436 |
* Displays the bulk actions dropdown. |
0 | 437 |
* |
438 |
* @since 3.1.0 |
|
5 | 439 |
* |
440 |
* @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
|
441 |
* This is designated as optional for backward compatibility. |
0 | 442 |
*/ |
5 | 443 |
protected function bulk_actions( $which = '' ) { |
0 | 444 |
if ( is_null( $this->_actions ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
$this->_actions = $this->get_bulk_actions(); |
16 | 446 |
|
5 | 447 |
/** |
16 | 448 |
* Filters the list table bulk actions drop-down. |
5 | 449 |
* |
450 |
* The dynamic portion of the hook name, `$this->screen->id`, refers |
|
451 |
* to the ID of the current screen, usually a string. |
|
452 |
* |
|
16 | 453 |
* @since 3.1.0 |
5 | 454 |
* |
9 | 455 |
* @param string[] $actions An array of the available bulk actions. |
5 | 456 |
*/ |
16 | 457 |
$this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
458 |
||
459 |
$two = ''; |
|
0 | 460 |
} else { |
461 |
$two = '2'; |
|
462 |
} |
|
463 |
||
9 | 464 |
if ( empty( $this->_actions ) ) { |
0 | 465 |
return; |
9 | 466 |
} |
0 | 467 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
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
|
469 |
echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n"; |
16 | 470 |
echo '<option value="-1">' . __( 'Bulk actions' ) . "</option>\n"; |
0 | 471 |
|
472 |
foreach ( $this->_actions as $name => $title ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
473 |
$class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
0 | 474 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
echo "\t" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>\n"; |
0 | 476 |
} |
477 |
||
478 |
echo "</select>\n"; |
|
479 |
||
5 | 480 |
submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
0 | 481 |
echo "\n"; |
482 |
} |
|
483 |
||
484 |
/** |
|
16 | 485 |
* Gets the current action selected from the bulk actions dropdown. |
0 | 486 |
* |
487 |
* @since 3.1.0 |
|
488 |
* |
|
16 | 489 |
* @return string|false The action name. False if no action was selected. |
0 | 490 |
*/ |
5 | 491 |
public function current_action() { |
9 | 492 |
if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) { |
5 | 493 |
return false; |
9 | 494 |
} |
5 | 495 |
|
9 | 496 |
if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) { |
0 | 497 |
return $_REQUEST['action']; |
9 | 498 |
} |
0 | 499 |
|
9 | 500 |
if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] ) { |
0 | 501 |
return $_REQUEST['action2']; |
9 | 502 |
} |
0 | 503 |
|
504 |
return false; |
|
505 |
} |
|
506 |
||
507 |
/** |
|
16 | 508 |
* Generates the required HTML for a list of row action links. |
0 | 509 |
* |
510 |
* @since 3.1.0 |
|
511 |
* |
|
9 | 512 |
* @param string[] $actions An array of action links. |
513 |
* @param bool $always_visible Whether the actions should be always visible. |
|
16 | 514 |
* @return string The HTML for the row actions. |
0 | 515 |
*/ |
5 | 516 |
protected function row_actions( $actions, $always_visible = false ) { |
0 | 517 |
$action_count = count( $actions ); |
518 |
||
9 | 519 |
if ( ! $action_count ) { |
0 | 520 |
return ''; |
9 | 521 |
} |
0 | 522 |
|
16 | 523 |
$mode = get_user_setting( 'posts_list_mode', 'list' ); |
524 |
||
525 |
if ( 'excerpt' === $mode ) { |
|
526 |
$always_visible = true; |
|
527 |
} |
|
528 |
||
0 | 529 |
$out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">'; |
16 | 530 |
|
531 |
$i = 0; |
|
532 |
||
0 | 533 |
foreach ( $actions as $action => $link ) { |
534 |
++$i; |
|
16 | 535 |
|
536 |
$sep = ( $i < $action_count ) ? ' | ' : ''; |
|
537 |
||
538 |
$out .= "<span class='$action'>$link$sep</span>"; |
|
0 | 539 |
} |
16 | 540 |
|
0 | 541 |
$out .= '</div>'; |
542 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
$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
|
544 |
|
0 | 545 |
return $out; |
546 |
} |
|
547 |
||
548 |
/** |
|
16 | 549 |
* Displays a dropdown for filtering items in the list table by month. |
0 | 550 |
* |
551 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
* |
16 | 553 |
* @global wpdb $wpdb WordPress database abstraction object. |
554 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
|
5 | 555 |
* |
16 | 556 |
* @param string $post_type The post type. |
0 | 557 |
*/ |
5 | 558 |
protected function months_dropdown( $post_type ) { |
0 | 559 |
global $wpdb, $wp_locale; |
560 |
||
5 | 561 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
562 |
* Filters whether to remove the 'Months' drop-down from the post list table. |
5 | 563 |
* |
564 |
* @since 4.2.0 |
|
565 |
* |
|
566 |
* @param bool $disable Whether to disable the drop-down. Default false. |
|
567 |
* @param string $post_type The post type. |
|
568 |
*/ |
|
569 |
if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) { |
|
570 |
return; |
|
571 |
} |
|
572 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
$extra_checks = "AND post_status != 'auto-draft'"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
$extra_checks .= " AND post_status != 'trash'"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
} elseif ( isset( $_GET['post_status'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
$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
|
578 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
579 |
|
9 | 580 |
$months = $wpdb->get_results( |
581 |
$wpdb->prepare( |
|
582 |
" |
|
0 | 583 |
SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month |
584 |
FROM $wpdb->posts |
|
585 |
WHERE post_type = %s |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
$extra_checks |
0 | 587 |
ORDER BY post_date DESC |
9 | 588 |
", |
589 |
$post_type |
|
590 |
) |
|
591 |
); |
|
0 | 592 |
|
593 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
* Filters the 'Months' drop-down results. |
0 | 595 |
* |
596 |
* @since 3.7.0 |
|
597 |
* |
|
16 | 598 |
* @param object[] $months Array of the months drop-down query results. |
599 |
* @param string $post_type The post type. |
|
0 | 600 |
*/ |
601 |
$months = apply_filters( 'months_dropdown_results', $months, $post_type ); |
|
602 |
||
603 |
$month_count = count( $months ); |
|
604 |
||
9 | 605 |
if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) { |
0 | 606 |
return; |
9 | 607 |
} |
0 | 608 |
|
609 |
$m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0; |
|
9 | 610 |
?> |
5 | 611 |
<label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label> |
612 |
<select name="m" id="filter-by-date"> |
|
613 |
<option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option> |
|
9 | 614 |
<?php |
0 | 615 |
foreach ( $months as $arc_row ) { |
9 | 616 |
if ( 0 == $arc_row->year ) { |
0 | 617 |
continue; |
9 | 618 |
} |
0 | 619 |
|
620 |
$month = zeroise( $arc_row->month, 2 ); |
|
9 | 621 |
$year = $arc_row->year; |
0 | 622 |
|
9 | 623 |
printf( |
624 |
"<option %s value='%s'>%s</option>\n", |
|
0 | 625 |
selected( $m, $year . $month, false ), |
626 |
esc_attr( $arc_row->year . $month ), |
|
16 | 627 |
/* translators: 1: Month name, 2: 4-digit year. */ |
0 | 628 |
sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year ) |
629 |
); |
|
630 |
} |
|
9 | 631 |
?> |
0 | 632 |
</select> |
9 | 633 |
<?php |
0 | 634 |
} |
635 |
||
636 |
/** |
|
16 | 637 |
* Displays a view switcher. |
0 | 638 |
* |
639 |
* @since 3.1.0 |
|
5 | 640 |
* |
641 |
* @param string $current_mode |
|
0 | 642 |
*/ |
5 | 643 |
protected function view_switcher( $current_mode ) { |
9 | 644 |
?> |
0 | 645 |
<input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" /> |
646 |
<div class="view-switch"> |
|
9 | 647 |
<?php |
648 |
foreach ( $this->modes as $mode => $title ) { |
|
16 | 649 |
$classes = array( 'view-' . $mode ); |
650 |
$aria_current = ''; |
|
651 |
||
9 | 652 |
if ( $current_mode === $mode ) { |
16 | 653 |
$classes[] = 'current'; |
654 |
$aria_current = ' aria-current="page"'; |
|
0 | 655 |
} |
16 | 656 |
|
9 | 657 |
printf( |
16 | 658 |
"<a href='%s' class='%s' id='view-switch-$mode'$aria_current><span class='screen-reader-text'>%s</span></a>\n", |
659 |
esc_url( remove_query_arg( 'attachment-filter', add_query_arg( 'mode', $mode ) ) ), |
|
9 | 660 |
implode( ' ', $classes ), |
661 |
$title |
|
662 |
); |
|
663 |
} |
|
0 | 664 |
?> |
665 |
</div> |
|
9 | 666 |
<?php |
0 | 667 |
} |
668 |
||
669 |
/** |
|
16 | 670 |
* Displays a comment count bubble. |
0 | 671 |
* |
672 |
* @since 3.1.0 |
|
673 |
* |
|
5 | 674 |
* @param int $post_id The post ID. |
675 |
* @param int $pending_comments Number of pending comments. |
|
0 | 676 |
*/ |
5 | 677 |
protected function comments_bubble( $post_id, $pending_comments ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
$approved_comments = get_comments_number(); |
0 | 679 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
$approved_comments_number = number_format_i18n( $approved_comments ); |
9 | 681 |
$pending_comments_number = number_format_i18n( $pending_comments ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
|
16 | 683 |
$approved_only_phrase = sprintf( |
684 |
/* translators: %s: Number of comments. */ |
|
685 |
_n( '%s comment', '%s comments', $approved_comments ), |
|
686 |
$approved_comments_number |
|
687 |
); |
|
0 | 688 |
|
16 | 689 |
$approved_phrase = sprintf( |
690 |
/* translators: %s: Number of comments. */ |
|
691 |
_n( '%s approved comment', '%s approved comments', $approved_comments ), |
|
692 |
$approved_comments_number |
|
693 |
); |
|
694 |
||
695 |
$pending_phrase = sprintf( |
|
696 |
/* translators: %s: Number of comments. */ |
|
697 |
_n( '%s pending comment', '%s pending comments', $pending_comments ), |
|
698 |
$pending_comments_number |
|
699 |
); |
|
700 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
if ( ! $approved_comments && ! $pending_comments ) { |
16 | 702 |
// No comments at all. |
9 | 703 |
printf( |
704 |
'<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
|
705 |
__( 'No comments' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
); |
16 | 707 |
} elseif ( $approved_comments && 'trash' === get_post_status( $post_id ) ) { |
708 |
// Don't link the comment bubble for a trashed post. |
|
709 |
printf( |
|
710 |
'<span class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', |
|
711 |
$approved_comments_number, |
|
712 |
$pending_comments ? $approved_phrase : $approved_only_phrase |
|
713 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
} elseif ( $approved_comments ) { |
16 | 715 |
// Link the comment bubble to approved comments. |
9 | 716 |
printf( |
717 |
'<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>', |
|
718 |
esc_url( |
|
719 |
add_query_arg( |
|
720 |
array( |
|
721 |
'p' => $post_id, |
|
722 |
'comment_status' => 'approved', |
|
723 |
), |
|
724 |
admin_url( 'edit-comments.php' ) |
|
725 |
) |
|
726 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
$approved_comments_number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
$pending_comments ? $approved_phrase : $approved_only_phrase |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
} else { |
16 | 731 |
// Don't link the comment bubble when there are no approved comments. |
9 | 732 |
printf( |
733 |
'<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
|
734 |
$approved_comments_number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
$pending_comments ? __( 'No approved comments' ) : __( 'No comments' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
736 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
} |
0 | 738 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
if ( $pending_comments ) { |
9 | 740 |
printf( |
741 |
'<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>', |
|
742 |
esc_url( |
|
743 |
add_query_arg( |
|
744 |
array( |
|
745 |
'p' => $post_id, |
|
746 |
'comment_status' => 'moderated', |
|
747 |
), |
|
748 |
admin_url( 'edit-comments.php' ) |
|
749 |
) |
|
750 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
$pending_comments_number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
$pending_phrase |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
} else { |
9 | 755 |
printf( |
756 |
'<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
|
757 |
$pending_comments_number, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
$approved_comments ? __( 'No pending comments' ) : __( 'No comments' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
} |
0 | 761 |
} |
762 |
||
763 |
/** |
|
16 | 764 |
* Gets the current page number. |
0 | 765 |
* |
766 |
* @since 3.1.0 |
|
767 |
* |
|
768 |
* @return int |
|
769 |
*/ |
|
5 | 770 |
public function get_pagenum() { |
0 | 771 |
$pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0; |
772 |
||
9 | 773 |
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) { |
0 | 774 |
$pagenum = $this->_pagination_args['total_pages']; |
9 | 775 |
} |
0 | 776 |
|
777 |
return max( 1, $pagenum ); |
|
778 |
} |
|
779 |
||
780 |
/** |
|
16 | 781 |
* Gets the number of items to display on a single page. |
0 | 782 |
* |
783 |
* @since 3.1.0 |
|
784 |
* |
|
5 | 785 |
* @param string $option |
786 |
* @param int $default |
|
0 | 787 |
* @return int |
788 |
*/ |
|
5 | 789 |
protected function get_items_per_page( $option, $default = 20 ) { |
0 | 790 |
$per_page = (int) get_user_option( $option ); |
9 | 791 |
if ( empty( $per_page ) || $per_page < 1 ) { |
0 | 792 |
$per_page = $default; |
9 | 793 |
} |
0 | 794 |
|
5 | 795 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
* Filters the number of items to be displayed on each page of the list table. |
5 | 797 |
* |
16 | 798 |
* The dynamic hook name, `$option`, refers to the `per_page` option depending |
799 |
* on the type of list table in use. Possible filter names include: |
|
800 |
* |
|
801 |
* - `edit_comments_per_page` |
|
802 |
* - `sites_network_per_page` |
|
803 |
* - `site_themes_network_per_page` |
|
804 |
* - `themes_network_per_page'` |
|
805 |
* - `users_network_per_page` |
|
806 |
* - `edit_post_per_page` |
|
807 |
* - `edit_page_per_page'` |
|
808 |
* - `edit_{$post_type}_per_page` |
|
809 |
* - `edit_post_tag_per_page` |
|
810 |
* - `edit_category_per_page` |
|
811 |
* - `edit_{$taxonomy}_per_page` |
|
812 |
* - `site_users_network_per_page` |
|
813 |
* - `users_per_page` |
|
5 | 814 |
* |
815 |
* @since 2.9.0 |
|
816 |
* |
|
817 |
* @param int $per_page Number of items to be displayed. Default 20. |
|
818 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
return (int) apply_filters( "{$option}", $per_page ); |
0 | 820 |
} |
821 |
||
822 |
/** |
|
16 | 823 |
* Displays the pagination. |
0 | 824 |
* |
825 |
* @since 3.1.0 |
|
5 | 826 |
* |
827 |
* @param string $which |
|
0 | 828 |
*/ |
5 | 829 |
protected function pagination( $which ) { |
830 |
if ( empty( $this->_pagination_args ) ) { |
|
0 | 831 |
return; |
5 | 832 |
} |
0 | 833 |
|
9 | 834 |
$total_items = $this->_pagination_args['total_items']; |
835 |
$total_pages = $this->_pagination_args['total_pages']; |
|
5 | 836 |
$infinite_scroll = false; |
837 |
if ( isset( $this->_pagination_args['infinite_scroll'] ) ) { |
|
838 |
$infinite_scroll = $this->_pagination_args['infinite_scroll']; |
|
839 |
} |
|
0 | 840 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
if ( 'top' === $which && $total_pages > 1 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
$this->screen->render_screen_reader_content( 'heading_pagination' ); |
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 |
|
16 | 845 |
$output = '<span class="displaying-num">' . sprintf( |
846 |
/* translators: %s: Number of items. */ |
|
847 |
_n( '%s item', '%s items', $total_items ), |
|
848 |
number_format_i18n( $total_items ) |
|
849 |
) . '</span>'; |
|
0 | 850 |
|
9 | 851 |
$current = $this->get_pagenum(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
852 |
$removable_query_args = wp_removable_query_args(); |
0 | 853 |
|
854 |
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
855 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
$current_url = remove_query_arg( $removable_query_args, $current_url ); |
0 | 857 |
|
858 |
$page_links = array(); |
|
859 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
$total_pages_before = '<span class="paging-input">'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
$total_pages_after = '</span></span>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
|
16 | 863 |
$disable_first = false; |
864 |
$disable_last = false; |
|
865 |
$disable_prev = false; |
|
866 |
$disable_next = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
|
16 | 868 |
if ( 1 == $current ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
$disable_first = true; |
9 | 870 |
$disable_prev = true; |
871 |
} |
|
16 | 872 |
if ( 2 == $current ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
$disable_first = true; |
5 | 874 |
} |
16 | 875 |
if ( $total_pages == $current ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
$disable_last = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
$disable_next = true; |
9 | 878 |
} |
16 | 879 |
if ( $total_pages - 1 == $current ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
880 |
$disable_last = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
} |
0 | 882 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
883 |
if ( $disable_first ) { |
9 | 884 |
$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
|
885 |
} else { |
9 | 886 |
$page_links[] = sprintf( |
887 |
"<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
|
888 |
esc_url( remove_query_arg( 'paged', $current_url ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
__( 'First page' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
'«' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
891 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
892 |
} |
0 | 893 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
if ( $disable_prev ) { |
9 | 895 |
$page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>'; |
5 | 896 |
} else { |
9 | 897 |
$page_links[] = sprintf( |
898 |
"<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", |
|
899 |
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
|
900 |
__( 'Previous page' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
'‹' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
if ( 'bottom' === $which ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
$html_current_page = $current; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
$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
|
908 |
} else { |
9 | 909 |
$html_current_page = sprintf( |
910 |
"%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
|
911 |
'<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>', |
0 | 912 |
$current, |
913 |
strlen( $total_pages ) |
|
914 |
); |
|
5 | 915 |
} |
0 | 916 |
$html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); |
16 | 917 |
$page_links[] = $total_pages_before . sprintf( |
918 |
/* translators: 1: Current page, 2: Total pages. */ |
|
919 |
_x( '%1$s of %2$s', 'paging' ), |
|
920 |
$html_current_page, |
|
921 |
$html_total_pages |
|
922 |
) . $total_pages_after; |
|
0 | 923 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
if ( $disable_next ) { |
9 | 925 |
$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
|
926 |
} else { |
9 | 927 |
$page_links[] = sprintf( |
928 |
"<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>", |
|
929 |
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
|
930 |
__( 'Next page' ), |
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 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
} |
0 | 934 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
if ( $disable_last ) { |
9 | 936 |
$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
|
937 |
} else { |
9 | 938 |
$page_links[] = sprintf( |
939 |
"<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
|
940 |
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
|
941 |
__( 'Last page' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
'»' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
} |
0 | 945 |
|
946 |
$pagination_links_class = 'pagination-links'; |
|
5 | 947 |
if ( ! empty( $infinite_scroll ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
$pagination_links_class .= ' hide-if-js'; |
5 | 949 |
} |
0 | 950 |
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>'; |
951 |
||
5 | 952 |
if ( $total_pages ) { |
0 | 953 |
$page_class = $total_pages < 2 ? ' one-page' : ''; |
5 | 954 |
} else { |
0 | 955 |
$page_class = ' no-pages'; |
5 | 956 |
} |
0 | 957 |
$this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; |
958 |
||
959 |
echo $this->_pagination; |
|
960 |
} |
|
961 |
||
962 |
/** |
|
16 | 963 |
* Gets a list of columns. |
964 |
* |
|
965 |
* The format is: |
|
966 |
* - `'internal-name' => 'Title'` |
|
0 | 967 |
* |
968 |
* @since 3.1.0 |
|
969 |
* @abstract |
|
970 |
* |
|
971 |
* @return array |
|
972 |
*/ |
|
5 | 973 |
public function get_columns() { |
16 | 974 |
die( 'function WP_List_Table::get_columns() must be overridden in a subclass.' ); |
0 | 975 |
} |
976 |
||
977 |
/** |
|
16 | 978 |
* Gets a list of sortable columns. |
0 | 979 |
* |
16 | 980 |
* The format is: |
981 |
* - `'internal-name' => 'orderby'` |
|
982 |
* - `'internal-name' => array( 'orderby', 'asc' )` - The second element sets the initial sorting order. |
|
983 |
* - `'internal-name' => array( 'orderby', true )` - The second element makes the initial order descending. |
|
0 | 984 |
* |
985 |
* @since 3.1.0 |
|
986 |
* |
|
987 |
* @return array |
|
988 |
*/ |
|
5 | 989 |
protected function get_sortable_columns() { |
0 | 990 |
return array(); |
991 |
} |
|
992 |
||
993 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
* Gets the name of the default primary column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* @since 4.3.0 |
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 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
|
999 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
protected function get_default_primary_column_name() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
$columns = $this->get_columns(); |
9 | 1002 |
$column = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
if ( empty( $columns ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
return $column; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
// 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
|
1009 |
// 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
|
1010 |
foreach ( $columns as $col => $column_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
if ( 'cb' === $col ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
$column = $col; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
break; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
return $column; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
* 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
|
1024 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
* @return string Name of the default primary column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
public function get_primary_column() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
return $this->get_primary_column_name(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
* Gets the name of the primary column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
* @return string The name of the primary column. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
protected function get_primary_column_name() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
$columns = get_column_headers( $this->screen ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
$default = $this->get_default_primary_column_name(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
|
16 | 1044 |
// If the primary column doesn't exist, |
1045 |
// fall back to the first non-checkbox column. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
if ( ! isset( $columns[ $default ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
$default = WP_List_Table::get_default_primary_column_name(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
* 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
|
1052 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
* @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
|
1056 |
* @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
|
1057 |
*/ |
9 | 1058 |
$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
|
1059 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
if ( empty( $column ) || ! isset( $columns[ $column ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
$column = $default; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
return $column; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
/** |
16 | 1068 |
* Gets a list of all, hidden and sortable columns, with filter applied. |
0 | 1069 |
* |
1070 |
* @since 3.1.0 |
|
1071 |
* |
|
1072 |
* @return array |
|
1073 |
*/ |
|
5 | 1074 |
protected function get_column_info() { |
16 | 1075 |
// $_column_headers is already set / cached. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
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
|
1077 |
// 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
|
1078 |
// 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
|
1079 |
$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
|
1080 |
foreach ( $this->_column_headers as $key => $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1081 |
$column_headers[ $key ] = $value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1083 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
return $column_headers; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
} |
0 | 1086 |
|
1087 |
$columns = get_column_headers( $this->screen ); |
|
9 | 1088 |
$hidden = get_hidden_columns( $this->screen ); |
0 | 1089 |
|
5 | 1090 |
$sortable_columns = $this->get_sortable_columns(); |
1091 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
* Filters the list table sortable columns for a specific screen. |
5 | 1093 |
* |
1094 |
* The dynamic portion of the hook name, `$this->screen->id`, refers |
|
1095 |
* to the ID of the current screen, usually a string. |
|
1096 |
* |
|
16 | 1097 |
* @since 3.1.0 |
5 | 1098 |
* |
1099 |
* @param array $sortable_columns An array of sortable columns. |
|
1100 |
*/ |
|
1101 |
$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns ); |
|
0 | 1102 |
|
1103 |
$sortable = array(); |
|
1104 |
foreach ( $_sortable as $id => $data ) { |
|
9 | 1105 |
if ( empty( $data ) ) { |
0 | 1106 |
continue; |
9 | 1107 |
} |
0 | 1108 |
|
1109 |
$data = (array) $data; |
|
9 | 1110 |
if ( ! isset( $data[1] ) ) { |
0 | 1111 |
$data[1] = false; |
9 | 1112 |
} |
0 | 1113 |
|
9 | 1114 |
$sortable[ $id ] = $data; |
0 | 1115 |
} |
1116 |
||
9 | 1117 |
$primary = $this->get_primary_column_name(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
$this->_column_headers = array( $columns, $hidden, $sortable, $primary ); |
0 | 1119 |
|
1120 |
return $this->_column_headers; |
|
1121 |
} |
|
1122 |
||
1123 |
/** |
|
16 | 1124 |
* Returns the number of visible columns. |
0 | 1125 |
* |
1126 |
* @since 3.1.0 |
|
1127 |
* |
|
1128 |
* @return int |
|
1129 |
*/ |
|
5 | 1130 |
public function get_column_count() { |
0 | 1131 |
list ( $columns, $hidden ) = $this->get_column_info(); |
9 | 1132 |
$hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) ); |
0 | 1133 |
return count( $columns ) - count( $hidden ); |
1134 |
} |
|
1135 |
||
1136 |
/** |
|
16 | 1137 |
* Prints column headers, accounting for hidden and sortable columns. |
0 | 1138 |
* |
1139 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* |
16 | 1141 |
* @param bool $with_id Whether to set the ID attribute or not |
0 | 1142 |
*/ |
5 | 1143 |
public function print_column_headers( $with_id = true ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
0 | 1145 |
|
1146 |
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
1147 |
$current_url = remove_query_arg( 'paged', $current_url ); |
|
1148 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
if ( isset( $_GET['orderby'] ) ) { |
0 | 1150 |
$current_orderby = $_GET['orderby']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
} else { |
0 | 1152 |
$current_orderby = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
} |
0 | 1154 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1155 |
if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) { |
0 | 1156 |
$current_order = 'desc'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
} else { |
0 | 1158 |
$current_order = 'asc'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1159 |
} |
0 | 1160 |
|
1161 |
if ( ! empty( $columns['cb'] ) ) { |
|
1162 |
static $cb_counter = 1; |
|
9 | 1163 |
$columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>' |
0 | 1164 |
. '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />'; |
1165 |
$cb_counter++; |
|
1166 |
} |
|
1167 |
||
1168 |
foreach ( $columns as $column_key => $column_display_name ) { |
|
1169 |
$class = array( 'manage-column', "column-$column_key" ); |
|
1170 |
||
16 | 1171 |
if ( in_array( $column_key, $hidden, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
$class[] = 'hidden'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
} |
0 | 1174 |
|
9 | 1175 |
if ( 'cb' === $column_key ) { |
0 | 1176 |
$class[] = 'check-column'; |
16 | 1177 |
} elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ), true ) ) { |
0 | 1178 |
$class[] = 'num'; |
9 | 1179 |
} |
0 | 1180 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
if ( $column_key === $primary ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
$class[] = 'column-primary'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
|
9 | 1185 |
if ( isset( $sortable[ $column_key ] ) ) { |
1186 |
list( $orderby, $desc_first ) = $sortable[ $column_key ]; |
|
0 | 1187 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
if ( $current_orderby === $orderby ) { |
16 | 1189 |
$order = 'asc' === $current_order ? 'desc' : 'asc'; |
1190 |
||
0 | 1191 |
$class[] = 'sorted'; |
1192 |
$class[] = $current_order; |
|
1193 |
} else { |
|
16 | 1194 |
$order = strtolower( $desc_first ); |
1195 |
||
1196 |
if ( ! in_array( $order, array( 'desc', 'asc' ), true ) ) { |
|
1197 |
$order = $desc_first ? 'desc' : 'asc'; |
|
1198 |
} |
|
1199 |
||
0 | 1200 |
$class[] = 'sortable'; |
16 | 1201 |
$class[] = 'desc' === $order ? 'asc' : 'desc'; |
0 | 1202 |
} |
1203 |
||
16 | 1204 |
$column_display_name = sprintf( |
1205 |
'<a href="%s"><span>%s</span><span class="sorting-indicator"></span></a>', |
|
1206 |
esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ), |
|
1207 |
$column_display_name |
|
1208 |
); |
|
0 | 1209 |
} |
1210 |
||
9 | 1211 |
$tag = ( 'cb' === $column_key ) ? 'td' : 'th'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
$scope = ( 'th' === $tag ) ? 'scope="col"' : ''; |
9 | 1213 |
$id = $with_id ? "id='$column_key'" : ''; |
0 | 1214 |
|
9 | 1215 |
if ( ! empty( $class ) ) { |
0 | 1216 |
$class = "class='" . join( ' ', $class ) . "'"; |
9 | 1217 |
} |
0 | 1218 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
echo "<$tag $scope $id $class>$column_display_name</$tag>"; |
0 | 1220 |
} |
1221 |
} |
|
1222 |
||
1223 |
/** |
|
16 | 1224 |
* Displays the table. |
0 | 1225 |
* |
1226 |
* @since 3.1.0 |
|
1227 |
*/ |
|
5 | 1228 |
public function display() { |
1229 |
$singular = $this->_args['singular']; |
|
0 | 1230 |
|
1231 |
$this->display_tablenav( 'top' ); |
|
1232 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
$this->screen->render_screen_reader_content( 'heading_list' ); |
9 | 1234 |
?> |
5 | 1235 |
<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> |
0 | 1236 |
<thead> |
1237 |
<tr> |
|
1238 |
<?php $this->print_column_headers(); ?> |
|
1239 |
</tr> |
|
1240 |
</thead> |
|
1241 |
||
9 | 1242 |
<tbody id="the-list" |
1243 |
<?php |
|
5 | 1244 |
if ( $singular ) { |
1245 |
echo " data-wp-lists='list:$singular'"; |
|
9 | 1246 |
} |
1247 |
?> |
|
1248 |
> |
|
5 | 1249 |
<?php $this->display_rows_or_placeholder(); ?> |
1250 |
</tbody> |
|
1251 |
||
0 | 1252 |
<tfoot> |
1253 |
<tr> |
|
1254 |
<?php $this->print_column_headers( false ); ?> |
|
1255 |
</tr> |
|
1256 |
</tfoot> |
|
1257 |
||
1258 |
</table> |
|
9 | 1259 |
<?php |
0 | 1260 |
$this->display_tablenav( 'bottom' ); |
1261 |
} |
|
1262 |
||
1263 |
/** |
|
16 | 1264 |
* Gets a list of CSS classes for the WP_List_Table table tag. |
0 | 1265 |
* |
1266 |
* @since 3.1.0 |
|
1267 |
* |
|
16 | 1268 |
* @return string[] Array of CSS classes for the table tag. |
0 | 1269 |
*/ |
5 | 1270 |
protected function get_table_classes() { |
16 | 1271 |
$mode = get_user_setting( 'posts_list_mode', 'list' ); |
1272 |
||
1273 |
$mode_class = esc_attr( 'table-view-' . $mode ); |
|
1274 |
||
1275 |
return array( 'widefat', 'fixed', 'striped', $mode_class, $this->_args['plural'] ); |
|
0 | 1276 |
} |
1277 |
||
1278 |
/** |
|
16 | 1279 |
* Generates the table navigation above or below the table |
0 | 1280 |
* |
1281 |
* @since 3.1.0 |
|
5 | 1282 |
* @param string $which |
0 | 1283 |
*/ |
5 | 1284 |
protected function display_tablenav( $which ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
if ( 'top' === $which ) { |
0 | 1286 |
wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
?> |
0 | 1289 |
<div class="tablenav <?php echo esc_attr( $which ); ?>"> |
1290 |
||
9 | 1291 |
<?php if ( $this->has_items() ) : ?> |
0 | 1292 |
<div class="alignleft actions bulkactions"> |
5 | 1293 |
<?php $this->bulk_actions( $which ); ?> |
0 | 1294 |
</div> |
9 | 1295 |
<?php |
1296 |
endif; |
|
0 | 1297 |
$this->extra_tablenav( $which ); |
1298 |
$this->pagination( $which ); |
|
9 | 1299 |
?> |
0 | 1300 |
|
1301 |
<br class="clear" /> |
|
1302 |
</div> |
|
9 | 1303 |
<?php |
0 | 1304 |
} |
1305 |
||
1306 |
/** |
|
16 | 1307 |
* Extra controls to be displayed between bulk actions and pagination. |
0 | 1308 |
* |
1309 |
* @since 3.1.0 |
|
5 | 1310 |
* |
1311 |
* @param string $which |
|
0 | 1312 |
*/ |
5 | 1313 |
protected function extra_tablenav( $which ) {} |
0 | 1314 |
|
1315 |
/** |
|
16 | 1316 |
* Generates the tbody element for the list table. |
0 | 1317 |
* |
1318 |
* @since 3.1.0 |
|
1319 |
*/ |
|
5 | 1320 |
public function display_rows_or_placeholder() { |
0 | 1321 |
if ( $this->has_items() ) { |
1322 |
$this->display_rows(); |
|
1323 |
} else { |
|
1324 |
echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">'; |
|
1325 |
$this->no_items(); |
|
1326 |
echo '</td></tr>'; |
|
1327 |
} |
|
1328 |
} |
|
1329 |
||
1330 |
/** |
|
16 | 1331 |
* Generates the table rows. |
0 | 1332 |
* |
1333 |
* @since 3.1.0 |
|
1334 |
*/ |
|
5 | 1335 |
public function display_rows() { |
9 | 1336 |
foreach ( $this->items as $item ) { |
0 | 1337 |
$this->single_row( $item ); |
9 | 1338 |
} |
0 | 1339 |
} |
1340 |
||
1341 |
/** |
|
16 | 1342 |
* Generates content for a single row of the table. |
0 | 1343 |
* |
1344 |
* @since 3.1.0 |
|
1345 |
* |
|
1346 |
* @param object $item The current item |
|
1347 |
*/ |
|
5 | 1348 |
public function single_row( $item ) { |
1349 |
echo '<tr>'; |
|
0 | 1350 |
$this->single_row_columns( $item ); |
1351 |
echo '</tr>'; |
|
1352 |
} |
|
1353 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
* @param object $item |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
* @param string $column_name |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
*/ |
5 | 1358 |
protected function column_default( $item, $column_name ) {} |
1359 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
* @param object $item |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
*/ |
5 | 1363 |
protected function column_cb( $item ) {} |
1364 |
||
0 | 1365 |
/** |
16 | 1366 |
* Generates the columns for a single row of the table. |
0 | 1367 |
* |
1368 |
* @since 3.1.0 |
|
1369 |
* |
|
16 | 1370 |
* @param object $item The current item. |
0 | 1371 |
*/ |
5 | 1372 |
protected function single_row_columns( $item ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
0 | 1374 |
|
1375 |
foreach ( $columns as $column_name => $column_display_name ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
$classes = "$column_name column-$column_name"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
if ( $primary === $column_name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
$classes .= ' has-row-actions column-primary'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
} |
0 | 1380 |
|
16 | 1381 |
if ( in_array( $column_name, $hidden, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
$classes .= ' hidden'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
} |
0 | 1384 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
// 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
|
1386 |
// 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
|
1387 |
$data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"'; |
0 | 1388 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
$attributes = "class='$classes' $data"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
if ( 'cb' === $column_name ) { |
0 | 1392 |
echo '<th scope="row" class="check-column">'; |
1393 |
echo $this->column_cb( $item ); |
|
1394 |
echo '</th>'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
} elseif ( method_exists( $this, '_column_' . $column_name ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
echo call_user_func( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
array( $this, '_column_' . $column_name ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
$item, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
$classes, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
$data, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
$primary |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
} elseif ( method_exists( $this, 'column_' . $column_name ) ) { |
0 | 1404 |
echo "<td $attributes>"; |
1405 |
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
|
1406 |
echo $this->handle_row_actions( $item, $column_name, $primary ); |
9 | 1407 |
echo '</td>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
} else { |
0 | 1409 |
echo "<td $attributes>"; |
1410 |
echo $this->column_default( $item, $column_name ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
echo $this->handle_row_actions( $item, $column_name, $primary ); |
9 | 1412 |
echo '</td>'; |
0 | 1413 |
} |
1414 |
} |
|
1415 |
} |
|
1416 |
||
1417 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
* 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
|
1419 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1420 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
* @param object $item The item being acted upon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
* @param string $column_name Current column name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
* @param string $primary Primary column name. |
16 | 1425 |
* @return string The row actions HTML, or an empty string |
1426 |
* if the current column is not the primary column. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1428 |
protected function handle_row_actions( $item, $column_name, $primary ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : ''; |
9 | 1430 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
/** |
16 | 1433 |
* Handles an incoming ajax request (called from admin-ajax.php) |
0 | 1434 |
* |
1435 |
* @since 3.1.0 |
|
1436 |
*/ |
|
5 | 1437 |
public function ajax_response() { |
0 | 1438 |
$this->prepare_items(); |
1439 |
||
1440 |
ob_start(); |
|
5 | 1441 |
if ( ! empty( $_REQUEST['no_placeholder'] ) ) { |
0 | 1442 |
$this->display_rows(); |
5 | 1443 |
} else { |
0 | 1444 |
$this->display_rows_or_placeholder(); |
5 | 1445 |
} |
0 | 1446 |
|
1447 |
$rows = ob_get_clean(); |
|
1448 |
||
1449 |
$response = array( 'rows' => $rows ); |
|
1450 |
||
5 | 1451 |
if ( isset( $this->_pagination_args['total_items'] ) ) { |
1452 |
$response['total_items_i18n'] = sprintf( |
|
16 | 1453 |
/* translators: Number of items. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
_n( '%s item', '%s items', $this->_pagination_args['total_items'] ), |
5 | 1455 |
number_format_i18n( $this->_pagination_args['total_items'] ) |
1456 |
); |
|
1457 |
} |
|
1458 |
if ( isset( $this->_pagination_args['total_pages'] ) ) { |
|
9 | 1459 |
$response['total_pages'] = $this->_pagination_args['total_pages']; |
5 | 1460 |
$response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] ); |
0 | 1461 |
} |
1462 |
||
5 | 1463 |
die( wp_json_encode( $response ) ); |
0 | 1464 |
} |
1465 |
||
1466 |
/** |
|
16 | 1467 |
* Sends required variables to JavaScript land. |
1468 |
* |
|
1469 |
* @since 3.1.0 |
|
0 | 1470 |
*/ |
5 | 1471 |
public function _js_vars() { |
0 | 1472 |
$args = array( |
1473 |
'class' => get_class( $this ), |
|
1474 |
'screen' => array( |
|
1475 |
'id' => $this->screen->id, |
|
1476 |
'base' => $this->screen->base, |
|
9 | 1477 |
), |
0 | 1478 |
); |
1479 |
||
5 | 1480 |
printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) ); |
0 | 1481 |
} |
1482 |
} |