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;
23 * @see WP_List_Table::__construct() for more information on default arguments.
25 * @param array $args An associative array of arguments.
27 public function __construct( $args = array() ) {
28 global $status, $page;
30 parent::__construct( array(
32 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
35 $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
36 if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) )
39 $page = $this->get_pagenum();
41 $this->is_site_themes = ( 'site-themes-network' == $this->screen->id ) ? true : false;
43 if ( $this->is_site_themes )
44 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
47 protected function get_table_classes() {
48 // todo: remove and add CSS for .themes
49 return array( 'widefat', 'plugins' );
52 public function ajax_user_can() {
53 if ( $this->is_site_themes )
54 return current_user_can( 'manage_sites' );
56 return current_user_can( 'manage_network_themes' );
59 public function prepare_items() {
60 global $status, $totals, $page, $orderby, $order, $s;
62 wp_reset_vars( array( 'orderby', 'order', 's' ) );
66 * Filter the full array of WP_Theme objects to list in the Multisite
71 * @param array $all An array of WP_Theme objects to display in the list table.
73 'all' => apply_filters( 'all_themes', wp_get_themes() ),
76 'disabled' => array(),
78 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
81 if ( $this->is_site_themes ) {
82 $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
83 $allowed_where = 'site';
85 $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
86 $allowed_where = 'network';
89 $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
91 foreach ( (array) $themes['all'] as $key => $theme ) {
92 if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
93 unset( $themes['all'][ $key ] );
97 if ( $maybe_update && isset( $current->response[ $key ] ) ) {
98 $themes['all'][ $key ]->update = true;
99 $themes['upgrade'][ $key ] = $themes['all'][ $key ];
102 $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
103 $themes[ $filter ][ $key ] = $themes['all'][ $key ];
108 $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
112 foreach ( $themes as $type => $list )
113 $totals[ $type ] = count( $list );
115 if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
118 $this->items = $themes[ $status ];
119 WP_Theme::sort_by_name( $this->items );
121 $this->has_items = ! empty( $themes['all'] );
122 $total_this_page = $totals[ $status ];
125 $orderby = ucfirst( $orderby );
126 $order = strtoupper( $order );
128 if ( $orderby == 'Name' ) {
129 if ( 'ASC' == $order )
130 $this->items = array_reverse( $this->items );
132 uasort( $this->items, array( $this, '_order_callback' ) );
136 $start = ( $page - 1 ) * $themes_per_page;
138 if ( $total_this_page > $themes_per_page )
139 $this->items = array_slice( $this->items, $start, $themes_per_page, true );
141 $this->set_pagination_args( array(
142 'total_items' => $total_this_page,
143 'per_page' => $themes_per_page,
148 * @staticvar string $term
149 * @param WP_Theme $theme
152 public function _search_callback( $theme ) {
154 if ( is_null( $term ) )
155 $term = wp_unslash( $_REQUEST['s'] );
157 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
158 // Don't mark up; Do translate.
159 if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
163 if ( false !== stripos( $theme->get_stylesheet(), $term ) )
166 if ( false !== stripos( $theme->get_template(), $term ) )
172 // Not used by any core columns.
174 * @global string $orderby
175 * @global string $order
176 * @param array $theme_a
177 * @param array $theme_b
180 public function _order_callback( $theme_a, $theme_b ) {
181 global $orderby, $order;
183 $a = $theme_a[ $orderby ];
184 $b = $theme_b[ $orderby ];
189 if ( 'DESC' == $order )
190 return ( $a < $b ) ? 1 : -1;
192 return ( $a < $b ) ? -1 : 1;
195 public function no_items() {
196 if ( ! $this->has_items )
197 _e( 'No themes found.' );
199 _e( 'You do not appear to have any themes available at this time.' );
202 public function get_columns() {
206 'cb' => '<input type="checkbox" />',
207 'name' => __( 'Theme' ),
208 'description' => __( 'Description' ),
212 protected function get_sortable_columns() {
218 protected function get_views() {
219 global $totals, $status;
221 $status_links = array();
222 foreach ( $totals as $type => $count ) {
228 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
231 $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
234 $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
237 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
240 $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
244 if ( $this->is_site_themes )
245 $url = 'site-themes.php?id=' . $this->site_id;
249 if ( 'search' != $type ) {
250 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
251 esc_url( add_query_arg('theme_status', $type, $url) ),
252 ( $type == $status ) ? ' class="current"' : '',
253 sprintf( $text, number_format_i18n( $count ) )
258 return $status_links;
261 protected function get_bulk_actions() {
265 if ( 'enabled' != $status )
266 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
267 if ( 'disabled' != $status )
268 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
269 if ( ! $this->is_site_themes ) {
270 if ( current_user_can( 'update_themes' ) )
271 $actions['update-selected'] = __( 'Update' );
272 if ( current_user_can( 'delete_themes' ) )
273 $actions['delete-selected'] = __( 'Delete' );
278 public function display_rows() {
279 foreach ( $this->items as $theme )
280 $this->single_row( $theme );
284 * @global string $status
287 * @global array $totals
288 * @param WP_Theme $theme
290 public function single_row( $theme ) {
291 global $status, $page, $s, $totals;
295 if ( $this->is_site_themes ) {
296 $url = "site-themes.php?id={$this->site_id}&";
297 $allowed = $theme->is_allowed( 'site', $this->site_id );
299 $url = 'themes.php?';
300 $allowed = $theme->is_allowed( 'network' );
311 $stylesheet = $theme->get_stylesheet();
312 $theme_key = urlencode( $stylesheet );
315 if ( ! $theme->errors() )
316 $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>';
318 $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>';
321 if ( current_user_can('edit_themes') )
322 $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>';
324 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) )
325 $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>';
328 * Filter the action links displayed for each theme in the Multisite
331 * The action links displayed are determined by the theme's status, and
332 * which Multisite themes list table is being displayed - the Network
333 * themes list table (themes.php), which displays all installed themes,
334 * or the Site themes list table (site-themes.php), which displays the
335 * non-network enabled themes when editing a site in the Network admin.
337 * The default action links for the Network themes list table include
338 * 'Network Enable', 'Network Disable', 'Edit', and 'Delete'.
340 * The default action links for the Site themes list table include
341 * 'Enable', 'Disable', and 'Edit'.
345 * @param array $actions An array of action links.
346 * @param WP_Theme $theme The current WP_Theme object.
347 * @param string $context Status of the theme.
349 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
352 * Filter the action links of a specific theme in the Multisite themes
355 * The dynamic portion of the hook name, `$stylesheet`, refers to the
356 * directory name of the theme, which in most cases is synonymous
357 * with the template name.
361 * @param array $actions An array of action links.
362 * @param WP_Theme $theme The current WP_Theme object.
363 * @param string $context Status of the theme.
365 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context );
367 $class = ! $allowed ? 'inactive' : 'active';
368 $checkbox_id = "checkbox_" . md5( $theme->get('Name') );
369 $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>";
371 $id = sanitize_html_class( $theme->get_stylesheet() );
373 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
376 echo "<tr id='$id' class='$class'>";
378 list( $columns, $hidden ) = $this->get_column_info();
380 foreach ( $columns as $column_name => $column_display_name ) {
382 if ( in_array( $column_name, $hidden ) )
383 $style = ' style="display:none;"';
385 switch ( $column_name ) {
387 echo "<th scope='row' class='check-column'>$checkbox</th>";
390 echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
391 echo $this->row_actions( $actions, true );
395 echo "<td class='column-description desc'$style>";
396 if ( $theme->errors() ) {
397 $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : '';
398 echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
400 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
401 <div class='$class second theme-version-author-uri'>";
403 $theme_meta = array();
405 if ( $theme->get('Version') )
406 $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
408 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
410 if ( $theme->get('ThemeURI') )
411 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
414 * Filter the array of row meta for each theme in the Multisite themes
419 * @param array $theme_meta An array of the theme's metadata,
420 * including the version, author, and
422 * @param string $stylesheet Directory name of the theme.
423 * @param WP_Theme $theme WP_Theme object.
424 * @param string $status Status of the theme.
426 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
427 echo implode( ' | ', $theme_meta );
433 echo "<td class='$column_name column-$column_name'$style>";
436 * Fires inside each custom column of the Multisite themes list table.
440 * @param string $column_name Name of the column.
441 * @param string $stylesheet Directory name of the theme.
442 * @param WP_Theme $theme Current WP_Theme object.
444 do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
451 if ( $this->is_site_themes )
452 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
455 * Fires after each row in the Multisite themes list table.
459 * @param string $stylesheet Directory name of the theme.
460 * @param WP_Theme $theme Current WP_Theme object.
461 * @param string $status Status of the theme.
463 do_action( 'after_theme_row', $stylesheet, $theme, $status );
466 * Fires after each specific row in the Multisite themes list table.
468 * The dynamic portion of the hook name, `$stylesheet`, refers to the
469 * directory name of the theme, most often synonymous with the template
474 * @param string $stylesheet Directory name of the theme.
475 * @param WP_Theme $theme Current WP_Theme object.
476 * @param string $status Status of the theme.
478 do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status );