7 * @since 3.1.0 |
7 * @since 3.1.0 |
8 * @access private |
8 * @access private |
9 */ |
9 */ |
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 public $site_id; |
13 var $is_site_themes; |
13 public $is_site_themes; |
14 |
14 |
15 function __construct( $args = array() ) { |
15 private $has_items; |
|
16 |
|
17 /** |
|
18 * Constructor. |
|
19 * |
|
20 * @since 3.1.0 |
|
21 * @access public |
|
22 * |
|
23 * @see WP_List_Table::__construct() for more information on default arguments. |
|
24 * |
|
25 * @param array $args An associative array of arguments. |
|
26 */ |
|
27 public function __construct( $args = array() ) { |
16 global $status, $page; |
28 global $status, $page; |
17 |
29 |
18 parent::__construct( array( |
30 parent::__construct( array( |
19 'plural' => 'themes', |
31 'plural' => 'themes', |
20 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
32 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
30 |
42 |
31 if ( $this->is_site_themes ) |
43 if ( $this->is_site_themes ) |
32 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; |
44 $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; |
33 } |
45 } |
34 |
46 |
35 function get_table_classes() { |
47 protected function get_table_classes() { |
36 return array( 'widefat', 'plugins' ); // todo: remove and add CSS for .themes |
48 // todo: remove and add CSS for .themes |
37 } |
49 return array( 'widefat', 'plugins' ); |
38 |
50 } |
39 function ajax_user_can() { |
51 |
|
52 public function ajax_user_can() { |
40 if ( $this->is_site_themes ) |
53 if ( $this->is_site_themes ) |
41 return current_user_can( 'manage_sites' ); |
54 return current_user_can( 'manage_sites' ); |
42 else |
55 else |
43 return current_user_can( 'manage_network_themes' ); |
56 return current_user_can( 'manage_network_themes' ); |
44 } |
57 } |
45 |
58 |
46 function prepare_items() { |
59 public function prepare_items() { |
47 global $status, $totals, $page, $orderby, $order, $s; |
60 global $status, $totals, $page, $orderby, $order, $s; |
48 |
61 |
49 wp_reset_vars( array( 'orderby', 'order', 's' ) ); |
62 wp_reset_vars( array( 'orderby', 'order', 's' ) ); |
50 |
63 |
51 $themes = array( |
64 $themes = array( |
|
65 /** |
|
66 * Filter the full array of WP_Theme objects to list in the Multisite |
|
67 * themes list table. |
|
68 * |
|
69 * @since 3.1.0 |
|
70 * |
|
71 * @param array $all An array of WP_Theme objects to display in the list table. |
|
72 */ |
52 'all' => apply_filters( 'all_themes', wp_get_themes() ), |
73 'all' => apply_filters( 'all_themes', wp_get_themes() ), |
53 'search' => array(), |
74 'search' => array(), |
54 'enabled' => array(), |
75 'enabled' => array(), |
55 'disabled' => array(), |
76 'disabled' => array(), |
56 'upgrade' => array(), |
77 'upgrade' => array(), |
121 'total_items' => $total_this_page, |
142 'total_items' => $total_this_page, |
122 'per_page' => $themes_per_page, |
143 'per_page' => $themes_per_page, |
123 ) ); |
144 ) ); |
124 } |
145 } |
125 |
146 |
126 function _search_callback( $theme ) { |
147 /** |
|
148 * @staticvar string $term |
|
149 * @param WP_Theme $theme |
|
150 * @return bool |
|
151 */ |
|
152 public function _search_callback( $theme ) { |
127 static $term; |
153 static $term; |
128 if ( is_null( $term ) ) |
154 if ( is_null( $term ) ) |
129 $term = wp_unslash( $_REQUEST['s'] ); |
155 $term = wp_unslash( $_REQUEST['s'] ); |
130 |
156 |
131 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) { |
157 foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) { |
142 |
168 |
143 return false; |
169 return false; |
144 } |
170 } |
145 |
171 |
146 // Not used by any core columns. |
172 // Not used by any core columns. |
147 function _order_callback( $theme_a, $theme_b ) { |
173 /** |
|
174 * @global string $orderby |
|
175 * @global string $order |
|
176 * @param array $theme_a |
|
177 * @param array $theme_b |
|
178 * @return int |
|
179 */ |
|
180 public function _order_callback( $theme_a, $theme_b ) { |
148 global $orderby, $order; |
181 global $orderby, $order; |
149 |
182 |
150 $a = $theme_a[ $orderby ]; |
183 $a = $theme_a[ $orderby ]; |
151 $b = $theme_b[ $orderby ]; |
184 $b = $theme_b[ $orderby ]; |
152 |
185 |
157 return ( $a < $b ) ? 1 : -1; |
190 return ( $a < $b ) ? 1 : -1; |
158 else |
191 else |
159 return ( $a < $b ) ? -1 : 1; |
192 return ( $a < $b ) ? -1 : 1; |
160 } |
193 } |
161 |
194 |
162 function no_items() { |
195 public function no_items() { |
163 if ( ! $this->has_items ) |
196 if ( ! $this->has_items ) |
164 _e( 'No themes found.' ); |
197 _e( 'No themes found.' ); |
165 else |
198 else |
166 _e( 'You do not appear to have any themes available at this time.' ); |
199 _e( 'You do not appear to have any themes available at this time.' ); |
167 } |
200 } |
168 |
201 |
169 function get_columns() { |
202 public function get_columns() { |
170 global $status; |
203 global $status; |
171 |
204 |
172 return array( |
205 return array( |
173 'cb' => '<input type="checkbox" />', |
206 'cb' => '<input type="checkbox" />', |
174 'name' => __( 'Theme' ), |
207 'name' => __( 'Theme' ), |
175 'description' => __( 'Description' ), |
208 'description' => __( 'Description' ), |
176 ); |
209 ); |
177 } |
210 } |
178 |
211 |
179 function get_sortable_columns() { |
212 protected function get_sortable_columns() { |
180 return array( |
213 return array( |
181 'name' => 'name', |
214 'name' => 'name', |
182 ); |
215 ); |
183 } |
216 } |
184 |
217 |
185 function get_views() { |
218 protected function get_views() { |
186 global $totals, $status; |
219 global $totals, $status; |
187 |
220 |
188 $status_links = array(); |
221 $status_links = array(); |
189 foreach ( $totals as $type => $count ) { |
222 foreach ( $totals as $type => $count ) { |
190 if ( !$count ) |
223 if ( !$count ) |
240 $actions['delete-selected'] = __( 'Delete' ); |
273 $actions['delete-selected'] = __( 'Delete' ); |
241 } |
274 } |
242 return $actions; |
275 return $actions; |
243 } |
276 } |
244 |
277 |
245 function display_rows() { |
278 public function display_rows() { |
246 foreach ( $this->items as $theme ) |
279 foreach ( $this->items as $theme ) |
247 $this->single_row( $theme ); |
280 $this->single_row( $theme ); |
248 } |
281 } |
249 |
282 |
250 function single_row( $theme ) { |
283 /** |
|
284 * @global string $status |
|
285 * @global int $page |
|
286 * @global string $s |
|
287 * @global array $totals |
|
288 * @param WP_Theme $theme |
|
289 */ |
|
290 public function single_row( $theme ) { |
251 global $status, $page, $s, $totals; |
291 global $status, $page, $s, $totals; |
252 |
292 |
253 $context = $status; |
293 $context = $status; |
254 |
294 |
255 if ( $this->is_site_themes ) { |
295 if ( $this->is_site_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>'; |
322 $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>'; |
283 |
323 |
284 if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $stylesheet != get_option( 'stylesheet' ) && $stylesheet != get_option( 'template' ) ) |
324 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>'; |
325 $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>'; |
286 |
326 |
|
327 /** |
|
328 * Filter the action links displayed for each theme in the Multisite |
|
329 * themes list table. |
|
330 * |
|
331 * The action links displayed are determined by the theme's status, and |
|
332 * which Multisite themes list table is being displayed - the Network |
|
333 * themes list table (themes.php), which displays all installed themes, |
|
334 * or the Site themes list table (site-themes.php), which displays the |
|
335 * non-network enabled themes when editing a site in the Network admin. |
|
336 * |
|
337 * The default action links for the Network themes list table include |
|
338 * 'Network Enable', 'Network Disable', 'Edit', and 'Delete'. |
|
339 * |
|
340 * The default action links for the Site themes list table include |
|
341 * 'Enable', 'Disable', and 'Edit'. |
|
342 * |
|
343 * @since 2.8.0 |
|
344 * |
|
345 * @param array $actions An array of action links. |
|
346 * @param WP_Theme $theme The current WP_Theme object. |
|
347 * @param string $context Status of the theme. |
|
348 */ |
287 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context ); |
349 $actions = apply_filters( 'theme_action_links', array_filter( $actions ), $theme, $context ); |
|
350 |
|
351 /** |
|
352 * Filter the action links of a specific theme in the Multisite themes |
|
353 * list table. |
|
354 * |
|
355 * The dynamic portion of the hook name, `$stylesheet`, refers to the |
|
356 * directory name of the theme, which in most cases is synonymous |
|
357 * with the template name. |
|
358 * |
|
359 * @since 3.1.0 |
|
360 * |
|
361 * @param array $actions An array of action links. |
|
362 * @param WP_Theme $theme The current WP_Theme object. |
|
363 * @param string $context Status of the theme. |
|
364 */ |
288 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context ); |
365 $actions = apply_filters( "theme_action_links_$stylesheet", $actions, $theme, $context ); |
289 |
366 |
290 $class = ! $allowed ? 'inactive' : 'active'; |
367 $class = ! $allowed ? 'inactive' : 'active'; |
291 $checkbox_id = "checkbox_" . md5( $theme->get('Name') ); |
368 $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>"; |
369 $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>"; |
315 echo "</td>"; |
392 echo "</td>"; |
316 break; |
393 break; |
317 case 'description': |
394 case 'description': |
318 echo "<td class='column-description desc'$style>"; |
395 echo "<td class='column-description desc'$style>"; |
319 if ( $theme->errors() ) { |
396 if ( $theme->errors() ) { |
320 $pre = $status == 'broken' ? '' : __( 'Broken Theme:' ) . ' '; |
397 $pre = $status == 'broken' ? __( 'Broken Theme:' ) . ' ' : ''; |
321 echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>'; |
398 echo '<p><strong class="attention">' . $pre . $theme->errors()->get_error_message() . '</strong></p>'; |
322 } |
399 } |
323 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div> |
400 echo "<div class='theme-description'><p>" . $theme->display( 'Description' ) . "</p></div> |
324 <div class='$class second theme-version-author-uri'>"; |
401 <div class='$class second theme-version-author-uri'>"; |
325 |
402 |
331 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); |
408 $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') ); |
332 |
409 |
333 if ( $theme->get('ThemeURI') ) |
410 if ( $theme->get('ThemeURI') ) |
334 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; |
411 $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>'; |
335 |
412 |
|
413 /** |
|
414 * Filter the array of row meta for each theme in the Multisite themes |
|
415 * list table. |
|
416 * |
|
417 * @since 3.1.0 |
|
418 * |
|
419 * @param array $theme_meta An array of the theme's metadata, |
|
420 * including the version, author, and |
|
421 * theme URI. |
|
422 * @param string $stylesheet Directory name of the theme. |
|
423 * @param WP_Theme $theme WP_Theme object. |
|
424 * @param string $status Status of the theme. |
|
425 */ |
336 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); |
426 $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $stylesheet, $theme, $status ); |
337 echo implode( ' | ', $theme_meta ); |
427 echo implode( ' | ', $theme_meta ); |
338 |
428 |
339 echo "</div></td>"; |
429 echo "</div></td>"; |
340 break; |
430 break; |
341 |
431 |
342 default: |
432 default: |
343 echo "<td class='$column_name column-$column_name'$style>"; |
433 echo "<td class='$column_name column-$column_name'$style>"; |
|
434 |
|
435 /** |
|
436 * Fires inside each custom column of the Multisite themes list table. |
|
437 * |
|
438 * @since 3.1.0 |
|
439 * |
|
440 * @param string $column_name Name of the column. |
|
441 * @param string $stylesheet Directory name of the theme. |
|
442 * @param WP_Theme $theme Current WP_Theme object. |
|
443 */ |
344 do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); |
444 do_action( 'manage_themes_custom_column', $column_name, $stylesheet, $theme ); |
345 echo "</td>"; |
445 echo "</td>"; |
346 } |
446 } |
347 } |
447 } |
348 |
448 |
349 echo "</tr>"; |
449 echo "</tr>"; |
350 |
450 |
351 if ( $this->is_site_themes ) |
451 if ( $this->is_site_themes ) |
352 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' ); |
452 remove_action( "after_theme_row_$stylesheet", 'wp_theme_update_row' ); |
|
453 |
|
454 /** |
|
455 * Fires after each row in the Multisite themes list table. |
|
456 * |
|
457 * @since 3.1.0 |
|
458 * |
|
459 * @param string $stylesheet Directory name of the theme. |
|
460 * @param WP_Theme $theme Current WP_Theme object. |
|
461 * @param string $status Status of the theme. |
|
462 */ |
353 do_action( 'after_theme_row', $stylesheet, $theme, $status ); |
463 do_action( 'after_theme_row', $stylesheet, $theme, $status ); |
|
464 |
|
465 /** |
|
466 * Fires after each specific row in the Multisite themes list table. |
|
467 * |
|
468 * The dynamic portion of the hook name, `$stylesheet`, refers to the |
|
469 * directory name of the theme, most often synonymous with the template |
|
470 * name of the theme. |
|
471 * |
|
472 * @since 3.5.0 |
|
473 * |
|
474 * @param string $stylesheet Directory name of the theme. |
|
475 * @param WP_Theme $theme Current WP_Theme object. |
|
476 * @param string $status Status of the theme. |
|
477 */ |
354 do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status ); |
478 do_action( "after_theme_row_$stylesheet", $stylesheet, $theme, $status ); |
355 } |
479 } |
356 } |
480 } |