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 $default_status = get_user_option( 'themes_last_view' );
19 if ( empty( $default_status ) )
20 $default_status = 'all';
21 $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : $default_status;
22 if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search' ) ) )
24 if ( $status != $default_status && 'search' != $status )
25 update_user_meta( get_current_user_id(), 'themes_last_view', $status );
27 $page = $this->get_pagenum();
29 $screen = get_current_screen();
30 $this->is_site_themes = ( 'site-themes-network' == $screen->id ) ? true : false;
32 if ( $this->is_site_themes )
33 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
35 parent::__construct( array(
40 function get_table_classes() {
41 return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes
44 function ajax_user_can() {
45 $menu_perms = get_site_option( 'menu_items', array() );
47 if ( empty( $menu_perms['themes'] ) && ! is_super_admin() )
50 if ( $this->is_site_themes && !current_user_can('manage_sites') )
52 elseif ( !$this->is_site_themes && !current_user_can('manage_network_themes') )
57 function prepare_items() {
58 global $status, $themes, $totals, $page, $orderby, $order, $s;
60 wp_reset_vars( array( 'orderby', 'order', 's' ) );
63 'all' => apply_filters( 'all_themes', get_themes() ),
66 'disabled' => array(),
70 $site_allowed_themes = get_site_allowed_themes();
71 if ( !$this->is_site_themes ) {
72 $allowed_themes = $site_allowed_themes;
73 $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
75 $allowed_themes = wpmu_get_blog_allowedthemes( $this->site_id );
76 $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
79 $current = get_site_transient( 'update_themes' );
81 foreach ( (array) $themes['all'] as $key => $theme ) {
82 $theme_key = $theme['Stylesheet'];
84 if ( isset( $allowed_themes [ $theme_key ] ) ) {
85 $themes['all'][$key]['enabled'] = true;
86 $themes['enabled'][$key] = $themes['all'][$key];
89 $themes['all'][$key]['enabled'] = false;
90 $themes['disabled'][$key] = $themes['all'][$key];
92 if ( isset( $current->response[ $theme['Template'] ] ) )
93 $themes['upgrade'][$key] = $themes['all'][$key];
95 if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {
96 unset( $themes['all'][$key] );
97 unset( $themes['enabled'][$key] );
98 unset( $themes['disabled'][$key] );
102 if ( !current_user_can( 'update_themes' ) || $this->is_site_themes )
103 $themes['upgrade'] = array();
107 $themes['search'] = array_filter( $themes['all'], array( &$this, '_search_callback' ) );
111 foreach ( $themes as $type => $list )
112 $totals[ $type ] = count( $list );
114 if ( empty( $themes[ $status ] ) && !in_array( $status, array( 'all', 'search' ) ) )
117 $this->items = $themes[ $status ];
118 $total_this_page = $totals[ $status ];
121 $orderby = ucfirst( $orderby );
122 $order = strtoupper( $order );
124 uasort( $this->items, array( &$this, '_order_callback' ) );
127 $start = ( $page - 1 ) * $themes_per_page;
129 if ( $total_this_page > $themes_per_page )
130 $this->items = array_slice( $this->items, $start, $themes_per_page );
132 $this->set_pagination_args( array(
133 'total_items' => $total_this_page,
134 'per_page' => $themes_per_page,
138 function _search_callback( $theme ) {
140 if ( is_null( $term ) )
141 $term = stripslashes( $_REQUEST['s'] );
143 $search_fields = array( 'Name', 'Title', 'Description', 'Author', 'Author Name', 'Author URI', 'Template', 'Stylesheet' );
144 foreach ( $search_fields as $field )
145 if ( stripos( $theme[ $field ], $term ) !== false )
151 function _order_callback( $theme_a, $theme_b ) {
152 global $orderby, $order;
154 $a = $theme_a[$orderby];
155 $b = $theme_b[$orderby];
160 if ( 'DESC' == $order )
161 return ( $a < $b ) ? 1 : -1;
163 return ( $a < $b ) ? -1 : 1;
166 function no_items() {
169 if ( !empty( $themes['all'] ) )
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 );
214 if ( $this->is_site_themes )
215 $url = 'site-themes.php?id=' . $this->site_id;
219 if ( 'search' != $type ) {
220 $status_links[$type] = sprintf( "<a href='%s' %s>%s</a>",
221 esc_url( add_query_arg('theme_status', $type, $url) ),
222 ( $type == $status ) ? ' class="current"' : '',
223 sprintf( $text, number_format_i18n( $count ) )
228 return $status_links;
231 function get_bulk_actions() {
235 if ( 'enabled' != $status )
236 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' );
237 if ( 'disabled' != $status )
238 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' );
239 if ( ! $this->is_site_themes ) {
240 if ( current_user_can( 'delete_themes' ) )
241 $actions['delete-selected'] = __( 'Delete' );
242 if ( current_user_can( 'update_themes' ) )
243 $actions['update-selected'] = __( 'Update' );
248 function bulk_actions( $which ) {
250 parent::bulk_actions( $which );
253 function current_action() {
254 return parent::current_action();
257 function display_rows() {
258 foreach ( $this->items as $key => $theme )
259 $this->single_row( $key, $theme );
262 function single_row( $key, $theme ) {
263 global $status, $page, $s;
267 if ( $this->is_site_themes )
268 $url = "site-themes.php?id={$this->site_id}&";
270 $url = 'themes.php?';
280 $theme_key = $theme['Stylesheet'];
282 if ( empty( $theme['enabled'] ) )
283 $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>';
285 $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>';
287 if ( current_user_can('edit_themes') )
288 $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . urlencode( $theme['Name'] )) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
290 if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) )
291 $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>';
293 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context );
294 $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context );
296 $class = empty( $theme['enabled'] ) ? 'inactive' : 'active';
297 $checkbox_id = "checkbox_" . md5($theme['Name']);
298 $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $theme_key ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme['Name'] . "</label>";
300 $description = '<p>' . $theme['Description'] . '</p>';
301 $theme_name = $theme['Name'];
303 $id = sanitize_title( $theme_name );
305 echo "<tr id='$id' class='$class'>";
307 list( $columns, $hidden ) = $this->get_column_info();
309 foreach ( $columns as $column_name => $column_display_name ) {
311 if ( in_array( $column_name, $hidden ) )
312 $style = ' style="display:none;"';
314 switch ( $column_name ) {
316 echo "<th scope='row' class='check-column'>$checkbox</th>";
319 echo "<td class='theme-title'$style><strong>$theme_name</strong>";
320 echo $this->row_actions( $actions, true );
324 echo "<td class='column-description desc'$style>
325 <div class='theme-description'>$description</div>
326 <div class='$class second theme-version-author-uri'>";
328 $theme_meta = array();
330 if ( !empty( $theme['Version'] ) )
331 $theme_meta[] = sprintf( __( 'Version %s' ), $theme['Version'] );
333 if ( !empty( $theme['Author'] ) )
334 $theme_meta[] = sprintf( __( 'By %s' ), $theme['Author'] );
336 if ( !empty( $theme['Theme URI'] ) )
337 $theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
339 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status );
340 echo implode( ' | ', $theme_meta );
346 echo "<td class='$column_name column-$column_name'$style>";
347 do_action( 'manage_themes_custom_column', $column_name, $theme_key, $theme );
354 if ( $this->is_site_themes )
355 remove_action( "after_theme_row_$theme_key", 'wp_theme_update_row' );
356 do_action( 'after_theme_row', $theme_key, $theme, $status );
357 do_action( "after_theme_row_$theme_key", $theme_key, $theme, $status );