3 * MS Themes List Table class.
6 * @subpackage List_Table
10 class WP_MS_Themes_List_Table extends WP_List_Table {
15 function __construct( $args = array() ) {
16 global $status, $page;
18 parent::__construct( array(
20 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
23 $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
24 if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) )
27 $page = $this->get_pagenum();
29 $this->is_site_themes = ( 'site-themes-network' == $this->screen->id ) ? true : false;
31 if ( $this->is_site_themes )
32 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
35 function get_table_classes() {
36 return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes
39 function ajax_user_can() {
40 if ( $this->is_site_themes )
41 return current_user_can( 'manage_sites' );
43 return current_user_can( 'manage_network_themes' );
46 function prepare_items() {
47 global $status, $totals, $page, $orderby, $order, $s;
49 wp_reset_vars( array( 'orderby', 'order', 's' ) );
53 * Filter the full array of WP_Theme objects to list in the Multisite
58 * @param array $all An array of WP_Theme objects to display in the list table.
60 'all' => apply_filters( 'all_themes', wp_get_themes() ),
63 'disabled' => array(),
65 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
68 if ( $this->is_site_themes ) {
69 $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
70 $allowed_where = 'site';
72 $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
73 $allowed_where = 'network';
76 $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
78 foreach ( (array) $themes['all'] as $key => $theme ) {
79 if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
80 unset( $themes['all'][ $key ] );
84 if ( $maybe_update && isset( $current->response[ $key ] ) ) {
85 $themes['all'][ $key ]->update = true;
86 $themes['upgrade'][ $key ] = $themes['all'][ $key ];
89 $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
90 $themes[ $filter ][ $key ] = $themes['all'][ $key ];
95 $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
99 foreach ( $themes as $type => $list )
100 $totals[ $type ] = count( $list );
102 if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
105 $this->items = $themes[ $status ];
106 WP_Theme::sort_by_name( $this->items );
108 $this->has_items = ! empty( $themes['all'] );
109 $total_this_page = $totals[ $status ];
112 $orderby = ucfirst( $orderby );
113 $order = strtoupper( $order );
115 if ( $orderby == 'Name' ) {
116 if ( 'ASC' == $order )
117 $this->items = array_reverse( $this->items );
119 uasort( $this->items, array( $this, '_order_callback' ) );
123 $start = ( $page - 1 ) * $themes_per_page;
125 if ( $total_this_page > $themes_per_page )
126 $this->items = array_slice( $this->items, $start, $themes_per_page, true );
128 $this->set_pagination_args( array(
129 'total_items' => $total_this_page,
130 'per_page' => $themes_per_page,
134 function _search_callback( $theme ) {
136 if ( is_null( $term ) )
137 $term = wp_unslash( $_REQUEST['s'] );
139 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
140 // Don't mark up; Do translate.
141 if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
145 if ( false !== stripos( $theme->get_stylesheet(), $term ) )
148 if ( false !== stripos( $theme->get_template(), $term ) )
154 // Not used by any core columns.
155 function _order_callback( $theme_a, $theme_b ) {
156 global $orderby, $order;
158 $a = $theme_a[ $orderby ];
159 $b = $theme_b[ $orderby ];
164 if ( 'DESC' == $order )
165 return ( $a < $b ) ? 1 : -1;
167 return ( $a < $b ) ? -1 : 1;
170 function no_items() {
171 if ( ! $this->has_items )
172 _e( 'No themes found.' );
174 _e( 'You do not appear to have any themes available at this time.' );
177 function get_columns() {
181 'cb' => '<input type="checkbox" />',
182 'name' => __( 'Theme' ),
183 'description' => __( 'Description' ),
187 function get_sortable_columns() {
193 function get_views() {
194 global $totals, $status;
196 $status_links = array();
197 foreach ( $totals as $type => $count ) {
203 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
206 $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
209 $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
212 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
215 $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
219 if ( $this->is_site_themes )
220 $url = 'site-themes.php?id=' . $this->site_id;
224 if ( 'search' != $type ) {
225 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
226 esc_url( add_query_arg('theme_status', $type, $url) ),
227 ( $type == $status ) ? ' class="current"' : '',
228 sprintf( $text, number_format_i18n( $count ) )
233 return $status_links;
236 function get_bulk_actions() {
240 if ( 'enabled' != $status )
241 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
242 if ( 'disabled' != $status )
243 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
244 if ( ! $this->is_site_themes ) {
245 if ( current_user_can( 'update_themes' ) )
246 $actions['update-selected'] = __( 'Update' );
247 if ( current_user_can( 'delete_themes' ) )
248 $actions['delete-selected'] = __( 'Delete' );
253 function display_rows() {
254 foreach ( $this->items as $theme )
255 $this->single_row( $theme );
258 function single_row( $theme ) {
259 global $status, $page, $s, $totals;
263 if ( $this->is_site_themes ) {
264 $url = "site-themes.php?id={$this->site_id}&";
265 $allowed = $theme->is_allowed( 'site', $this->site_id );
267 $url = 'themes.php?';
268 $allowed = $theme->is_allowed( 'network' );
279 $stylesheet = $theme->get_stylesheet();
280 $theme_key = urlencode( $stylesheet );
283 if ( ! $theme->errors() )
284 $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>';
286 $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>';
289 if ( current_user_can('edit_themes') )
290 $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>';
292 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) )
293 $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>';
296 * Filter the action links displayed for each theme in the Multisite
299 * The action links displayed are determined by the theme's status, and
300 * which Multisite themes list table is being displayed - the Network
301 * themes list table (themes.php), which displays all installed themes,
302 * or the Site themes list table (site-themes.php), which displays the
303 * non-network enabled themes when editing a site in the Network admin.
305 * The default action links for the Network themes list table include
306 * 'Network Enable', 'Network Disable', 'Edit', and 'Delete'.
308 * The default action links for the Site themes list table include
309 * 'Enable', 'Disable', and 'Edit'.
313 * @param array $actions An array of action links.
314 * @param WP_Theme $theme The current WP_Theme object.
315 * @param string $context Status of the theme.
317 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
320 * Filter the action links of a specific theme in the Multisite themes
323 * The dynamic portion of the hook name, $stylesheet, refers to the
324 * directory name of the theme, which in most cases is synonymous
325 * with the template name.
329 * @param array $actions An array of action links.
330 * @param WP_Theme $theme The current WP_Theme object.
331 * @param string $context Status of the theme.
333 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context );
335 $class = ! $allowed ? 'inactive' : 'active';
336 $checkbox_id = "checkbox_" . md5( $theme->get('Name') );
337 $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>";
339 $id = sanitize_html_class( $theme->get_stylesheet() );
341 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
344 echo "<tr id='$id' class='$class'>";
346 list( $columns, $hidden ) = $this->get_column_info();
348 foreach ( $columns as $column_name => $column_display_name ) {
350 if ( in_array( $column_name, $hidden ) )
351 $style = ' style="display:none;"';
353 switch ( $column_name ) {
355 echo "<th scope='row' class='check-column'>$checkbox</th>";
358 echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
359 echo $this->row_actions( $actions, true );
363 echo "<td class='column-description desc'$style>";
364 if ( $theme->errors() ) {
365 $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : '';
366 echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
368 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
369 <div class='$class second theme-version-author-uri'>";
371 $theme_meta = array();
373 if ( $theme->get('Version') )
374 $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
376 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
378 if ( $theme->get('ThemeURI') )
379 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
382 * Filter the array of row meta for each theme in the Multisite themes
387 * @param array $theme_meta An array of the theme's metadata,
388 * including the version, author, and
390 * @param string $stylesheet Directory name of the theme.
391 * @param WP_Theme $theme WP_Theme object.
392 * @param string $status Status of the theme.
394 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
395 echo implode( ' | ', $theme_meta );
401 echo "<td class='$column_name column-$column_name'$style>";
404 * Fires inside each custom column of the Multisite themes list table.
408 * @param string $column_name Name of the column.
409 * @param string $stylesheet Directory name of the theme.
410 * @param WP_Theme $theme Current WP_Theme object.
412 do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
419 if ( $this->is_site_themes )
420 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
423 * Fires after each row in the Multisite themes list table.
427 * @param string $stylesheet Directory name of the theme.
428 * @param WP_Theme $theme Current WP_Theme object.
429 * @param string $status Status of the theme.
431 do_action( 'after_theme_row', $stylesheet, $theme, $status );
434 * Fires after each specific row in the Multisite themes list table.
436 * The dynamic portion of the hook name, $stylesheet, refers to the
437 * directory name of the theme, most often synonymous with the template
442 * @param string $stylesheet Directory name of the theme.
443 * @param WP_Theme $theme Current WP_Theme object.
444 * @param string $status Status of the theme.
446 do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status );