3
* Theme Installer List Table class.
6
* @subpackage List_Table
10
class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
12
public $features = array();
14
public function ajax_user_can() {
15
return current_user_can( 'install_themes' );
18
public function prepare_items() {
19
include( ABSPATH . 'wp-admin/includes/theme-install.php' );
21
global $tabs, $tab, $paged, $type, $theme_field_defaults;
22
wp_reset_vars( array( 'tab' ) );
24
$search_terms = array();
26
if ( ! empty( $_REQUEST['s'] ) ){
27
$search_string = strtolower( wp_unslash( $_REQUEST['s'] ) );
28
$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) );
31
if ( ! empty( $_REQUEST['features'] ) )
32
$this->features = $_REQUEST['features'];
34
$paged = $this->get_pagenum();
38
// These are the tabs which are shown on the page,
40
$tabs['dashboard'] = __( 'Search' );
41
if ( 'search' == $tab )
42
$tabs['search'] = __( 'Search Results' );
43
$tabs['upload'] = __( 'Upload' );
44
$tabs['featured'] = _x( 'Featured', 'themes' );
45
//$tabs['popular'] = _x( 'Popular', 'themes' );
46
$tabs['new'] = _x( 'Latest', 'themes' );
47
$tabs['updated'] = _x( 'Recently Updated', 'themes' );
49
$nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item.
51
/** This filter is documented in wp-admin/theme-install.php */
52
$tabs = apply_filters( 'install_themes_tabs', $tabs );
55
* Filter tabs not associated with a menu item on the Install Themes screen.
59
* @param array $nonmenu_tabs The tabs that don't have a menu item on
60
* the Install Themes screen.
62
$nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs );
64
// If a non-valid menu tab has been selected, And it's not a non-menu action.
65
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) )
68
$args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults );
72
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
75
$args['tag'] = array_map( 'sanitize_key', $search_terms );
78
$args['search'] = $search_string;
81
$args['author'] = $search_string;
85
if ( ! empty( $this->features ) ) {
86
$args['tag'] = $this->features;
87
$_REQUEST['s'] = implode( ',', $this->features );
88
$_REQUEST['type'] = 'tag';
91
add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 );
98
$args['browse'] = $tab;
107
* Filter API request arguments for each Install Themes screen tab.
109
* The dynamic portion of the hook name, $tab, refers to the theme install
110
* tabs. Default tabs are 'dashboard', 'search', 'upload', 'featured',
111
* 'new', and 'updated'.
115
* @param array $args An array of themes API arguments.
117
$args = apply_filters( 'install_themes_table_api_args_' . $tab, $args );
122
$api = themes_api( 'query_themes', $args );
124
if ( is_wp_error( $api ) )
125
wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' );
127
$this->items = $api->themes;
129
$this->set_pagination_args( array(
130
'total_items' => $api->info['results'],
131
'per_page' => $args['per_page'],
132
'infinite_scroll' => true,
136
public function no_items() {
137
_e( 'No themes match your request.' );
140
protected function get_views() {
143
$display_tabs = array();
144
foreach ( (array) $tabs as $action => $text ) {
145
$class = ( $action == $tab ) ? ' class="current"' : '';
146
$href = self_admin_url('theme-install.php?tab=' . $action);
147
$display_tabs['theme-install-'.$action] = "<a href='$href'$class>$text</a>";
150
return $display_tabs;
153
public function display() {
154
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
156
<div class="tablenav top themes">
157
<div class="alignleft actions">
160
* Fires in the Install Themes list table header.
164
do_action( 'install_themes_table_header' );
167
<?php $this->pagination( 'top' ); ?>
171
<div id="availablethemes">
172
<?php $this->display_rows_or_placeholder(); ?>
176
parent::tablenav( 'bottom' );
179
public function display_rows() {
180
$themes = $this->items;
181
foreach ( $themes as $theme ) {
183
<div class="available-theme installable-theme"><?php
184
$this->single_row( $theme );
186
<?php } // end foreach $theme_names
188
$this->theme_installer();
192
* Prints a theme from the WordPress.org API.
194
* @param object $theme An object that contains theme data returned by the WordPress.org API.
196
* Example theme data:
197
* object(stdClass)[59]
198
* public 'name' => string 'Magazine Basic'
199
* public 'slug' => string 'magazine-basic'
200
* public 'version' => string '1.1'
201
* public 'author' => string 'tinkerpriest'
202
* public 'preview_url' => string 'http://wp-themes.com/?magazine-basic'
203
* public 'screenshot_url' => string 'http://wp-themes.com/wp-content/themes/magazine-basic/screenshot.png'
204
* public 'rating' => float 80
205
* public 'num_ratings' => int 1
206
* public 'homepage' => string 'http://wordpress.org/themes/magazine-basic'
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>.'
208
* public 'download_link' => string 'http://wordpress.org/themes/download/magazine-basic.1.1.zip'
210
public function single_row( $theme ) {
211
global $themes_allowedtags;
213
if ( empty( $theme ) )
216
$name = wp_kses( $theme->name, $themes_allowedtags );
217
$author = wp_kses( $theme->author, $themes_allowedtags );
219
$preview_title = sprintf( __('Preview “%s”'), $name );
220
$preview_url = add_query_arg( array(
221
'tab' => 'theme-information',
222
'theme' => $theme->slug,
223
), self_admin_url( 'theme-install.php' ) );
227
$install_url = add_query_arg( array(
228
'action' => 'install-theme',
229
'theme' => $theme->slug,
230
), self_admin_url( 'update.php' ) );
232
$update_url = add_query_arg( array(
233
'action' => 'upgrade-theme',
234
'theme' => $theme->slug,
235
), self_admin_url( 'update.php' ) );
237
$status = $this->_get_theme_status( $theme );
240
case 'update_available':
241
$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>';
243
case 'newer_installed':
244
case 'latest_installed':
245
$actions[] = '<span class="install-now" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>';
249
$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>';
253
$actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>';
256
* Filter the install action links for a theme in the Install Themes list table.
260
* @param array $actions An array of theme action hyperlinks. Defaults are
261
* links to Install Now, Preview, and Details.
262
* @param WP_Theme $theme Theme object.
264
$actions = apply_filters( 'theme_install_actions', $actions, $theme );
267
<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" />
271
<h3><?php echo $name; ?></h3>
272
<div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div>
274
<div class="action-links">
276
<?php foreach ( $actions as $action ): ?>
277
<li><?php echo $action; ?></li>
279
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li>
284
$this->install_theme_info( $theme );
288
* Prints the wrapper for the theme installer.
290
public function theme_installer() {
292
<div id="theme-installer" class="wp-full-overlay expanded">
293
<div class="wp-full-overlay-sidebar">
294
<div class="wp-full-overlay-header">
295
<a href="#" class="close-full-overlay button-secondary"><?php _e( 'Close' ); ?></a>
296
<span class="theme-install"></span>
298
<div class="wp-full-overlay-sidebar-content">
299
<div class="install-theme-info"></div>
301
<div class="wp-full-overlay-footer">
302
<a href="#" class="collapse-sidebar" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
303
<span class="collapse-sidebar-label"><?php _e('Collapse'); ?></span>
304
<span class="collapse-sidebar-arrow"></span>
308
<div class="wp-full-overlay-main"></div>
314
* Prints the wrapper for the theme installer with a provided theme's data.
315
* Used to make the theme installer work for no-js.
317
* @param object $theme - A WordPress.org Theme API object.
319
public function theme_installer_single( $theme ) {
321
<div id="theme-installer" class="wp-full-overlay single-theme">
322
<div class="wp-full-overlay-sidebar">
323
<?php $this->install_theme_info( $theme ); ?>
325
<div class="wp-full-overlay-main">
326
<iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe>
333
* Prints the info for a theme (to be used in the theme installer modal).
335
* @param object $theme - A WordPress.org Theme API object.
337
public function install_theme_info( $theme ) {
338
global $themes_allowedtags;
340
if ( empty( $theme ) )
343
$name = wp_kses( $theme->name, $themes_allowedtags );
344
$author = wp_kses( $theme->author, $themes_allowedtags );
346
$install_url = add_query_arg( array(
347
'action' => 'install-theme',
348
'theme' => $theme->slug,
349
), self_admin_url( 'update.php' ) );
351
$update_url = add_query_arg( array(
352
'action' => 'upgrade-theme',
353
'theme' => $theme->slug,
354
), self_admin_url( 'update.php' ) );
356
$status = $this->_get_theme_status( $theme );
359
<div class="install-theme-info"><?php
361
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>';
364
case 'newer_installed':
365
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>';
370
echo '<a class="theme-install button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>';
373
<h3 class="theme-name"><?php echo $name; ?></h3>
374
<span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span>
375
<?php if ( isset( $theme->screenshot_url ) ): ?>
376
<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" />
378
<div class="theme-details">
379
<?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?>
380
<div class="theme-version">
381
<strong><?php _e('Version:') ?> </strong>
382
<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?>
384
<div class="theme-description">
385
<?php echo wp_kses( $theme->description, $themes_allowedtags ); ?>
388
<input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" />
394
* Send required variables to JavaScript land
399
* @uses $tab Global; current tab within Themes->Install screen
400
* @uses $type Global; type of search.
402
public function _js_vars( $extra_args = array() ) {
404
parent::_js_vars( compact( 'tab', 'type' ) );
408
* Check to see if the theme is already installed.
413
* @param object $theme - A WordPress.org Theme API object.
414
* @return string Theme status.
416
private function _get_theme_status( $theme ) {
419
$installed_theme = wp_get_theme( $theme->slug );
420
if ( $installed_theme->exists() ) {
421
if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) )
422
$status = 'latest_installed';
423
elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) )
424
$status = 'newer_installed';
426
$status = 'update_available';