3 * MS Themes List Table class.
6 * @subpackage List_Table
10 class WP_MS_Themes_List_Table extends WP_List_Table {
15 function __construct() {
16 global $status, $page;
18 $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all';
19 if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) )
22 $page = $this->get_pagenum();
24 $screen = get_current_screen();
25 $this->is_site_themes = ( 'site-themes-network' == $screen->id ) ? true : false;
27 if ( $this->is_site_themes )
28 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
30 parent::__construct( array(
35 function get_table_classes() {
36 return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes
39 function ajax_user_can() {
40 $menu_perms = get_site_option( 'menu_items', array() );
42 if ( empty( $menu_perms['themes'] ) && ! is_super_admin() )
45 if ( $this->is_site_themes && !current_user_can('manage_sites') )
47 elseif ( !$this->is_site_themes && !current_user_can('manage_network_themes') )
52 function prepare_items() {
53 global $status, $totals, $page, $orderby, $order, $s;
55 wp_reset_vars( array( 'orderby', 'order', 's' ) );
58 'all' => apply_filters( 'all_themes', wp_get_themes() ),
61 'disabled' => array(),
63 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
66 if ( $this->is_site_themes ) {
67 $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
68 $allowed_where = 'site';
70 $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
71 $allowed_where = 'network';
74 $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
76 foreach ( (array) $themes['all'] as $key => $theme ) {
77 if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
78 unset( $themes['all'][ $key ] );
82 if ( $maybe_update && isset( $current->response[ $key ] ) ) {
83 $themes['all'][ $key ]->update = true;
84 $themes['upgrade'][ $key ] = $themes['all'][ $key ];
87 $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
88 $themes[ $filter ][ $key ] = $themes['all'][ $key ];
93 $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( &$this, '_search_callback' ) );
97 foreach ( $themes as $type => $list )
98 $totals[ $type ] = count( $list );
100 if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
103 $this->items = $themes[ $status ];
104 WP_Theme::sort_by_name( $this->items );
106 $this->has_items = ! empty( $themes['all'] );
107 $total_this_page = $totals[ $status ];
110 $orderby = ucfirst( $orderby );
111 $order = strtoupper( $order );
113 if ( $orderby == 'Name' ) {
114 if ( 'ASC' == $order )
115 $this->items = array_reverse( $this->items );
117 uasort( $this->items, array( &$this, '_order_callback' ) );
121 $start = ( $page - 1 ) * $themes_per_page;
123 if ( $total_this_page > $themes_per_page )
124 $this->items = array_slice( $this->items, $start, $themes_per_page, true );
126 $this->set_pagination_args( array(
127 'total_items' => $total_this_page,
128 'per_page' => $themes_per_page,
132 function _search_callback( $theme ) {
134 if ( is_null( $term ) )
135 $term = stripslashes( $_REQUEST['s'] );
137 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
138 // Don't mark up; Do translate.
139 if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
143 if ( false !== stripos( $theme->get_stylesheet(), $term ) )
146 if ( false !== stripos( $theme->get_template(), $term ) )
152 // Not used by any core columns.
153 function _order_callback( $theme_a, $theme_b ) {
154 global $orderby, $order;
156 $a = $theme_a[ $orderby ];
157 $b = $theme_b[ $orderby ];
162 if ( 'DESC' == $order )
163 return ( $a < $b ) ? 1 : -1;
165 return ( $a < $b ) ? -1 : 1;
168 function no_items() {
169 if ( ! $this->has_items )
170 _e( 'No themes found.' );
172 _e( 'You do not appear to have any themes available at this time.' );
175 function get_columns() {
179 'cb' => '<input type="checkbox" />',
180 'name' => __( 'Theme' ),
181 'description' => __( 'Description' ),
185 function get_sortable_columns() {
191 function get_views() {
192 global $totals, $status;
194 $status_links = array();
195 foreach ( $totals as $type => $count ) {
201 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
204 $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
207 $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
210 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
213 $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
217 if ( $this->is_site_themes )
218 $url = 'site-themes.php?id=' . $this->site_id;
222 if ( 'search' != $type ) {
223 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
224 esc_url( add_query_arg('theme_status', $type, $url) ),
225 ( $type == $status ) ? ' class="current"' : '',
226 sprintf( $text, number_format_i18n( $count ) )
231 return $status_links;
234 function get_bulk_actions() {
238 if ( 'enabled' != $status )
239 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
240 if ( 'disabled' != $status )
241 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
242 if ( ! $this->is_site_themes ) {
243 if ( current_user_can( 'delete_themes' ) )
244 $actions['delete-selected'] = __( 'Delete' );
245 if ( current_user_can( 'update_themes' ) )
246 $actions['update-selected'] = __( 'Update' );
251 function bulk_actions( $which ) {
253 parent::bulk_actions( $which );
256 function current_action() {
257 return parent::current_action();
260 function display_rows() {
261 foreach ( $this->items as $key => $theme )
262 $this->single_row( $key, $theme );
265 function single_row( $key, $theme ) {
266 global $status, $page, $s, $totals;
270 if ( $this->is_site_themes ) {
271 $url = "site-themes.php?id={$this->site_id}&";
272 $allowed = $theme->is_allowed( 'site', $this->site_id );
274 $url = 'themes.php?';
275 $allowed = $theme->is_allowed( 'network' );
286 $theme_key = $theme->get_stylesheet();
289 if ( ! $theme->errors() )
290 $actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'enable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
292 $actions['disable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=disable&theme=' . $theme_key . '&paged=' . $page . '&s=' . $s, 'disable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Disable this theme') . '">' . ( $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ) ) . '</a>';
295 if ( current_user_can('edit_themes') )
296 $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . urlencode( $theme_key ) ) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
298 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) )
299 $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>';
301 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context );
302 $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context );
304 $class = ! $allowed ? 'inactive' : 'active';
305 $checkbox_id = "checkbox_" . md5( $theme->get('Name') );
306 $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $theme_key ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme->display('Name') . "</label>";
308 $id = sanitize_html_class( $theme->get_stylesheet() );
310 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
313 echo "<tr id='$id' class='$class'>";
315 list( $columns, $hidden ) = $this->get_column_info();
317 foreach ( $columns as $column_name => $column_display_name ) {
319 if ( in_array( $column_name, $hidden ) )
320 $style = ' style="display:none;"';
322 switch ( $column_name ) {
324 echo "<th scope='row' class='check-column'>$checkbox</th>";
327 echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
328 echo $this->row_actions( $actions, true );
332 echo "<td class='column-description desc'$style>";
333 if ( $theme->errors() ) {
334 $pre = $status == 'broken' ? '' : __( 'Broken Theme:' ) . ' ';
335 echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
337 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
338 <div class='$class second theme-version-author-uri'>";
340 $theme_meta = array();
342 if ( $theme->get('Version') )
343 $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
345 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
347 if ( $theme->get('ThemeURI') )
348 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
350 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status );
351 echo implode( ' | ', $theme_meta );
357 echo "<td class='$column_name column-$column_name'$style>";
358 do_action( 'manage_themes_custom_column', $column_name, $theme_key, $theme );
365 if ( $this->is_site_themes )
366 remove_action( "after_theme_row_$theme_key", 'wp_theme_update_row' );
367 do_action( 'after_theme_row', $theme_key, $theme, $status );
368 do_action( "after_theme_row_$theme_key", $theme_key, $theme, $status );