3
* MS Themes List Table class.
6
* @subpackage List_Table
10
class WP_MS_Themes_List_Table extends WP_List_Table {
13
public $is_site_themes;
21
* @see WP_List_Table::__construct() for more information on default arguments.
23
* @param array $args An associative array of arguments.
25
public function __construct( $args = array() ) {
26
global $status, $page;
28
parent::__construct( array(
30
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
33
$status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
34
if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) )
37
$page = $this->get_pagenum();
39
$this->is_site_themes = ( 'site-themes-network' == $this->screen->id ) ? true : false;
41
if ( $this->is_site_themes )
42
$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
45
protected function get_table_classes() {
46
// todo: remove and add CSS for .themes
47
return array( 'widefat', 'plugins' );
50
public function ajax_user_can() {
51
if ( $this->is_site_themes )
52
return current_user_can( 'manage_sites' );
54
return current_user_can( 'manage_network_themes' );
57
public function prepare_items() {
58
global $status, $totals, $page, $orderby, $order, $s;
60
wp_reset_vars( array( 'orderby', 'order', 's' ) );
64
* Filter the full array of WP_Theme objects to list in the Multisite
69
* @param array $all An array of WP_Theme objects to display in the list table.
71
'all' => apply_filters( 'all_themes', wp_get_themes() ),
74
'disabled' => array(),
76
'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
79
if ( $this->is_site_themes ) {
80
$themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
81
$allowed_where = 'site';
83
$themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
84
$allowed_where = 'network';
87
$maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
89
foreach ( (array) $themes['all'] as $key => $theme ) {
90
if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
91
unset( $themes['all'][ $key ] );
95
if ( $maybe_update && isset( $current->response[ $key ] ) ) {
96
$themes['all'][ $key ]->update = true;
97
$themes['upgrade'][ $key ] = $themes['all'][ $key ];
100
$filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
101
$themes[ $filter ][ $key ] = $themes['all'][ $key ];
106
$themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
110
foreach ( $themes as $type => $list )
111
$totals[ $type ] = count( $list );
113
if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
116
$this->items = $themes[ $status ];
117
WP_Theme::sort_by_name( $this->items );
119
$this->has_items = ! empty( $themes['all'] );
120
$total_this_page = $totals[ $status ];
123
$orderby = ucfirst( $orderby );
124
$order = strtoupper( $order );
126
if ( $orderby == 'Name' ) {
127
if ( 'ASC' == $order )
128
$this->items = array_reverse( $this->items );
130
uasort( $this->items, array( $this, '_order_callback' ) );
134
$start = ( $page - 1 ) * $themes_per_page;
136
if ( $total_this_page > $themes_per_page )
137
$this->items = array_slice( $this->items, $start, $themes_per_page, true );
139
$this->set_pagination_args( array(
140
'total_items' => $total_this_page,
141
'per_page' => $themes_per_page,
145
public function _search_callback( $theme ) {
147
if ( is_null( $term ) )
148
$term = wp_unslash( $_REQUEST['s'] );
150
foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
151
// Don't mark up; Do translate.
152
if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
156
if ( false !== stripos( $theme->get_stylesheet(), $term ) )
159
if ( false !== stripos( $theme->get_template(), $term ) )
165
// Not used by any core columns.
166
public function _order_callback( $theme_a, $theme_b ) {
167
global $orderby, $order;
169
$a = $theme_a[ $orderby ];
170
$b = $theme_b[ $orderby ];
175
if ( 'DESC' == $order )
176
return ( $a < $b ) ? 1 : -1;
178
return ( $a < $b ) ? -1 : 1;
181
public function no_items() {
182
if ( ! $this->has_items )
183
_e( 'No themes found.' );
185
_e( 'You do not appear to have any themes available at this time.' );
188
public function get_columns() {
192
'cb' => '<input type="checkbox" />',
193
'name' => __( 'Theme' ),
194
'description' => __( 'Description' ),
198
protected function get_sortable_columns() {
204
protected function get_views() {
205
global $totals, $status;
207
$status_links = array();
208
foreach ( $totals as $type => $count ) {
214
$text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
217
$text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
220
$text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
223
$text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
226
$text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
230
if ( $this->is_site_themes )
231
$url = 'site-themes.php?id=' . $this->site_id;
235
if ( 'search' != $type ) {
236
$status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
237
esc_url( add_query_arg('theme_status', $type, $url) ),
238
( $type == $status ) ? ' class="current"' : '',
239
sprintf( $text, number_format_i18n( $count ) )
244
return $status_links;
247
protected function get_bulk_actions() {
251
if ( 'enabled' != $status )
252
$actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
253
if ( 'disabled' != $status )
254
$actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
255
if ( ! $this->is_site_themes ) {
256
if ( current_user_can( 'update_themes' ) )
257
$actions['update-selected'] = __( 'Update' );
258
if ( current_user_can( 'delete_themes' ) )
259
$actions['delete-selected'] = __( 'Delete' );
264
public function display_rows() {
265
foreach ( $this->items as $theme )
266
$this->single_row( $theme );
269
public function single_row( $theme ) {
270
global $status, $page, $s, $totals;
274
if ( $this->is_site_themes ) {
275
$url = "site-themes.php?id={$this->site_id}&";
276
$allowed = $theme->is_allowed( 'site', $this->site_id );
278
$url = 'themes.php?';
279
$allowed = $theme->is_allowed( 'network' );
290
$stylesheet = $theme->get_stylesheet();
291
$theme_key = urlencode( $stylesheet );
294
if ( ! $theme->errors() )
295
$actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
297
$actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'disable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>';
300
if ( current_user_can('edit_themes') )
301
$actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . $theme_key ) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
303
if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) )
304
$actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&checked[]=' . $theme_key . '&theme_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>';
307
* Filter the action links displayed for each theme in the Multisite
310
* The action links displayed are determined by the theme's status, and
311
* which Multisite themes list table is being displayed - the Network
312
* themes list table (themes.php), which displays all installed themes,
313
* or the Site themes list table (site-themes.php), which displays the
314
* non-network enabled themes when editing a site in the Network admin.
316
* The default action links for the Network themes list table include
317
* 'Network Enable', 'Network Disable', 'Edit', and 'Delete'.
319
* The default action links for the Site themes list table include
320
* 'Enable', 'Disable', and 'Edit'.
324
* @param array $actions An array of action links.
325
* @param WP_Theme $theme The current WP_Theme object.
326
* @param string $context Status of the theme.
328
$actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
331
* Filter the action links of a specific theme in the Multisite themes
334
* The dynamic portion of the hook name, $stylesheet, refers to the
335
* directory name of the theme, which in most cases is synonymous
336
* with the template name.
340
* @param array $actions An array of action links.
341
* @param WP_Theme $theme The current WP_Theme object.
342
* @param string $context Status of the theme.
344
$actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context );
346
$class = ! $allowed ? 'inactive' : 'active';
347
$checkbox_id = "checkbox_" . md5( $theme->get('Name') );
348
$checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $stylesheet ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme->display('Name') . "</label>";
350
$id = sanitize_html_class( $theme->get_stylesheet() );
352
if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
355
echo "<tr id='$id' class='$class'>";
357
list( $columns, $hidden ) = $this->get_column_info();
359
foreach ( $columns as $column_name => $column_display_name ) {
361
if ( in_array( $column_name, $hidden ) )
362
$style = ' style="display:none;"';
364
switch ( $column_name ) {
366
echo "<th scope='row' class='check-column'>$checkbox</th>";
369
echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
370
echo $this->row_actions( $actions, true );
374
echo "<td class='column-description desc'$style>";
375
if ( $theme->errors() ) {
376
$pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : '';
377
echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
379
echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
380
<div class='$class second theme-version-author-uri'>";
382
$theme_meta = array();
384
if ( $theme->get('Version') )
385
$theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
387
$theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
389
if ( $theme->get('ThemeURI') )
390
$theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
393
* Filter the array of row meta for each theme in the Multisite themes
398
* @param array $theme_meta An array of the theme's metadata,
399
* including the version, author, and
401
* @param string $stylesheet Directory name of the theme.
402
* @param WP_Theme $theme WP_Theme object.
403
* @param string $status Status of the theme.
405
$theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
406
echo implode( ' | ', $theme_meta );
412
echo "<td class='$column_name column-$column_name'$style>";
415
* Fires inside each custom column of the Multisite themes list table.
419
* @param string $column_name Name of the column.
420
* @param string $stylesheet Directory name of the theme.
421
* @param WP_Theme $theme Current WP_Theme object.
423
do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
430
if ( $this->is_site_themes )
431
remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
434
* Fires after each row in the Multisite themes list table.
438
* @param string $stylesheet Directory name of the theme.
439
* @param WP_Theme $theme Current WP_Theme object.
440
* @param string $status Status of the theme.
442
do_action( 'after_theme_row', $stylesheet, $theme, $status );
445
* Fires after each specific row in the Multisite themes list table.
447
* The dynamic portion of the hook name, $stylesheet, refers to the
448
* directory name of the theme, most often synonymous with the template
453
* @param string $stylesheet Directory name of the theme.
454
* @param WP_Theme $theme Current WP_Theme object.
455
* @param string $status Status of the theme.
457
do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status );