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' ) );
52 'all' => apply_filters( 'all_themes', wp_get_themes() ),
55 'disabled' => array(),
57 'broken' => $this->is_site_themes ? array() : wp_get_themes( array( 'errors' => true ) ),
60 if ( $this->is_site_themes ) {
61 $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
62 $allowed_where = 'site';
64 $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
65 $allowed_where = 'network';
68 $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current = get_site_transient( 'update_themes' );
70 foreach ( (array) $themes['all'] as $key => $theme ) {
71 if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
72 unset( $themes['all'][ $key ] );
76 if ( $maybe_update && isset( $current->response[ $key ] ) ) {
77 $themes['all'][ $key ]->update = true;
78 $themes['upgrade'][ $key ] = $themes['all'][ $key ];
81 $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
82 $themes[ $filter ][ $key ] = $themes['all'][ $key ];
87 $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
91 foreach ( $themes as $type => $list )
92 $totals[ $type ] = count( $list );
94 if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
97 $this->items = $themes[ $status ];
98 WP_Theme::sort_by_name( $this->items );
100 $this->has_items = ! empty( $themes['all'] );
101 $total_this_page = $totals[ $status ];
104 $orderby = ucfirst( $orderby );
105 $order = strtoupper( $order );
107 if ( $orderby == 'Name' ) {
108 if ( 'ASC' == $order )
109 $this->items = array_reverse( $this->items );
111 uasort( $this->items, array( $this, '_order_callback' ) );
115 $start = ( $page - 1 ) * $themes_per_page;
117 if ( $total_this_page > $themes_per_page )
118 $this->items = array_slice( $this->items, $start, $themes_per_page, true );
120 $this->set_pagination_args( array(
121 'total_items' => $total_this_page,
122 'per_page' => $themes_per_page,
126 function _search_callback( $theme ) {
128 if ( is_null( $term ) )
129 $term = wp_unslash( $_REQUEST['s'] );
131 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
132 // Don't mark up; Do translate.
133 if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
137 if ( false !== stripos( $theme->get_stylesheet(), $term ) )
140 if ( false !== stripos( $theme->get_template(), $term ) )
146 // Not used by any core columns.
147 function _order_callback( $theme_a, $theme_b ) {
148 global $orderby, $order;
150 $a = $theme_a[ $orderby ];
151 $b = $theme_b[ $orderby ];
156 if ( 'DESC' == $order )
157 return ( $a < $b ) ? 1 : -1;
159 return ( $a < $b ) ? -1 : 1;
162 function no_items() {
163 if ( ! $this->has_items )
164 _e( 'No themes found.' );
166 _e( 'You do not appear to have any themes available at this time.' );
169 function get_columns() {
173 'cb' => '<input type="checkbox" />',
174 'name' => __( 'Theme' ),
175 'description' => __( 'Description' ),
179 function get_sortable_columns() {
185 function get_views() {
186 global $totals, $status;
188 $status_links = array();
189 foreach ( $totals as $type => $count ) {
195 $text = _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'themes' );
198 $text = _n( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', $count );
201 $text = _n( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', $count );
204 $text = _n( 'Update Available <span class="count">(%s)</span>', 'Update Available <span class="count">(%s)</span>', $count );
207 $text = _n( 'Broken <span class="count">(%s)</span>', 'Broken <span class="count">(%s)</span>', $count );
211 if ( $this->is_site_themes )
212 $url = 'site-themes.php?id=' . $this->site_id;
216 if ( 'search' != $type ) {
217 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
218 esc_url( add_query_arg('theme_status', $type, $url) ),
219 ( $type == $status ) ? ' class="current"' : '',
220 sprintf( $text, number_format_i18n( $count ) )
225 return $status_links;
228 function get_bulk_actions() {
232 if ( 'enabled' != $status )
233 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
234 if ( 'disabled' != $status )
235 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
236 if ( ! $this->is_site_themes ) {
237 if ( current_user_can( 'update_themes' ) )
238 $actions['update-selected'] = __( 'Update' );
239 if ( current_user_can( 'delete_themes' ) )
240 $actions['delete-selected'] = __( 'Delete' );
245 function display_rows() {
246 foreach ( $this->items as $theme )
247 $this->single_row( $theme );
250 function single_row( $theme ) {
251 global $status, $page, $s, $totals;
255 if ( $this->is_site_themes ) {
256 $url = "site-themes.php?id={$this->site_id}&";
257 $allowed = $theme->is_allowed( 'site', $this->site_id );
259 $url = 'themes.php?';
260 $allowed = $theme->is_allowed( 'network' );
271 $stylesheet = $theme->get_stylesheet();
272 $theme_key = urlencode( $stylesheet );
275 if ( ! $theme->errors() )
276 $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>';
278 $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>';
281 if ( current_user_can('edit_themes') )
282 $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>';
284 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) )
285 $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>';
287 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context );
288 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context );
290 $class = ! $allowed ? 'inactive' : 'active';
291 $checkbox_id = "checkbox_" . md5( $theme->get('Name') );
292 $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>";
294 $id = sanitize_html_class( $theme->get_stylesheet() );
296 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) )
299 echo "<tr id='$id' class='$class'>";
301 list( $columns, $hidden ) = $this->get_column_info();
303 foreach ( $columns as $column_name => $column_display_name ) {
305 if ( in_array( $column_name, $hidden ) )
306 $style = ' style="display:none;"';
308 switch ( $column_name ) {
310 echo "<th scope='row' class='check-column'>$checkbox</th>";
313 echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
314 echo $this->row_actions( $actions, true );
318 echo "<td class='column-description desc'$style>";
319 if ( $theme->errors() ) {
320 $pre = $status == 'broken' ? '' : __( 'Broken Theme:' ) . ' ';
321 echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>';
323 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div>
324 <div class='$class second theme-version-author-uri'>";
326 $theme_meta = array();
328 if ( $theme->get('Version') )
329 $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
331 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
333 if ( $theme->get('ThemeURI') )
334 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
336 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status );
337 echo implode( ' | ', $theme_meta );
343 echo "<td class='$column_name column-$column_name'$style>";
344 do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme );
351 if ( $this->is_site_themes )
352 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' );
353 do_action( 'after_theme_row', $stylesheet, $theme, $status );
354 do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status );