39 include( ABSPATH . 'wp-admin/includes/theme-install.php' ); |
37 include( ABSPATH . 'wp-admin/includes/theme-install.php' ); |
40 |
38 |
41 global $tabs, $tab, $paged, $type, $theme_field_defaults; |
39 global $tabs, $tab, $paged, $type, $theme_field_defaults; |
42 wp_reset_vars( array( 'tab' ) ); |
40 wp_reset_vars( array( 'tab' ) ); |
43 |
41 |
44 $search_terms = array(); |
42 $search_terms = array(); |
45 $search_string = ''; |
43 $search_string = ''; |
46 if ( ! empty( $_REQUEST['s'] ) ){ |
44 if ( ! empty( $_REQUEST['s'] ) ) { |
47 $search_string = strtolower( wp_unslash( $_REQUEST['s'] ) ); |
45 $search_string = strtolower( wp_unslash( $_REQUEST['s'] ) ); |
48 $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); |
46 $search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); |
49 } |
47 } |
50 |
48 |
51 if ( ! empty( $_REQUEST['features'] ) ) |
49 if ( ! empty( $_REQUEST['features'] ) ) { |
52 $this->features = $_REQUEST['features']; |
50 $this->features = $_REQUEST['features']; |
|
51 } |
53 |
52 |
54 $paged = $this->get_pagenum(); |
53 $paged = $this->get_pagenum(); |
55 |
54 |
56 $per_page = 36; |
55 $per_page = 36; |
57 |
56 |
58 // These are the tabs which are shown on the page, |
57 // These are the tabs which are shown on the page, |
59 $tabs = array(); |
58 $tabs = array(); |
60 $tabs['dashboard'] = __( 'Search' ); |
59 $tabs['dashboard'] = __( 'Search' ); |
61 if ( 'search' === $tab ) |
60 if ( 'search' === $tab ) { |
62 $tabs['search'] = __( 'Search Results' ); |
61 $tabs['search'] = __( 'Search Results' ); |
63 $tabs['upload'] = __( 'Upload' ); |
62 } |
|
63 $tabs['upload'] = __( 'Upload' ); |
64 $tabs['featured'] = _x( 'Featured', 'themes' ); |
64 $tabs['featured'] = _x( 'Featured', 'themes' ); |
65 //$tabs['popular'] = _x( 'Popular', 'themes' ); |
65 //$tabs['popular'] = _x( 'Popular', 'themes' ); |
66 $tabs['new'] = _x( 'Latest', 'themes' ); |
66 $tabs['new'] = _x( 'Latest', 'themes' ); |
67 $tabs['updated'] = _x( 'Recently Updated', 'themes' ); |
67 $tabs['updated'] = _x( 'Recently Updated', 'themes' ); |
68 |
68 |
69 $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item. |
69 $nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item. |
70 |
70 |
71 /** This filter is documented in wp-admin/theme-install.php */ |
71 /** This filter is documented in wp-admin/theme-install.php */ |
72 $tabs = apply_filters( 'install_themes_tabs', $tabs ); |
72 $tabs = apply_filters( 'install_themes_tabs', $tabs ); |
134 * |
139 * |
135 * @param array $args An array of themes API arguments. |
140 * @param array $args An array of themes API arguments. |
136 */ |
141 */ |
137 $args = apply_filters( "install_themes_table_api_args_{$tab}", $args ); |
142 $args = apply_filters( "install_themes_table_api_args_{$tab}", $args ); |
138 |
143 |
139 if ( ! $args ) |
144 if ( ! $args ) { |
140 return; |
145 return; |
|
146 } |
141 |
147 |
142 $api = themes_api( 'query_themes', $args ); |
148 $api = themes_api( 'query_themes', $args ); |
143 |
149 |
144 if ( is_wp_error( $api ) ) |
150 if ( is_wp_error( $api ) ) { |
145 wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' ); |
151 wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' ); |
|
152 } |
146 |
153 |
147 $this->items = $api->themes; |
154 $this->items = $api->themes; |
148 |
155 |
149 $this->set_pagination_args( array( |
156 $this->set_pagination_args( |
150 'total_items' => $api->info['results'], |
157 array( |
151 'per_page' => $args['per_page'], |
158 'total_items' => $api->info['results'], |
152 'infinite_scroll' => true, |
159 'per_page' => $args['per_page'], |
153 ) ); |
160 'infinite_scroll' => true, |
|
161 ) |
|
162 ); |
154 } |
163 } |
155 |
164 |
156 /** |
165 /** |
157 */ |
166 */ |
158 public function no_items() { |
167 public function no_items() { |
159 _e( 'No themes match your request.' ); |
168 _e( 'No themes match your request.' ); |
160 } |
169 } |
161 |
170 |
162 /** |
171 /** |
163 * |
|
164 * @global array $tabs |
172 * @global array $tabs |
165 * @global string $tab |
173 * @global string $tab |
166 * @return array |
174 * @return array |
167 */ |
175 */ |
168 protected function get_views() { |
176 protected function get_views() { |
169 global $tabs, $tab; |
177 global $tabs, $tab; |
170 |
178 |
171 $display_tabs = array(); |
179 $display_tabs = array(); |
172 foreach ( (array) $tabs as $action => $text ) { |
180 foreach ( (array) $tabs as $action => $text ) { |
173 $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; |
181 $current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; |
174 $href = self_admin_url('theme-install.php?tab=' . $action); |
182 $href = self_admin_url( 'theme-install.php?tab=' . $action ); |
175 $display_tabs['theme-install-'.$action] = "<a href='$href'$current_link_attributes>$text</a>"; |
183 $display_tabs[ 'theme-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>"; |
176 } |
184 } |
177 |
185 |
178 return $display_tabs; |
186 return $display_tabs; |
179 } |
187 } |
180 |
188 |
181 /** |
189 /** |
182 */ |
190 */ |
183 public function display() { |
191 public function display() { |
184 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); |
192 wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); |
185 ?> |
193 ?> |
186 <div class="tablenav top themes"> |
194 <div class="tablenav top themes"> |
187 <div class="alignleft actions"> |
195 <div class="alignleft actions"> |
188 <?php |
196 <?php |
189 /** |
197 /** |
190 * Fires in the Install Themes list table header. |
198 * Fires in the Install Themes list table header. |
228 * @global array $themes_allowedtags |
239 * @global array $themes_allowedtags |
229 * |
240 * |
230 * @param object $theme { |
241 * @param object $theme { |
231 * An object that contains theme data returned by the WordPress.org API. |
242 * An object that contains theme data returned by the WordPress.org API. |
232 * |
243 * |
233 * @type string $name Theme name, e.g. 'Twenty Seventeen'. |
244 * @type string $name Theme name, e.g. 'Twenty Nineteen'. |
234 * @type string $slug Theme slug, e.g. 'twentyseventeen'. |
245 * @type string $slug Theme slug, e.g. 'twentynineteen'. |
235 * @type string $version Theme version, e.g. '1.1'. |
246 * @type string $version Theme version, e.g. '1.1'. |
236 * @type string $author Theme author username, e.g. 'melchoyce'. |
247 * @type string $author Theme author username, e.g. 'melchoyce'. |
237 * @type string $preview_url Preview URL, e.g. 'http://2017.wordpress.net/'. |
248 * @type string $preview_url Preview URL, e.g. 'http://2019.wordpress.net/'. |
238 * @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentyseventeen/'. |
249 * @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentynineteen/'. |
239 * @type float $rating Rating score. |
250 * @type float $rating Rating score. |
240 * @type int $num_ratings The number of ratings. |
251 * @type int $num_ratings The number of ratings. |
241 * @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentyseventeen/'. |
252 * @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentynineteen/'. |
242 * @type string $description Theme description. |
253 * @type string $description Theme description. |
243 * @type string $download_link Theme ZIP download URL. |
254 * @type string $download_link Theme ZIP download URL. |
244 * } |
255 * } |
245 */ |
256 */ |
246 public function single_row( $theme ) { |
257 public function single_row( $theme ) { |
247 global $themes_allowedtags; |
258 global $themes_allowedtags; |
248 |
259 |
249 if ( empty( $theme ) ) |
260 if ( empty( $theme ) ) { |
250 return; |
261 return; |
251 |
262 } |
252 $name = wp_kses( $theme->name, $themes_allowedtags ); |
263 |
|
264 $name = wp_kses( $theme->name, $themes_allowedtags ); |
253 $author = wp_kses( $theme->author, $themes_allowedtags ); |
265 $author = wp_kses( $theme->author, $themes_allowedtags ); |
254 |
266 |
255 $preview_title = sprintf( __('Preview “%s”'), $name ); |
267 /* translators: %s: theme name */ |
256 $preview_url = add_query_arg( array( |
268 $preview_title = sprintf( __( 'Preview “%s”' ), $name ); |
257 'tab' => 'theme-information', |
269 $preview_url = add_query_arg( |
258 'theme' => $theme->slug, |
270 array( |
259 ), self_admin_url( 'theme-install.php' ) ); |
271 'tab' => 'theme-information', |
|
272 'theme' => $theme->slug, |
|
273 ), |
|
274 self_admin_url( 'theme-install.php' ) |
|
275 ); |
260 |
276 |
261 $actions = array(); |
277 $actions = array(); |
262 |
278 |
263 $install_url = add_query_arg( array( |
279 $install_url = add_query_arg( |
264 'action' => 'install-theme', |
280 array( |
265 'theme' => $theme->slug, |
281 'action' => 'install-theme', |
266 ), self_admin_url( 'update.php' ) ); |
282 'theme' => $theme->slug, |
267 |
283 ), |
268 $update_url = add_query_arg( array( |
284 self_admin_url( 'update.php' ) |
269 'action' => 'upgrade-theme', |
285 ); |
270 'theme' => $theme->slug, |
286 |
271 ), self_admin_url( 'update.php' ) ); |
287 $update_url = add_query_arg( |
|
288 array( |
|
289 'action' => 'upgrade-theme', |
|
290 'theme' => $theme->slug, |
|
291 ), |
|
292 self_admin_url( 'update.php' ) |
|
293 ); |
272 |
294 |
273 $status = $this->_get_theme_status( $theme ); |
295 $status = $this->_get_theme_status( $theme ); |
274 |
296 |
275 switch ( $status ) { |
297 switch ( $status ) { |
276 case 'update_available': |
298 case 'update_available': |
277 $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ) . '">' . __( 'Update' ) . '</a>'; |
299 $actions[] = sprintf( |
|
300 '<a class="install-now" href="%s" title="%s">%s</a>', |
|
301 esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ), |
|
302 /* translators: %s: theme version */ |
|
303 esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ), |
|
304 __( 'Update' ) |
|
305 ); |
278 break; |
306 break; |
279 case 'newer_installed': |
307 case 'newer_installed': |
280 case 'latest_installed': |
308 case 'latest_installed': |
281 $actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; |
309 $actions[] = sprintf( |
|
310 '<span class="install-now" title="%s">%s</span>', |
|
311 esc_attr__( 'This theme is already installed and is up to date' ), |
|
312 _x( 'Installed', 'theme' ) |
|
313 ); |
282 break; |
314 break; |
283 case 'install': |
315 case 'install': |
284 default: |
316 default: |
285 $actions[] = '<a class="install-now" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '" title="' . esc_attr( sprintf( __( 'Install %s' ), $name ) ) . '">' . __( 'Install Now' ) . '</a>'; |
317 $actions[] = sprintf( |
286 break; |
318 '<a class="install-now" href="%s" title="%s">%s</a>', |
287 } |
319 esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ), |
288 |
320 /* translators: %s: theme name */ |
289 $actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>'; |
321 esc_attr( sprintf( __( 'Install %s' ), $name ) ), |
|
322 __( 'Install Now' ) |
|
323 ); |
|
324 break; |
|
325 } |
|
326 |
|
327 $actions[] = sprintf( |
|
328 '<a class="install-theme-preview" href="%s" title="%s">%s</a>', |
|
329 esc_url( $preview_url ), |
|
330 /* translators: %s: theme name */ |
|
331 esc_attr( sprintf( __( 'Preview %s' ), $name ) ), |
|
332 __( 'Preview' ) |
|
333 ); |
290 |
334 |
291 /** |
335 /** |
292 * Filters the install action links for a theme in the Install Themes list table. |
336 * Filters the install action links for a theme in the Install Themes list table. |
293 * |
337 * |
294 * @since 3.4.0 |
338 * @since 3.4.0 |
295 * |
339 * |
296 * @param array $actions An array of theme action hyperlinks. Defaults are |
340 * @param string[] $actions An array of theme action links. Defaults are |
297 * links to Install Now, Preview, and Details. |
341 * links to Install Now, Preview, and Details. |
298 * @param WP_Theme $theme Theme object. |
342 * @param WP_Theme $theme Theme object. |
299 */ |
343 */ |
300 $actions = apply_filters( 'theme_install_actions', $actions, $theme ); |
344 $actions = apply_filters( 'theme_install_actions', $actions, $theme ); |
301 |
345 |
373 * @param object $theme - A WordPress.org Theme API object. |
422 * @param object $theme - A WordPress.org Theme API object. |
374 */ |
423 */ |
375 public function install_theme_info( $theme ) { |
424 public function install_theme_info( $theme ) { |
376 global $themes_allowedtags; |
425 global $themes_allowedtags; |
377 |
426 |
378 if ( empty( $theme ) ) |
427 if ( empty( $theme ) ) { |
379 return; |
428 return; |
380 |
429 } |
381 $name = wp_kses( $theme->name, $themes_allowedtags ); |
430 |
|
431 $name = wp_kses( $theme->name, $themes_allowedtags ); |
382 $author = wp_kses( $theme->author, $themes_allowedtags ); |
432 $author = wp_kses( $theme->author, $themes_allowedtags ); |
383 |
433 |
384 $install_url = add_query_arg( array( |
434 $install_url = add_query_arg( |
385 'action' => 'install-theme', |
435 array( |
386 'theme' => $theme->slug, |
436 'action' => 'install-theme', |
387 ), self_admin_url( 'update.php' ) ); |
437 'theme' => $theme->slug, |
388 |
438 ), |
389 $update_url = add_query_arg( array( |
439 self_admin_url( 'update.php' ) |
390 'action' => 'upgrade-theme', |
440 ); |
391 'theme' => $theme->slug, |
441 |
392 ), self_admin_url( 'update.php' ) ); |
442 $update_url = add_query_arg( |
|
443 array( |
|
444 'action' => 'upgrade-theme', |
|
445 'theme' => $theme->slug, |
|
446 ), |
|
447 self_admin_url( 'update.php' ) |
|
448 ); |
393 |
449 |
394 $status = $this->_get_theme_status( $theme ); |
450 $status = $this->_get_theme_status( $theme ); |
395 |
451 |
396 ?> |
452 ?> |
397 <div class="install-theme-info"><?php |
453 <div class="install-theme-info"> |
398 switch ( $status ) { |
454 <?php |
399 case 'update_available': |
455 switch ( $status ) { |
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>'; |
456 case 'update_available': |
401 break; |
457 printf( |
402 case 'newer_installed': |
458 '<a class="theme-install button button-primary" href="%s" title="%s">%s</a>', |
403 case 'latest_installed': |
459 esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ), |
404 echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; |
460 /* translators: %s: theme version */ |
405 break; |
461 esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ), |
406 case 'install': |
462 __( 'Update' ) |
407 default: |
463 ); |
408 echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>'; |
464 break; |
409 break; |
465 case 'newer_installed': |
410 } ?> |
466 case 'latest_installed': |
|
467 printf( |
|
468 '<span class="theme-install" title="%s">%s</span>', |
|
469 esc_attr__( 'This theme is already installed and is up to date' ), |
|
470 _x( 'Installed', 'theme' ) |
|
471 ); |
|
472 break; |
|
473 case 'install': |
|
474 default: |
|
475 printf( |
|
476 '<a class="theme-install button button-primary" href="%s">%s</a>', |
|
477 esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ), |
|
478 __( 'Install' ) |
|
479 ); |
|
480 break; |
|
481 } |
|
482 ?> |
411 <h3 class="theme-name"><?php echo $name; ?></h3> |
483 <h3 class="theme-name"><?php echo $name; ?></h3> |
412 <span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span> |
484 <span class="theme-by"> |
413 <?php if ( isset( $theme->screenshot_url ) ): ?> |
485 <?php |
|
486 /* translators: %s: theme author */ |
|
487 printf( __( 'By %s' ), $author ); |
|
488 ?> |
|
489 </span> |
|
490 <?php if ( isset( $theme->screenshot_url ) ) : ?> |
414 <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" /> |
491 <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" /> |
415 <?php endif; ?> |
492 <?php endif; ?> |
416 <div class="theme-details"> |
493 <div class="theme-details"> |
417 <?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?> |
494 <?php |
|
495 wp_star_rating( |
|
496 array( |
|
497 'rating' => $theme->rating, |
|
498 'type' => 'percent', |
|
499 'number' => $theme->num_ratings, |
|
500 ) |
|
501 ); |
|
502 ?> |
418 <div class="theme-version"> |
503 <div class="theme-version"> |
419 <strong><?php _e('Version:') ?> </strong> |
504 <strong><?php _e( 'Version:' ); ?> </strong> |
420 <?php echo wp_kses( $theme->version, $themes_allowedtags ); ?> |
505 <?php echo wp_kses( $theme->version, $themes_allowedtags ); ?> |
421 </div> |
506 </div> |
422 <div class="theme-description"> |
507 <div class="theme-description"> |
423 <?php echo wp_kses( $theme->description, $themes_allowedtags ); ?> |
508 <?php echo wp_kses( $theme->description, $themes_allowedtags ); ?> |
424 </div> |
509 </div> |