1 <?php |
1 <?php |
2 /** |
2 /** |
3 * Theme Installer List Table class. |
3 * List Table API: WP_Theme_Install_List_Table class |
4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage List_Table |
6 * @subpackage Administration |
|
7 * @since 3.1.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Core class used to implement displaying themes to install in a list table. |
|
12 * |
7 * @since 3.1.0 |
13 * @since 3.1.0 |
8 * @access private |
14 * @access private |
|
15 * |
|
16 * @see WP_Themes_List_Table |
9 */ |
17 */ |
10 class WP_Theme_Install_List_Table extends WP_Themes_List_Table { |
18 class WP_Theme_Install_List_Table extends WP_Themes_List_Table { |
11 |
19 |
12 public $features = array(); |
20 public $features = array(); |
13 |
21 |
|
22 /** |
|
23 * |
|
24 * @return bool |
|
25 */ |
14 public function ajax_user_can() { |
26 public function ajax_user_can() { |
15 return current_user_can( 'install_themes' ); |
27 return current_user_can( 'install_themes' ); |
16 } |
28 } |
17 |
29 |
|
30 /** |
|
31 * |
|
32 * @global array $tabs |
|
33 * @global string $tab |
|
34 * @global int $paged |
|
35 * @global string $type |
|
36 * @global array $theme_field_defaults |
|
37 */ |
18 public function prepare_items() { |
38 public function prepare_items() { |
19 include( ABSPATH . 'wp-admin/includes/theme-install.php' ); |
39 include( ABSPATH . 'wp-admin/includes/theme-install.php' ); |
20 |
40 |
21 global $tabs, $tab, $paged, $type, $theme_field_defaults; |
41 global $tabs, $tab, $paged, $type, $theme_field_defaults; |
22 wp_reset_vars( array( 'tab' ) ); |
42 wp_reset_vars( array( 'tab' ) ); |
36 $per_page = 36; |
56 $per_page = 36; |
37 |
57 |
38 // These are the tabs which are shown on the page, |
58 // These are the tabs which are shown on the page, |
39 $tabs = array(); |
59 $tabs = array(); |
40 $tabs['dashboard'] = __( 'Search' ); |
60 $tabs['dashboard'] = __( 'Search' ); |
41 if ( 'search' == $tab ) |
61 if ( 'search' === $tab ) |
42 $tabs['search'] = __( 'Search Results' ); |
62 $tabs['search'] = __( 'Search Results' ); |
43 $tabs['upload'] = __( 'Upload' ); |
63 $tabs['upload'] = __( 'Upload' ); |
44 $tabs['featured'] = _x( 'Featured', 'themes' ); |
64 $tabs['featured'] = _x( 'Featured', 'themes' ); |
45 //$tabs['popular'] = _x( 'Popular', 'themes' ); |
65 //$tabs['popular'] = _x( 'Popular', 'themes' ); |
46 $tabs['new'] = _x( 'Latest', 'themes' ); |
66 $tabs['new'] = _x( 'Latest', 'themes' ); |
50 |
70 |
51 /** This filter is documented in wp-admin/theme-install.php */ |
71 /** This filter is documented in wp-admin/theme-install.php */ |
52 $tabs = apply_filters( 'install_themes_tabs', $tabs ); |
72 $tabs = apply_filters( 'install_themes_tabs', $tabs ); |
53 |
73 |
54 /** |
74 /** |
55 * Filter tabs not associated with a menu item on the Install Themes screen. |
75 * Filters tabs not associated with a menu item on the Install Themes screen. |
56 * |
76 * |
57 * @since 2.8.0 |
77 * @since 2.8.0 |
58 * |
78 * |
59 * @param array $nonmenu_tabs The tabs that don't have a menu item on |
79 * @param array $nonmenu_tabs The tabs that don't have a menu item on |
60 * the Install Themes screen. |
80 * the Install Themes screen. |
102 $args = false; |
122 $args = false; |
103 break; |
123 break; |
104 } |
124 } |
105 |
125 |
106 /** |
126 /** |
107 * Filter API request arguments for each Install Themes screen tab. |
127 * Filters API request arguments for each Install Themes screen tab. |
108 * |
128 * |
109 * The dynamic portion of the hook name, `$tab`, refers to the theme install |
129 * The dynamic portion of the hook name, `$tab`, refers to the theme install |
110 * tabs. Default tabs are 'dashboard', 'search', 'upload', 'featured', |
130 * tabs. Default tabs are 'dashboard', 'search', 'upload', 'featured', |
111 * 'new', and 'updated'. |
131 * 'new', and 'updated'. |
112 * |
132 * |
113 * @since 3.7.0 |
133 * @since 3.7.0 |
114 * |
134 * |
115 * @param array $args An array of themes API arguments. |
135 * @param array $args An array of themes API arguments. |
116 */ |
136 */ |
117 $args = apply_filters( 'install_themes_table_api_args_' . $tab, $args ); |
137 $args = apply_filters( "install_themes_table_api_args_{$tab}", $args ); |
118 |
138 |
119 if ( ! $args ) |
139 if ( ! $args ) |
120 return; |
140 return; |
121 |
141 |
122 $api = themes_api( 'query_themes', $args ); |
142 $api = themes_api( 'query_themes', $args ); |
131 'per_page' => $args['per_page'], |
151 'per_page' => $args['per_page'], |
132 'infinite_scroll' => true, |
152 'infinite_scroll' => true, |
133 ) ); |
153 ) ); |
134 } |
154 } |
135 |
155 |
|
156 /** |
|
157 */ |
136 public function no_items() { |
158 public function no_items() { |
137 _e( 'No themes match your request.' ); |
159 _e( 'No themes match your request.' ); |
138 } |
160 } |
139 |
161 |
|
162 /** |
|
163 * |
|
164 * @global array $tabs |
|
165 * @global string $tab |
|
166 * @return array |
|
167 */ |
140 protected function get_views() { |
168 protected function get_views() { |
141 global $tabs, $tab; |
169 global $tabs, $tab; |
142 |
170 |
143 $display_tabs = array(); |
171 $display_tabs = array(); |
144 foreach ( (array) $tabs as $action => $text ) { |
172 foreach ( (array) $tabs as $action => $text ) { |
145 $class = ( $action == $tab ) ? ' class="current"' : ''; |
173 $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; |
146 $href = self_admin_url('theme-install.php?tab=' . $action); |
174 $href = self_admin_url('theme-install.php?tab=' . $action); |
147 $display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>"; |
175 $display_tabs['theme-install-'.$action] = "<a href='$href'$current_link_attributes>$text</a>"; |
148 } |
176 } |
149 |
177 |
150 return $display_tabs; |
178 return $display_tabs; |
151 } |
179 } |
152 |
180 |
|
181 /** |
|
182 */ |
153 public function display() { |
183 public function display() { |
154 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); |
184 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); |
155 ?> |
185 ?> |
156 <div class="tablenav top themes"> |
186 <div class="tablenav top themes"> |
157 <div class="alignleft actions"> |
187 <div class="alignleft actions"> |
174 |
204 |
175 <?php |
205 <?php |
176 $this->tablenav( 'bottom' ); |
206 $this->tablenav( 'bottom' ); |
177 } |
207 } |
178 |
208 |
|
209 /** |
|
210 */ |
179 public function display_rows() { |
211 public function display_rows() { |
180 $themes = $this->items; |
212 $themes = $this->items; |
181 foreach ( $themes as $theme ) { |
213 foreach ( $themes as $theme ) { |
182 ?> |
214 ?> |
183 <div class="available-theme installable-theme"><?php |
215 <div class="available-theme installable-theme"><?php |
189 } |
221 } |
190 |
222 |
191 /** |
223 /** |
192 * Prints a theme from the WordPress.org API. |
224 * Prints a theme from the WordPress.org API. |
193 * |
225 * |
194 * @param object $theme An object that contains theme data returned by the WordPress.org API. |
226 * @since 3.1.0 |
195 * |
227 * |
196 * Example theme data: |
228 * @global array $themes_allowedtags |
197 * object(stdClass)[59] |
229 * |
198 * public 'name' => string 'Magazine Basic' |
230 * @param object $theme { |
199 * public 'slug' => string 'magazine-basic' |
231 * An object that contains theme data returned by the WordPress.org API. |
200 * public 'version' => string '1.1' |
232 * |
201 * public 'author' => string 'tinkerpriest' |
233 * @type string $name Theme name, e.g. 'Twenty Seventeen'. |
202 * public 'preview_url' => string 'http://wp-themes.com/?magazine-basic' |
234 * @type string $slug Theme slug, e.g. 'twentyseventeen'. |
203 * public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png' |
235 * @type string $version Theme version, e.g. '1.1'. |
204 * public 'rating' => float 80 |
236 * @type string $author Theme author username, e.g. 'melchoyce'. |
205 * public 'num_ratings' => int 1 |
237 * @type string $preview_url Preview URL, e.g. 'http://2017.wordpress.net/'. |
206 * public 'homepage' => string 'http://wordpress.org/themes/magazine-basic' |
238 * @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentyseventeen/'. |
207 * public 'description' => string 'A basic magazine style layout with a fully customizable layout through a backend interface. Designed by <a href="http://bavotasan.com">c.bavota</a> of <a href="http://tinkerpriestmedia.com">Tinker Priest Media</a>.' |
239 * @type float $rating Rating score. |
208 * public 'download_link' => string 'http://wordpress.org/themes/download/magazine-basic.1.1.zip' |
240 * @type int $num_ratings The number of ratings. |
|
241 * @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentyseventeen/'. |
|
242 * @type string $description Theme description. |
|
243 * @type string $download_link Theme ZIP download URL. |
|
244 * } |
209 */ |
245 */ |
210 public function single_row( $theme ) { |
246 public function single_row( $theme ) { |
211 global $themes_allowedtags; |
247 global $themes_allowedtags; |
212 |
248 |
213 if ( empty( $theme ) ) |
249 if ( empty( $theme ) ) |
251 } |
287 } |
252 |
288 |
253 $actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>'; |
289 $actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>'; |
254 |
290 |
255 /** |
291 /** |
256 * Filter the install action links for a theme in the Install Themes list table. |
292 * Filters the install action links for a theme in the Install Themes list table. |
257 * |
293 * |
258 * @since 3.4.0 |
294 * @since 3.4.0 |
259 * |
295 * |
260 * @param array $actions An array of theme action hyperlinks. Defaults are |
296 * @param array $actions An array of theme action hyperlinks. Defaults are |
261 * links to Install Now, Preview, and Details. |
297 * links to Install Now, Preview, and Details. |
263 */ |
299 */ |
264 $actions = apply_filters( 'theme_install_actions', $actions, $theme ); |
300 $actions = apply_filters( 'theme_install_actions', $actions, $theme ); |
265 |
301 |
266 ?> |
302 ?> |
267 <a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>"> |
303 <a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>"> |
268 <img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" /> |
304 <img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" /> |
269 </a> |
305 </a> |
270 |
306 |
271 <h3><?php echo $name; ?></h3> |
307 <h3><?php echo $name; ?></h3> |
272 <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div> |
308 <div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div> |
273 |
309 |
290 public function theme_installer() { |
326 public function theme_installer() { |
291 ?> |
327 ?> |
292 <div id="theme-installer" class="wp-full-overlay expanded"> |
328 <div id="theme-installer" class="wp-full-overlay expanded"> |
293 <div class="wp-full-overlay-sidebar"> |
329 <div class="wp-full-overlay-sidebar"> |
294 <div class="wp-full-overlay-header"> |
330 <div class="wp-full-overlay-header"> |
295 <a href="#" class="close-full-overlay button-secondary"><?php _e( 'Close' ); ?></a> |
331 <a href="#" class="close-full-overlay button"><?php _e( 'Close' ); ?></a> |
296 <span class="theme-install"></span> |
332 <span class="theme-install"></span> |
297 </div> |
333 </div> |
298 <div class="wp-full-overlay-sidebar-content"> |
334 <div class="wp-full-overlay-sidebar-content"> |
299 <div class="install-theme-info"></div> |
335 <div class="install-theme-info"></div> |
300 </div> |
336 </div> |
301 <div class="wp-full-overlay-footer"> |
337 <div class="wp-full-overlay-footer"> |
302 <a href="#" class="collapse-sidebar" title="<?php esc_attr_e('Collapse Sidebar'); ?>"> |
338 <button type="button" class="collapse-sidebar button" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>"> |
303 <span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span> |
|
304 <span class="collapse-sidebar-arrow"></span> |
339 <span class="collapse-sidebar-arrow"></span> |
305 </a> |
340 <span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span> |
|
341 </button> |
306 </div> |
342 </div> |
307 </div> |
343 </div> |
308 <div class="wp-full-overlay-main"></div> |
344 <div class="wp-full-overlay-main"></div> |
309 </div> |
345 </div> |
310 <?php |
346 <?php |
330 } |
366 } |
331 |
367 |
332 /** |
368 /** |
333 * Prints the info for a theme (to be used in the theme installer modal). |
369 * Prints the info for a theme (to be used in the theme installer modal). |
334 * |
370 * |
|
371 * @global array $themes_allowedtags |
|
372 * |
335 * @param object $theme - A WordPress.org Theme API object. |
373 * @param object $theme - A WordPress.org Theme API object. |
336 */ |
374 */ |
337 public function install_theme_info( $theme ) { |
375 public function install_theme_info( $theme ) { |
338 global $themes_allowedtags; |
376 global $themes_allowedtags; |
339 |
377 |
357 |
395 |
358 ?> |
396 ?> |
359 <div class="install-theme-info"><?php |
397 <div class="install-theme-info"><?php |
360 switch ( $status ) { |
398 switch ( $status ) { |
361 case 'update_available': |
399 case 'update_available': |
362 echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>'; |
400 echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>'; |
363 break; |
401 break; |
364 case 'newer_installed': |
402 case 'newer_installed': |
365 case 'latest_installed': |
403 case 'latest_installed': |
366 echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; |
404 echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; |
367 break; |
405 break; |
368 case 'install': |
406 case 'install': |
369 default: |
407 default: |
370 echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>'; |
408 echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>'; |
371 break; |
409 break; |
372 } ?> |
410 } ?> |
373 <h3 class="theme-name"><?php echo $name; ?></h3> |
411 <h3 class="theme-name"><?php echo $name; ?></h3> |
374 <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span> |
412 <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span> |
375 <?php if ( isset( $theme->screenshot_url ) ): ?> |
413 <?php if ( isset( $theme->screenshot_url ) ): ?> |
376 <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" /> |
414 <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" /> |
377 <?php endif; ?> |
415 <?php endif; ?> |
378 <div class="theme-details"> |
416 <div class="theme-details"> |
379 <?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?> |
417 <?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?> |
380 <div class="theme-version"> |
418 <div class="theme-version"> |
381 <strong><?php _e('Version:') ?> </strong> |
419 <strong><?php _e('Version:') ?> </strong> |
392 |
430 |
393 /** |
431 /** |
394 * Send required variables to JavaScript land |
432 * Send required variables to JavaScript land |
395 * |
433 * |
396 * @since 3.4.0 |
434 * @since 3.4.0 |
397 * @access public |
435 * |
398 * |
436 * @global string $tab Current tab within Themes->Install screen |
399 * @uses $tab Global; current tab within Themes->Install screen |
437 * @global string $type Type of search. |
400 * @uses $type Global; type of search. |
438 * |
|
439 * @param array $extra_args Unused. |
401 */ |
440 */ |
402 public function _js_vars( $extra_args = array() ) { |
441 public function _js_vars( $extra_args = array() ) { |
403 global $tab, $type; |
442 global $tab, $type; |
404 parent::_js_vars( compact( 'tab', 'type' ) ); |
443 parent::_js_vars( compact( 'tab', 'type' ) ); |
405 } |
444 } |
406 |
445 |
407 /** |
446 /** |
408 * Check to see if the theme is already installed. |
447 * Check to see if the theme is already installed. |
409 * |
448 * |
410 * @since 3.4.0 |
449 * @since 3.4.0 |
411 * @access private |
|
412 * |
450 * |
413 * @param object $theme - A WordPress.org Theme API object. |
451 * @param object $theme - A WordPress.org Theme API object. |
414 * @return string Theme status. |
452 * @return string Theme status. |
415 */ |
453 */ |
416 private function _get_theme_status( $theme ) { |
454 private function _get_theme_status( $theme ) { |