1 | <?php |
---|
2 | /** |
---|
3 | * List Table API: WP_MS_Themes_List_Table class |
---|
4 | * |
---|
5 | * @package WordPress |
---|
6 | * @subpackage Administration |
---|
7 | * @since 3.1.0 |
---|
8 | */ |
---|
9 | |
---|
10 | /** |
---|
11 | * Core class used to implement displaying themes in a list table for the network admin. |
---|
12 | * |
---|
13 | * @since 3.1.0 |
---|
14 | * @access private |
---|
15 | * |
---|
16 | * @see WP_List_Table |
---|
17 | */ |
---|
18 | class WP_MS_Themes_List_Table extends WP_List_Table { |
---|
19 | |
---|
20 | public $site_id; |
---|
21 | public $is_site_themes; |
---|
22 | |
---|
23 | private $has_items; |
---|
24 | |
---|
25 | /** |
---|
26 | * Constructor. |
---|
27 | * |
---|
28 | * @since 3.1.0 |
---|
29 | * @access public |
---|
30 | * |
---|
31 | * @see WP_List_Table::__construct() for more information on default arguments. |
---|
32 | * |
---|
33 | * @global string $status |
---|
34 | * @global int $page |
---|
35 | * |
---|
36 | * @param array $args An associative array of arguments. |
---|
37 | */ |
---|
38 | public function __construct( $args = array() ) { |
---|
39 | global $status, $page; |
---|
40 | |
---|
41 | parent::__construct( array( |
---|
42 | 'plural' => 'themes', |
---|
43 | 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
---|
44 | ) ); |
---|
45 | |
---|
46 | $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all'; |
---|
47 | if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) ) |
---|
48 | $status = 'all'; |
---|
49 | |
---|
50 | $page = $this->get_pagenum(); |
---|
51 | |
---|
52 | $this->is_site_themes = ( 'site-themes-network' === $this->screen->id ) ? true : false; |
---|
53 | |
---|
54 | if ( $this->is_site_themes ) |
---|
55 | $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * |
---|
60 | * @return array |
---|
61 | */ |
---|
62 | protected function get_table_classes() { |
---|
63 | // todo: remove and add CSS for .themes |
---|
64 | return array( 'widefat', 'plugins' ); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * |
---|
69 | * @return bool |
---|
70 | */ |
---|
71 | public function ajax_user_can() { |
---|
72 | if ( $this->is_site_themes ) |
---|
73 | return current_user_can( 'manage_sites' ); |
---|
74 | else |
---|
75 | return current_user_can( 'manage_network_themes' ); |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * |
---|
80 | * @global string $status |
---|
81 | * @global array $totals |
---|
82 | * @global int $page |
---|
83 | * @global string $orderby |
---|
84 | * @global string $order |
---|
85 | * @global string $s |
---|
86 | */ |
---|
87 | public function prepare_items() { |
---|
88 | global $status, $totals, $page, $orderby, $order, $s; |
---|
89 | |
---|
90 | wp_reset_vars( array( 'orderby', 'order', 's' ) ); |
---|
91 | |
---|
92 | $themes = array( |
---|
93 | /** |
---|
94 | * Filters the full array of WP_Theme objects to list in the Multisite |
---|
95 | * themes list table. |
---|
96 | * |
---|
97 | * @since 3.1.0 |
---|
98 | * |
---|
99 | * @param array $all An array of WP_Theme objects to display in the list table. |
---|
100 | */ |
---|
101 | 'all' => apply_filters( 'all_themes', wp_get_themes() ), |
---|
102 | 'search' => array(), |
---|
103 | 'enabled' => array(), |
---|
104 | 'disabled' => array(), |
---|
105 | 'upgrade' => array(), |
---|
106 | 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ), |
---|
107 | ); |
---|
108 | |
---|
109 | if ( $this->is_site_themes ) { |
---|
110 | $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' ); |
---|
111 | $allowed_where = 'site'; |
---|
112 | } else { |
---|
113 | $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' ); |
---|
114 | $allowed_where = 'network'; |
---|
115 | } |
---|
116 | |
---|
117 | $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' ); |
---|
118 | |
---|
119 | foreach ( (array) $themes['all'] as $key => $theme ) { |
---|
120 | if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) { |
---|
121 | unset( $themes['all'][ $key ] ); |
---|
122 | continue; |
---|
123 | } |
---|
124 | |
---|
125 | if ( $maybe_update && isset( $current->response[ $key ] ) ) { |
---|
126 | $themes['all'][ $key ]->update = true; |
---|
127 | $themes['upgrade'][ $key ] = $themes['all'][ $key ]; |
---|
128 | } |
---|
129 | |
---|
130 | $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled'; |
---|
131 | $themes[ $filter ][ $key ] = $themes['all'][ $key ]; |
---|
132 | } |
---|
133 | |
---|
134 | if ( $s ) { |
---|
135 | $status = 'search'; |
---|
136 | $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) ); |
---|
137 | } |
---|
138 | |
---|
139 | $totals = array(); |
---|
140 | foreach ( $themes as $type => $list ) |
---|
141 | $totals[ $type ] = count( $list ); |
---|
142 | |
---|
143 | if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) ) |
---|
144 | $status = 'all'; |
---|
145 | |
---|
146 | $this->items = $themes[ $status ]; |
---|
147 | WP_Theme::sort_by_name( $this->items ); |
---|
148 | |
---|
149 | $this->has_items = ! empty( $themes['all'] ); |
---|
150 | $total_this_page = $totals[ $status ]; |
---|
151 | |
---|
152 | wp_localize_script( 'updates', '_wpUpdatesItemCounts', array( |
---|
153 | 'themes' => $totals, |
---|
154 | 'totals' => wp_get_update_data(), |
---|
155 | ) ); |
---|
156 | |
---|
157 | if ( $orderby ) { |
---|
158 | $orderby = ucfirst( $orderby ); |
---|
159 | $order = strtoupper( $order ); |
---|
160 | |
---|
161 | if ( $orderby === 'Name' ) { |
---|
162 | if ( 'ASC' === $order ) { |
---|
163 | $this->items = array_reverse( $this->items ); |
---|
164 | } |
---|
165 | } else { |
---|
166 | uasort( $this->items, array( $this, '_order_callback' ) ); |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | $start = ( $page - 1 ) * $themes_per_page; |
---|
171 | |
---|
172 | if ( $total_this_page > $themes_per_page ) |
---|
173 | $this->items = array_slice( $this->items, $start, $themes_per_page, true ); |
---|
174 | |
---|
175 | $this->set_pagination_args( array( |
---|
176 | 'total_items' => $total_this_page, |
---|
177 | 'per_page' => $themes_per_page, |
---|
178 | ) ); |
---|
179 | } |
---|
180 | |
---|
181 | /** |
---|
182 | * @staticvar string $term |
---|
183 | * @param WP_Theme $theme |
---|
184 | * @return bool |
---|
185 | */ |
---|
186 | public function _search_callback( $theme ) { |
---|
187 | static $term = null; |
---|
188 | if ( is_null( $term ) ) |
---|
189 | $term = wp_unslash( $_REQUEST['s'] ); |
---|
190 | |
---|
191 | foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) { |
---|
192 | // Don't mark up; Do translate. |
---|
193 | if ( false !== stripos( $theme->display( $field, false, true ), $term ) ) |
---|
194 | return true; |
---|
195 | } |
---|
196 | |
---|
197 | if ( false !== stripos( $theme->get_stylesheet(), $term ) ) |
---|
198 | return true; |
---|
199 | |
---|
200 | if ( false !== stripos( $theme->get_template(), $term ) ) |
---|
201 | return true; |
---|
202 | |
---|
203 | return false; |
---|
204 | } |
---|
205 | |
---|
206 | // Not used by any core columns. |
---|
207 | /** |
---|
208 | * @global string $orderby |
---|
209 | * @global string $order |
---|
210 | * @param array $theme_a |
---|
211 | * @param array $theme_b |
---|
212 | * @return int |
---|
213 | */ |
---|
214 | public function _order_callback( $theme_a, $theme_b ) { |
---|
215 | global $orderby, $order; |
---|
216 | |
---|
217 | $a = $theme_a[ $orderby ]; |
---|
218 | $b = $theme_b[ $orderby ]; |
---|
219 | |
---|
220 | if ( $a == $b ) |
---|
221 | return 0; |
---|
222 | |
---|
223 | if ( 'DESC' === $order ) |
---|
224 | return ( $a < $b ) ? 1 : -1; |
---|
225 | else |
---|
226 | return ( $a < $b ) ? -1 : 1; |
---|
227 | } |
---|
228 | |
---|
229 | /** |
---|
230 | * @access public |
---|
231 | */ |
---|
232 | public function no_items() { |
---|
233 | if ( $this->has_items ) { |
---|
234 | _e( 'No themes found.' ); |
---|
235 | } else { |
---|
236 | _e( 'You do not appear to have any themes available at this time.' ); |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | /** |
---|
241 | * |
---|
242 | * @return array |
---|
243 | */ |
---|
244 | public function get_columns() { |
---|
245 | return array( |
---|
246 | 'cb' => '<input type="checkbox" />', |
---|
247 | 'name' => __( 'Theme' ), |
---|
248 | 'description' => __( 'Description' ), |
---|
249 | 'screenshot' => __( 'Screenshot' ), |
---|
250 | ); |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * |
---|
255 | * @return array |
---|
256 | */ |
---|
257 | protected function get_sortable_columns() { |
---|
258 | return array( |
---|
259 | 'name' => 'name', |
---|
260 | ); |
---|
261 | } |
---|
262 | |
---|
263 | /** |
---|
264 | * Gets the name of the primary column. |
---|
265 | * |
---|
266 | * @since 4.3.0 |
---|
267 | * @access protected |
---|
268 | * |
---|
269 | * @return string Unalterable name of the primary column name, in this case, 'name'. |
---|
270 | */ |
---|
271 | protected function get_primary_column_name() { |
---|
272 | return 'name'; |
---|
273 | } |
---|
274 | |
---|
275 | /** |
---|
276 | * |
---|
277 | * @global array $totals |
---|
278 | * @global string $status |
---|
279 | * @return array |
---|
280 | */ |
---|
281 | protected function get_views() { |
---|
282 | global $totals, $status; |
---|
283 | |
---|
284 | $status_links = array(); |
---|
285 | foreach ( $totals as $type => $count ) { |
---|
286 | if ( !$count ) |
---|
287 | continue; |
---|
288 | |
---|
289 | switch ( $type ) { |
---|
290 | case 'all': |
---|
291 | $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' ); |
---|
292 | break; |
---|
293 | case 'enabled': |
---|
294 | $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count ); |
---|
295 | break; |
---|
296 | case 'disabled': |
---|
297 | $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count ); |
---|
298 | break; |
---|
299 | case 'upgrade': |
---|
300 | $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count ); |
---|
301 | break; |
---|
302 | case 'broken' : |
---|
303 | $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count ); |
---|
304 | break; |
---|
305 | } |
---|
306 | |
---|
307 | if ( $this->is_site_themes ) |
---|
308 | $url = 'site-themes.php?id=' . $this->site_id; |
---|
309 | else |
---|
310 | $url = 'themes.php'; |
---|
311 | |
---|
312 | if ( 'search' != $type ) { |
---|
313 | $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>", |
---|
314 | esc_url( add_query_arg('theme_status', $type, $url) ), |
---|
315 | ( $type === $status ) ? ' class="current"' : '', |
---|
316 | sprintf( $text, number_format_i18n( $count ) ) |
---|
317 | ); |
---|
318 | } |
---|
319 | } |
---|
320 | |
---|
321 | return $status_links; |
---|
322 | } |
---|
323 | |
---|
324 | /** |
---|
325 | * @global string $status |
---|
326 | * |
---|
327 | * @return array |
---|
328 | */ |
---|
329 | protected function get_bulk_actions() { |
---|
330 | global $status; |
---|
331 | |
---|
332 | $actions = array(); |
---|
333 | if ( 'enabled' != $status ) |
---|
334 | $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ); |
---|
335 | if ( 'disabled' != $status ) |
---|
336 | $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ); |
---|
337 | if ( ! $this->is_site_themes ) { |
---|
338 | if ( current_user_can( 'update_themes' ) ) |
---|
339 | $actions['update-selected'] = __( 'Update' ); |
---|
340 | if ( current_user_can( 'delete_themes' ) ) |
---|
341 | $actions['delete-selected'] = __( 'Delete' ); |
---|
342 | } |
---|
343 | return $actions; |
---|
344 | } |
---|
345 | |
---|
346 | /** |
---|
347 | * @access public |
---|
348 | */ |
---|
349 | public function display_rows() { |
---|
350 | foreach ( $this->items as $theme ) |
---|
351 | $this->single_row( $theme ); |
---|
352 | } |
---|
353 | |
---|
354 | /** |
---|
355 | * Handles the checkbox column output. |
---|
356 | * |
---|
357 | * @since 4.3.0 |
---|
358 | * @access public |
---|
359 | * |
---|
360 | * @param WP_Theme $theme The current WP_Theme object. |
---|
361 | */ |
---|
362 | public function column_cb( $theme ) { |
---|
363 | $checkbox_id = 'checkbox_' . md5( $theme->get('Name') ); |
---|
364 | ?> |
---|
365 | <input type="checkbox" name="checked[]" value="<?php echo esc_attr( $theme->get_stylesheet() ) ?>" id="<?php echo $checkbox_id ?>" /> |
---|
366 | <label class="screen-reader-text" for="<?php echo $checkbox_id ?>" ><?php _e( 'Select' ) ?> <?php echo $theme->display( 'Name' ) ?></label> |
---|
367 | <?php |
---|
368 | } |
---|
369 | |
---|
370 | /** |
---|
371 | * Handles the name column output. |
---|
372 | * |
---|
373 | * @since 4.3.0 |
---|
374 | * @access public |
---|
375 | * |
---|
376 | * @global string $status |
---|
377 | * @global int $page |
---|
378 | * @global string $s |
---|
379 | * |
---|
380 | * @param WP_Theme $theme The current WP_Theme object. |
---|
381 | */ |
---|
382 | public function column_name( $theme ) { |
---|
383 | global $status, $page, $s; |
---|
384 | |
---|
385 | $context = $status; |
---|
386 | |
---|
387 | if ( $this->is_site_themes ) { |
---|
388 | $url = "site-themes.php?id={$this->site_id}&"; |
---|
389 | $allowed = $theme->is_allowed( 'site', $this->site_id ); |
---|
390 | } else { |
---|
391 | $url = 'themes.php?'; |
---|
392 | $allowed = $theme->is_allowed( 'network' ); |
---|
393 | } |
---|
394 | |
---|
395 | // Pre-order. |
---|
396 | $actions = array( |
---|
397 | 'enable' => '', |
---|
398 | 'disable' => '', |
---|
399 | 'edit' => '', |
---|
400 | 'delete' => '' |
---|
401 | ); |
---|
402 | |
---|
403 | $stylesheet = $theme->get_stylesheet(); |
---|
404 | $theme_key = urlencode( $stylesheet ); |
---|
405 | |
---|
406 | if ( ! $allowed ) { |
---|
407 | if ( ! $theme->errors() ) { |
---|
408 | $url = add_query_arg( array( |
---|
409 | 'action' => 'enable', |
---|
410 | 'theme' => $theme_key, |
---|
411 | 'paged' => $page, |
---|
412 | 's' => $s, |
---|
413 | ), $url ); |
---|
414 | |
---|
415 | if ( $this->is_site_themes ) { |
---|
416 | /* translators: %s: theme name */ |
---|
417 | $aria_label = sprintf( __( 'Enable %s' ), $theme->display( 'Name' ) ); |
---|
418 | } else { |
---|
419 | /* translators: %s: theme name */ |
---|
420 | $aria_label = sprintf( __( 'Network Enable %s' ), $theme->display( 'Name' ) ); |
---|
421 | } |
---|
422 | |
---|
423 | $actions['enable'] = sprintf( '<a href="%s" class="edit" aria-label="%s">%s</a>', |
---|
424 | esc_url( wp_nonce_url( $url, 'enable-theme_' . $stylesheet ) ), |
---|
425 | esc_attr( $aria_label ), |
---|
426 | ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) |
---|
427 | ); |
---|
428 | } |
---|
429 | } else { |
---|
430 | $url = add_query_arg( array( |
---|
431 | 'action' => 'disable', |
---|
432 | 'theme' => $theme_key, |
---|
433 | 'paged' => $page, |
---|
434 | 's' => $s, |
---|
435 | ), $url ); |
---|
436 | |
---|
437 | if ( $this->is_site_themes ) { |
---|
438 | /* translators: %s: theme name */ |
---|
439 | $aria_label = sprintf( __( 'Disable %s' ), $theme->display( 'Name' ) ); |
---|
440 | } else { |
---|
441 | /* translators: %s: theme name */ |
---|
442 | $aria_label = sprintf( __( 'Network Disable %s' ), $theme->display( 'Name' ) ); |
---|
443 | } |
---|
444 | |
---|
445 | $actions['disable'] = sprintf( '<a href="%s" aria-label="%s">%s</a>', |
---|
446 | esc_url( wp_nonce_url( $url, 'disable-theme_' . $stylesheet ) ), |
---|
447 | esc_attr( $aria_label ), |
---|
448 | ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) |
---|
449 | ); |
---|
450 | } |
---|
451 | |
---|
452 | if ( current_user_can('edit_themes') ) { |
---|
453 | $url = add_query_arg( array( |
---|
454 | 'theme' => $theme_key, |
---|
455 | ), 'theme-editor.php' ); |
---|
456 | |
---|
457 | /* translators: %s: theme name */ |
---|
458 | $aria_label = sprintf( __( 'Open %s in the Theme Editor' ), $theme->display( 'Name' ) ); |
---|
459 | |
---|
460 | $actions['edit'] = sprintf( '<a href="%s" class="edit" aria-label="%s">%s</a>', |
---|
461 | esc_url( $url ), |
---|
462 | esc_attr( $aria_label ), |
---|
463 | __( 'Edit' ) |
---|
464 | ); |
---|
465 | } |
---|
466 | |
---|
467 | if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) { |
---|
468 | $url = add_query_arg( array( |
---|
469 | 'action' => 'delete-selected', |
---|
470 | 'checked[]' => $theme_key, |
---|
471 | 'theme_status' => $context, |
---|
472 | 'paged' => $page, |
---|
473 | 's' => $s, |
---|
474 | ), 'themes.php' ); |
---|
475 | |
---|
476 | /* translators: %s: theme name */ |
---|
477 | $aria_label = sprintf( _x( 'Delete %s', 'theme' ), $theme->display( 'Name' ) ); |
---|
478 | |
---|
479 | $actions['delete'] = sprintf( '<a href="%s" class="delete" aria-label="%s">%s</a>', |
---|
480 | esc_url( wp_nonce_url( $url, 'bulk-themes' ) ), |
---|
481 | esc_attr( $aria_label ), |
---|
482 | __( 'Delete' ) |
---|
483 | ); |
---|
484 | } |
---|
485 | /** |
---|
486 | * Filters the action links displayed for each theme in the Multisite |
---|
487 | * themes list table. |
---|
488 | * |
---|
489 | * The action links displayed are determined by the theme's status, and |
---|
490 | * which Multisite themes list table is being displayed - the Network |
---|
491 | * themes list table (themes.php), which displays all installed themes, |
---|
492 | * or the Site themes list table (site-themes.php), which displays the |
---|
493 | * non-network enabled themes when editing a site in the Network admin. |
---|
494 | * |
---|
495 | * The default action links for the Network themes list table include |
---|
496 | * 'Network Enable', 'Network Disable', 'Edit', and 'Delete'. |
---|
497 | * |
---|
498 | * The default action links for the Site themes list table include |
---|
499 | * 'Enable', 'Disable', and 'Edit'. |
---|
500 | * |
---|
501 | * @since 2.8.0 |
---|
502 | * |
---|
503 | * @param array $actions An array of action links. |
---|
504 | * @param WP_Theme $theme The current WP_Theme object. |
---|
505 | * @param string $context Status of the theme. |
---|
506 | */ |
---|
507 | $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context ); |
---|
508 | |
---|
509 | /** |
---|
510 | * Filters the action links of a specific theme in the Multisite themes |
---|
511 | * list table. |
---|
512 | * |
---|
513 | * The dynamic portion of the hook name, `$stylesheet`, refers to the |
---|
514 | * directory name of the theme, which in most cases is synonymous |
---|
515 | * with the template name. |
---|
516 | * |
---|
517 | * @since 3.1.0 |
---|
518 | * |
---|
519 | * @param array $actions An array of action links. |
---|
520 | * @param WP_Theme $theme The current WP_Theme object. |
---|
521 | * @param string $context Status of the theme. |
---|
522 | */ |
---|
523 | $actions = apply_filters( "theme_action_links_{$stylesheet}", $actions, $theme, $context ); |
---|
524 | |
---|
525 | echo $this->row_actions( $actions, true ); |
---|
526 | } |
---|
527 | |
---|
528 | /** |
---|
529 | * Handles the description column output. |
---|
530 | * |
---|
531 | * @since 4.3.0 |
---|
532 | * @access public |
---|
533 | * |
---|
534 | * @global string $status |
---|
535 | * @global array $totals |
---|
536 | * |
---|
537 | * @param WP_Theme $theme The current WP_Theme object. |
---|
538 | */ |
---|
539 | public function column_description( $theme ) { |
---|
540 | |
---|
541 | global $status, $totals; |
---|
542 | if ( $theme->errors() ) { |
---|
543 | $pre = $status === 'broken' ? __( 'Broken Theme:' ) . ' ' : ''; |
---|
544 | echo '<p><strong class="error-message">' . $pre . $theme->errors()->get_error_message() . '</strong></p>'; |
---|
545 | } |
---|
546 | |
---|
547 | if ( $this->is_site_themes ) { |
---|
548 | $allowed = $theme->is_allowed( 'site', $this->site_id ); |
---|
549 | } else { |
---|
550 | $allowed = $theme->is_allowed( 'network' ); |
---|
551 | } |
---|
552 | |
---|
553 | $class = ! $allowed ? 'inactive' : 'active'; |
---|
554 | if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) |
---|
555 | $class .= ' update'; |
---|
556 | |
---|
557 | echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div> |
---|
558 | <div class='$class second theme-version-author-uri'>"; |
---|
559 | |
---|
560 | $stylesheet = $theme->get_stylesheet(); |
---|
561 | $theme_meta = array(); |
---|
562 | |
---|
563 | if ( $theme->get('Version') ) { |
---|
564 | $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') ); |
---|
565 | } |
---|
566 | $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); |
---|
567 | |
---|
568 | if ( $theme->get('ThemeURI') ) { |
---|
569 | /* translators: %s: theme name */ |
---|
570 | $aria_label = sprintf( __( 'Visit %s homepage' ), $theme->display( 'Name' ) ); |
---|
571 | |
---|
572 | $theme_meta[] = sprintf( '<a href="%s" aria-label="%s">%s</a>', |
---|
573 | $theme->display( 'ThemeURI' ), |
---|
574 | esc_attr( $aria_label ), |
---|
575 | __( 'Visit Theme Site' ) |
---|
576 | ); |
---|
577 | } |
---|
578 | /** |
---|
579 | * Filters the array of row meta for each theme in the Multisite themes |
---|
580 | * list table. |
---|
581 | * |
---|
582 | * @since 3.1.0 |
---|
583 | * |
---|
584 | * @param array $theme_meta An array of the theme's metadata, |
---|
585 | * including the version, author, and |
---|
586 | * theme URI. |
---|
587 | * @param string $stylesheet Directory name of the theme. |
---|
588 | * @param WP_Theme $theme WP_Theme object. |
---|
589 | * @param string $status Status of the theme. |
---|
590 | */ |
---|
591 | $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); |
---|
592 | echo implode( ' | ', $theme_meta ); |
---|
593 | |
---|
594 | echo '</div>'; |
---|
595 | } |
---|
596 | |
---|
597 | /** |
---|
598 | * Handles the screenshot column output. |
---|
599 | * |
---|
600 | * @since 4.3.0 |
---|
601 | * @access public |
---|
602 | * |
---|
603 | * @param WP_Theme $theme The current WP_Theme object. |
---|
604 | */ |
---|
605 | public function column_screenshot( $theme ) { |
---|
606 | |
---|
607 | echo '<img src="'.esc_url($theme->get_screenshot()).'" />'; |
---|
608 | |
---|
609 | } |
---|
610 | |
---|
611 | /** |
---|
612 | * Handles default column output. |
---|
613 | * |
---|
614 | * @since 4.3.0 |
---|
615 | * @access public |
---|
616 | * |
---|
617 | * @param WP_Theme $theme The current WP_Theme object. |
---|
618 | * @param string $column_name The current column name. |
---|
619 | */ |
---|
620 | public function column_default( $theme, $column_name ) { |
---|
621 | $stylesheet = $theme->get_stylesheet(); |
---|
622 | |
---|
623 | /** |
---|
624 | * Fires inside each custom column of the Multisite themes list table. |
---|
625 | * |
---|
626 | * @since 3.1.0 |
---|
627 | * |
---|
628 | * @param string $column_name Name of the column. |
---|
629 | * @param string $stylesheet Directory name of the theme. |
---|
630 | * @param WP_Theme $theme Current WP_Theme object. |
---|
631 | */ |
---|
632 | do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); |
---|
633 | } |
---|
634 | |
---|
635 | /** |
---|
636 | * Handles the output for a single table row. |
---|
637 | * |
---|
638 | * @since 4.3.0 |
---|
639 | * @access public |
---|
640 | * |
---|
641 | * @param WP_Theme $item The current WP_Theme object. |
---|
642 | */ |
---|
643 | public function single_row_columns( $item ) { |
---|
644 | list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); |
---|
645 | |
---|
646 | foreach ( $columns as $column_name => $column_display_name ) { |
---|
647 | $extra_classes = ''; |
---|
648 | if ( in_array( $column_name, $hidden ) ) { |
---|
649 | $extra_classes .= ' hidden'; |
---|
650 | } |
---|
651 | switch ( $column_name ) { |
---|
652 | case 'cb': |
---|
653 | echo '<th scope="row" class="check-column">'; |
---|
654 | |
---|
655 | $this->column_cb( $item ); |
---|
656 | |
---|
657 | echo '</th>'; |
---|
658 | break; |
---|
659 | |
---|
660 | case 'name': |
---|
661 | echo "<td class='theme-title column-primary{$extra_classes}'><strong>" . $item->display('Name') . "</strong>"; |
---|
662 | |
---|
663 | $this->column_name( $item ); |
---|
664 | |
---|
665 | echo "</td>"; |
---|
666 | break; |
---|
667 | |
---|
668 | case 'description': |
---|
669 | echo "<td class='column-description desc{$extra_classes}'>"; |
---|
670 | |
---|
671 | $this->column_description( $item ); |
---|
672 | |
---|
673 | echo '</td>'; |
---|
674 | break; |
---|
675 | |
---|
676 | case 'screenshot': |
---|
677 | echo "<td class='column-screenshot theme-screenshots{$extra_classes}'>"; |
---|
678 | |
---|
679 | $this->column_screenshot( $item ); |
---|
680 | |
---|
681 | echo '</td>'; |
---|
682 | break; |
---|
683 | default: |
---|
684 | echo "<td class='$column_name column-$column_name{$extra_classes}'>"; |
---|
685 | |
---|
686 | $this->column_default( $item, $column_name ); |
---|
687 | |
---|
688 | echo "</td>"; |
---|
689 | break; |
---|
690 | } |
---|
691 | } |
---|
692 | } |
---|
693 | |
---|
694 | /** |
---|
695 | * @global string $status |
---|
696 | * @global array $totals |
---|
697 | * |
---|
698 | * @param WP_Theme $theme |
---|
699 | */ |
---|
700 | public function single_row( $theme ) { |
---|
701 | global $status, $totals; |
---|
702 | |
---|
703 | if ( $this->is_site_themes ) { |
---|
704 | $allowed = $theme->is_allowed( 'site', $this->site_id ); |
---|
705 | } else { |
---|
706 | $allowed = $theme->is_allowed( 'network' ); |
---|
707 | } |
---|
708 | |
---|
709 | $stylesheet = $theme->get_stylesheet(); |
---|
710 | |
---|
711 | $class = ! $allowed ? 'inactive' : 'active'; |
---|
712 | if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) { |
---|
713 | $class .= ' update'; |
---|
714 | } |
---|
715 | |
---|
716 | printf( '<tr class="%s" data-slug="%s">', |
---|
717 | esc_attr( $class ), |
---|
718 | esc_attr( $stylesheet ) |
---|
719 | ); |
---|
720 | |
---|
721 | $this->single_row_columns( $theme ); |
---|
722 | |
---|
723 | echo "</tr>"; |
---|
724 | |
---|
725 | if ( $this->is_site_themes ) |
---|
726 | remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' ); |
---|
727 | |
---|
728 | /** |
---|
729 | * Fires after each row in the Multisite themes list table. |
---|
730 | * |
---|
731 | * @since 3.1.0 |
---|
732 | * |
---|
733 | * @param string $stylesheet Directory name of the theme. |
---|
734 | * @param WP_Theme $theme Current WP_Theme object. |
---|
735 | * @param string $status Status of the theme. |
---|
736 | */ |
---|
737 | do_action( 'after_theme_row', $stylesheet, $theme, $status ); |
---|
738 | |
---|
739 | /** |
---|
740 | * Fires after each specific row in the Multisite themes list table. |
---|
741 | * |
---|
742 | * The dynamic portion of the hook name, `$stylesheet`, refers to the |
---|
743 | * directory name of the theme, most often synonymous with the template |
---|
744 | * name of the theme. |
---|
745 | * |
---|
746 | * @since 3.5.0 |
---|
747 | * |
---|
748 | * @param string $stylesheet Directory name of the theme. |
---|
749 | * @param WP_Theme $theme Current WP_Theme object. |
---|
750 | * @param string $status Status of the theme. |
---|
751 | */ |
---|
752 | do_action( "after_theme_row_{$stylesheet}", $stylesheet, $theme, $status ); |
---|
753 | } |
---|
754 | } |
---|