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,
146 * @staticvar string $term
147 * @param WP_Theme $theme
150 public function _search_callback( $theme ) {
152 if ( is_null( $term ) )
153 $term = wp_unslash( $_REQUEST['s'] );
155 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
156 // Don't mark up; Do translate.
157 if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
161 if ( false !== stripos( $theme->get_stylesheet(), $term ) )
164 if ( false !== stripos( $theme->get_template(), $term ) )
170 // Not used by any core columns.
172 * @global string $orderby
173 * @global string $order
174 * @param array $theme_a
175 * @param array $theme_b
178 public function _order_callback( $theme_a, $theme_b ) {
179 global $orderby, $order;
181 $a = $theme_a[ $orderby ];
182 $b = $theme_b[ $orderby ];
187 if ( 'DESC' == $order )
188 return ( $a < $b ) ? 1 : -1;
190 return ( $a < $b ) ? -1 : 1;
193 public function no_items() {
194 if ( ! $this->has_items )
195 _e( 'No themes found.' );
197 _e( 'You do not appear to have any themes available at this time.' );
200 public function get_columns() {
204 'cb' => '<input type="checkbox" />',
205 'name' => __( 'Theme' ),
206 'description' => __( 'Description' ),
210 protected function get_sortable_columns() {
216 protected function get_views() {
217 global $totals, $status;
219 $status_links = array();
220 foreach ( $totals as $type => $count ) {
226 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
229 $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
232 $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
235 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
238 $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
242 if ( $this->is_site_themes )
243 $url = 'site-themes.php?id=' . $this->site_id;
247 if ( 'search' != $type ) {
248 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
249 esc_url( add_query_arg('theme_status', $type, $url) ),
250 ( $type == $status ) ? ' class="current"' : '',
251 sprintf( $text, number_format_i18n( $count ) )
256 return $status_links;
259 protected function get_bulk_actions() {
263 if ( 'enabled' != $status )
264 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
265 if ( 'disabled' != $status )
266 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
267 if ( ! $this->is_site_themes ) {
268 if ( current_user_can( 'update_themes' ) )
269 $actions['update-selected'] = __( 'Update' );
270 if ( current_user_can( 'delete_themes' ) )
271 $actions['delete-selected'] = __( 'Delete' );
276 public function display_rows() {
277 foreach ( $this->items as $theme )
278 $this->single_row( $theme );
282 * @global string $status
285 * @global array $totals
286 * @param WP_Theme $theme
288 public function single_row( $theme ) {
289 global $status, $page, $s, $totals;
293 if ( $this->is_site_themes ) {
294 $url = "site-themes.php?id={$this->site_id}&";
295 $allowed = $theme->is_allowed( 'site', $this->site_id );
297 $url = 'themes.php?';
298 $allowed = $theme->is_allowed( 'network' );
309 $stylesheet = $theme->get_stylesheet();
310 $theme_key = urlencode( $stylesheet );
313 if ( ! $theme->errors() )
314 $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>';
316 $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>';
319 if ( current_user_can('edit_themes') )
320 $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>';
322 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) )
323 $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>';
326 * Filter the action links displayed for each theme in the Multisite
329 * The action links displayed are determined by the theme's status, and
330 * which Multisite themes list table is being displayed - the Network
331 * themes list table (themes.php), which displays all installed themes,
332 * or the Site themes list table (site-themes.php), which displays the
333 * non-network enabled themes when editing a site in the Network admin.
335 * The default action links for the Network themes list table include
336 * 'Network Enable', 'Network Disable', 'Edit', and 'Delete'.
338 * The default action links for the Site themes list table include
339 * 'Enable', 'Disable', and 'Edit'.
343 * @param array $actions An array of action links.
344 * @param WP_Theme $theme The current WP_Theme object.
345 * @param string $context Status of the theme.
347 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
350 * Filter the action links of a specific theme in the Multisite themes
353 * The dynamic portion of the hook name, `$stylesheet`, refers to the
354 * directory name of the theme, which in most cases is synonymous
355 * with the template name.
359 * @param array $actions An array of action links.
360 * @param WP_Theme $theme The current WP_Theme object.
361 * @param string $context Status of the theme.
363 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context );
365 $class = ! $allowed ? 'inactive' : 'active';
366 $checkbox_id = "checkbox_" . md5( $theme->get('Name') );
367 $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>";
369 $id = sanitize_html_class( $theme->get_stylesheet() );
371 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
374 echo "<tr id='$id' class='$class'>";
376 list( $columns, $hidden ) = $this->get_column_info();
378 foreach ( $columns as $column_name => $column_display_name ) {
380 if ( in_array( $column_name, $hidden ) )
381 $style = ' style="display:none;"';
383 switch ( $column_name ) {
385 echo "<th scope='row' class='check-column'>$checkbox</th>";
388 echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
389 echo $this->row_actions( $actions, true );
393 echo "<td class='column-description desc'$style>";
394 if ( $theme->errors() ) {
395 $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : '';
396 echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
398 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
399 <div class='$class second theme-version-author-uri'>";
401 $theme_meta = array();
403 if ( $theme->get('Version') )
404 $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
406 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
408 if ( $theme->get('ThemeURI') )
409 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
412 * Filter the array of row meta for each theme in the Multisite themes
417 * @param array $theme_meta An array of the theme's metadata,
418 * including the version, author, and
420 * @param string $stylesheet Directory name of the theme.
421 * @param WP_Theme $theme WP_Theme object.
422 * @param string $status Status of the theme.
424 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
425 echo implode( ' | ', $theme_meta );
431 echo "<td class='$column_name column-$column_name'$style>";
434 * Fires inside each custom column of the Multisite themes list table.
438 * @param string $column_name Name of the column.
439 * @param string $stylesheet Directory name of the theme.
440 * @param WP_Theme $theme Current WP_Theme object.
442 do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
449 if ( $this->is_site_themes )
450 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
453 * Fires after each row in the Multisite themes list table.
457 * @param string $stylesheet Directory name of the theme.
458 * @param WP_Theme $theme Current WP_Theme object.
459 * @param string $status Status of the theme.
461 do_action( 'after_theme_row', $stylesheet, $theme, $status );
464 * Fires after each specific row in the Multisite themes list table.
466 * The dynamic portion of the hook name, `$stylesheet`, refers to the
467 * directory name of the theme, most often synonymous with the template
472 * @param string $stylesheet Directory name of the theme.
473 * @param WP_Theme $theme Current WP_Theme object.
474 * @param string $status Status of the theme.
476 do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status );