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