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