10 class WP_MS_Themes_List_Table extends WP_List_Table { |
10 class WP_MS_Themes_List_Table extends WP_List_Table { |
11 |
11 |
12 var $site_id; |
12 var $site_id; |
13 var $is_site_themes; |
13 var $is_site_themes; |
14 |
14 |
15 function __construct() { |
15 function __construct( $args = array() ) { |
16 global $status, $page; |
16 global $status, $page; |
|
17 |
|
18 parent::__construct( array( |
|
19 'plural' => 'themes', |
|
20 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
|
21 ) ); |
17 |
22 |
18 $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all'; |
23 $status = isset( $_REQUEST['theme_status'] ) ? $_REQUEST['theme_status'] : 'all'; |
19 if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) ) |
24 if ( !in_array( $status, array( 'all', 'enabled', 'disabled', 'upgrade', 'search', 'broken' ) ) ) |
20 $status = 'all'; |
25 $status = 'all'; |
21 |
26 |
22 $page = $this->get_pagenum(); |
27 $page = $this->get_pagenum(); |
23 |
28 |
24 $screen = get_current_screen(); |
29 $this->is_site_themes = ( 'site-themes-network' == $this->screen->id ) ? true : false; |
25 $this->is_site_themes = ( 'site-themes-network' == $screen->id ) ? true : false; |
|
26 |
30 |
27 if ( $this->is_site_themes ) |
31 if ( $this->is_site_themes ) |
28 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; |
32 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; |
29 |
|
30 parent::__construct( array( |
|
31 'plural' => 'themes' |
|
32 ) ); |
|
33 } |
33 } |
34 |
34 |
35 function get_table_classes() { |
35 function get_table_classes() { |
36 return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes |
36 return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes |
37 } |
37 } |
38 |
38 |
39 function ajax_user_can() { |
39 function ajax_user_can() { |
40 $menu_perms = get_site_option( 'menu_items', array() ); |
40 if ( $this->is_site_themes ) |
41 |
41 return current_user_can( 'manage_sites' ); |
42 if ( empty( $menu_perms['themes'] ) && ! is_super_admin() ) |
42 else |
43 return false; |
43 return current_user_can( 'manage_network_themes' ); |
44 |
|
45 if ( $this->is_site_themes && !current_user_can('manage_sites') ) |
|
46 return false; |
|
47 elseif ( !$this->is_site_themes && !current_user_can('manage_network_themes') ) |
|
48 return false; |
|
49 return true; |
|
50 } |
44 } |
51 |
45 |
52 function prepare_items() { |
46 function prepare_items() { |
53 global $status, $totals, $page, $orderby, $order, $s; |
47 global $status, $totals, $page, $orderby, $order, $s; |
54 |
48 |
238 if ( 'enabled' != $status ) |
232 if ( 'enabled' != $status ) |
239 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ); |
233 $actions['enable-selected'] = $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ); |
240 if ( 'disabled' != $status ) |
234 if ( 'disabled' != $status ) |
241 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ); |
235 $actions['disable-selected'] = $this->is_site_themes ? __( 'Disable' ) : __( 'Network Disable' ); |
242 if ( ! $this->is_site_themes ) { |
236 if ( ! $this->is_site_themes ) { |
|
237 if ( current_user_can( 'update_themes' ) ) |
|
238 $actions['update-selected'] = __( 'Update' ); |
243 if ( current_user_can( 'delete_themes' ) ) |
239 if ( current_user_can( 'delete_themes' ) ) |
244 $actions['delete-selected'] = __( 'Delete' ); |
240 $actions['delete-selected'] = __( 'Delete' ); |
245 if ( current_user_can( 'update_themes' ) ) |
|
246 $actions['update-selected'] = __( 'Update' ); |
|
247 } |
241 } |
248 return $actions; |
242 return $actions; |
249 } |
|
250 |
|
251 function bulk_actions( $which ) { |
|
252 global $status; |
|
253 parent::bulk_actions( $which ); |
|
254 } |
|
255 |
|
256 function current_action() { |
|
257 return parent::current_action(); |
|
258 } |
243 } |
259 |
244 |
260 function display_rows() { |
245 function display_rows() { |
261 foreach ( $this->items as $key => $theme ) |
246 foreach ( $this->items as $key => $theme ) |
262 $this->single_row( $key, $theme ); |
247 $this->single_row( $key, $theme ); |
281 'disable' => '', |
266 'disable' => '', |
282 'edit' => '', |
267 'edit' => '', |
283 'delete' => '' |
268 'delete' => '' |
284 ); |
269 ); |
285 |
270 |
286 $theme_key = $theme->get_stylesheet(); |
271 $stylesheet = $theme->get_stylesheet(); |
|
272 $theme_key = urlencode( $stylesheet ); |
287 |
273 |
288 if ( ! $allowed ) { |
274 if ( ! $allowed ) { |
289 if ( ! $theme->errors() ) |
275 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>'; |
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>'; |
291 } else { |
277 } else { |
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>'; |
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>'; |
293 } |
279 } |
294 |
280 |
295 if ( current_user_can('edit_themes') ) |
281 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>'; |
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>'; |
297 |
283 |
298 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) ) |
284 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != 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>'; |
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>'; |
300 |
286 |
301 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme_key, $theme, $context ); |
287 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $stylesheet, $theme, $context ); |
302 $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context ); |
288 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $stylesheet, $theme, $context ); |
303 |
289 |
304 $class = ! $allowed ? 'inactive' : 'active'; |
290 $class = ! $allowed ? 'inactive' : 'active'; |
305 $checkbox_id = "checkbox_" . md5( $theme->get('Name') ); |
291 $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>"; |
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>"; |
307 |
293 |
308 $id = sanitize_html_class( $theme->get_stylesheet() ); |
294 $id = sanitize_html_class( $theme->get_stylesheet() ); |
309 |
295 |
310 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) |
296 if ( ! empty( $totals['upgrade'] ) && ! empty( $theme->update ) ) |
311 $class .= ' update'; |
297 $class .= ' update'; |
345 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); |
331 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); |
346 |
332 |
347 if ( $theme->get('ThemeURI') ) |
333 if ( $theme->get('ThemeURI') ) |
348 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; |
334 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; |
349 |
335 |
350 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status ); |
336 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); |
351 echo implode( ' | ', $theme_meta ); |
337 echo implode( ' | ', $theme_meta ); |
352 |
338 |
353 echo "</div></td>"; |
339 echo "</div></td>"; |
354 break; |
340 break; |
355 |
341 |
356 default: |
342 default: |
357 echo "<td class='$column_name column-$column_name'$style>"; |
343 echo "<td class='$column_name column-$column_name'$style>"; |
358 do_action( 'manage_themes_custom_column', $column_name, $theme_key, $theme ); |
344 do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); |
359 echo "</td>"; |
345 echo "</td>"; |
360 } |
346 } |
361 } |
347 } |
362 |
348 |
363 echo "</tr>"; |
349 echo "</tr>"; |
364 |
350 |
365 if ( $this->is_site_themes ) |
351 if ( $this->is_site_themes ) |
366 remove_action( "after_theme_row_$theme_key", 'wp_theme_update_row' ); |
352 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' ); |
367 do_action( 'after_theme_row', $theme_key, $theme, $status ); |
353 do_action( 'after_theme_row', $stylesheet, $theme, $status ); |
368 do_action( "after_theme_row_$theme_key", $theme_key, $theme, $status ); |
354 do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status ); |
369 } |
355 } |
370 } |
356 } |