author | ymh <ymh.work@gmail.com> |
Tue, 15 Oct 2019 15:48:13 +0200 | |
changeset 13 | d255fe9cd479 |
parent 9 | 177826044cd9 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* List Table API: WP_Theme_Install_List_Table class |
0 | 4 |
* |
5 |
* @package WordPress |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* @subpackage Administration |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
9 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
* Core class used to implement displaying themes to install in a list table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
* |
0 | 13 |
* @since 3.1.0 |
14 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @see WP_Themes_List_Table |
0 | 17 |
*/ |
18 |
class WP_Theme_Install_List_Table extends WP_Themes_List_Table { |
|
19 |
||
5 | 20 |
public $features = array(); |
0 | 21 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
*/ |
5 | 25 |
public function ajax_user_can() { |
0 | 26 |
return current_user_can( 'install_themes' ); |
27 |
} |
|
28 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* @global array $tabs |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* @global string $tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* @global string $type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* @global array $theme_field_defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
*/ |
5 | 36 |
public function prepare_items() { |
0 | 37 |
include( ABSPATH . 'wp-admin/includes/theme-install.php' ); |
38 |
||
39 |
global $tabs, $tab, $paged, $type, $theme_field_defaults; |
|
40 |
wp_reset_vars( array( 'tab' ) ); |
|
41 |
||
9 | 42 |
$search_terms = array(); |
0 | 43 |
$search_string = ''; |
9 | 44 |
if ( ! empty( $_REQUEST['s'] ) ) { |
0 | 45 |
$search_string = strtolower( wp_unslash( $_REQUEST['s'] ) ); |
9 | 46 |
$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); |
0 | 47 |
} |
48 |
||
9 | 49 |
if ( ! empty( $_REQUEST['features'] ) ) { |
0 | 50 |
$this->features = $_REQUEST['features']; |
9 | 51 |
} |
0 | 52 |
|
53 |
$paged = $this->get_pagenum(); |
|
54 |
||
55 |
$per_page = 36; |
|
56 |
||
57 |
// These are the tabs which are shown on the page, |
|
9 | 58 |
$tabs = array(); |
0 | 59 |
$tabs['dashboard'] = __( 'Search' ); |
9 | 60 |
if ( 'search' === $tab ) { |
61 |
$tabs['search'] = __( 'Search Results' ); |
|
62 |
} |
|
63 |
$tabs['upload'] = __( 'Upload' ); |
|
5 | 64 |
$tabs['featured'] = _x( 'Featured', 'themes' ); |
65 |
//$tabs['popular'] = _x( 'Popular', 'themes' ); |
|
9 | 66 |
$tabs['new'] = _x( 'Latest', 'themes' ); |
67 |
$tabs['updated'] = _x( 'Recently Updated', 'themes' ); |
|
0 | 68 |
|
69 |
$nonmenu_tabs = array( 'theme-information' ); // Valid actions to perform which do not have a Menu item. |
|
70 |
||
5 | 71 |
/** This filter is documented in wp-admin/theme-install.php */ |
0 | 72 |
$tabs = apply_filters( 'install_themes_tabs', $tabs ); |
5 | 73 |
|
74 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
* Filters tabs not associated with a menu item on the Install Themes screen. |
5 | 76 |
* |
77 |
* @since 2.8.0 |
|
78 |
* |
|
9 | 79 |
* @param string[] $nonmenu_tabs The tabs that don't have a menu item on |
80 |
* the Install Themes screen. |
|
5 | 81 |
*/ |
0 | 82 |
$nonmenu_tabs = apply_filters( 'install_themes_nonmenu_tabs', $nonmenu_tabs ); |
83 |
||
84 |
// If a non-valid menu tab has been selected, And it's not a non-menu action. |
|
9 | 85 |
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) { |
0 | 86 |
$tab = key( $tabs ); |
9 | 87 |
} |
0 | 88 |
|
9 | 89 |
$args = array( |
90 |
'page' => $paged, |
|
91 |
'per_page' => $per_page, |
|
92 |
'fields' => $theme_field_defaults, |
|
93 |
); |
|
0 | 94 |
|
95 |
switch ( $tab ) { |
|
96 |
case 'search': |
|
97 |
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; |
|
98 |
switch ( $type ) { |
|
99 |
case 'tag': |
|
100 |
$args['tag'] = array_map( 'sanitize_key', $search_terms ); |
|
101 |
break; |
|
102 |
case 'term': |
|
103 |
$args['search'] = $search_string; |
|
104 |
break; |
|
105 |
case 'author': |
|
106 |
$args['author'] = $search_string; |
|
107 |
break; |
|
108 |
} |
|
109 |
||
110 |
if ( ! empty( $this->features ) ) { |
|
9 | 111 |
$args['tag'] = $this->features; |
112 |
$_REQUEST['s'] = implode( ',', $this->features ); |
|
0 | 113 |
$_REQUEST['type'] = 'tag'; |
114 |
} |
|
115 |
||
116 |
add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 ); |
|
117 |
break; |
|
118 |
||
119 |
case 'featured': |
|
9 | 120 |
// case 'popular': |
0 | 121 |
case 'new': |
122 |
case 'updated': |
|
123 |
$args['browse'] = $tab; |
|
124 |
break; |
|
125 |
||
126 |
default: |
|
127 |
$args = false; |
|
128 |
break; |
|
129 |
} |
|
130 |
||
5 | 131 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
* Filters API request arguments for each Install Themes screen tab. |
5 | 133 |
* |
134 |
* The dynamic portion of the hook name, `$tab`, refers to the theme install |
|
135 |
* tabs. Default tabs are 'dashboard', 'search', 'upload', 'featured', |
|
136 |
* 'new', and 'updated'. |
|
137 |
* |
|
138 |
* @since 3.7.0 |
|
139 |
* |
|
140 |
* @param array $args An array of themes API arguments. |
|
141 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
$args = apply_filters( "install_themes_table_api_args_{$tab}", $args ); |
0 | 143 |
|
9 | 144 |
if ( ! $args ) { |
0 | 145 |
return; |
9 | 146 |
} |
0 | 147 |
|
148 |
$api = themes_api( 'query_themes', $args ); |
|
149 |
||
9 | 150 |
if ( is_wp_error( $api ) ) { |
0 | 151 |
wp_die( $api->get_error_message() . '</p> <p><a href="#" onclick="document.location.reload(); return false;">' . __( 'Try again' ) . '</a>' ); |
9 | 152 |
} |
0 | 153 |
|
154 |
$this->items = $api->themes; |
|
155 |
||
9 | 156 |
$this->set_pagination_args( |
157 |
array( |
|
158 |
'total_items' => $api->info['results'], |
|
159 |
'per_page' => $args['per_page'], |
|
160 |
'infinite_scroll' => true, |
|
161 |
) |
|
162 |
); |
|
0 | 163 |
} |
164 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
*/ |
5 | 167 |
public function no_items() { |
0 | 168 |
_e( 'No themes match your request.' ); |
169 |
} |
|
170 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
* @global array $tabs |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
* @global string $tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
*/ |
5 | 176 |
protected function get_views() { |
0 | 177 |
global $tabs, $tab; |
178 |
||
179 |
$display_tabs = array(); |
|
180 |
foreach ( (array) $tabs as $action => $text ) { |
|
9 | 181 |
$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; |
182 |
$href = self_admin_url( 'theme-install.php?tab=' . $action ); |
|
183 |
$display_tabs[ 'theme-install-' . $action ] = "<a href='$href'$current_link_attributes>$text</a>"; |
|
0 | 184 |
} |
185 |
||
186 |
return $display_tabs; |
|
187 |
} |
|
188 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
*/ |
5 | 191 |
public function display() { |
9 | 192 |
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); |
193 |
?> |
|
0 | 194 |
<div class="tablenav top themes"> |
195 |
<div class="alignleft actions"> |
|
5 | 196 |
<?php |
197 |
/** |
|
198 |
* Fires in the Install Themes list table header. |
|
199 |
* |
|
200 |
* @since 2.8.0 |
|
201 |
*/ |
|
202 |
do_action( 'install_themes_table_header' ); |
|
203 |
?> |
|
0 | 204 |
</div> |
205 |
<?php $this->pagination( 'top' ); ?> |
|
206 |
<br class="clear" /> |
|
207 |
</div> |
|
208 |
||
209 |
<div id="availablethemes"> |
|
210 |
<?php $this->display_rows_or_placeholder(); ?> |
|
211 |
</div> |
|
212 |
||
213 |
<?php |
|
5 | 214 |
$this->tablenav( 'bottom' ); |
0 | 215 |
} |
216 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
*/ |
5 | 219 |
public function display_rows() { |
0 | 220 |
$themes = $this->items; |
221 |
foreach ( $themes as $theme ) { |
|
9 | 222 |
?> |
223 |
<div class="available-theme installable-theme"> |
|
224 |
<?php |
|
0 | 225 |
$this->single_row( $theme ); |
9 | 226 |
?> |
227 |
</div> |
|
228 |
<?php |
|
229 |
} // end foreach $theme_names |
|
0 | 230 |
|
231 |
$this->theme_installer(); |
|
232 |
} |
|
233 |
||
5 | 234 |
/** |
0 | 235 |
* Prints a theme from the WordPress.org API. |
236 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* @global array $themes_allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* @param object $theme { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* An object that contains theme data returned by the WordPress.org API. |
0 | 243 |
* |
9 | 244 |
* @type string $name Theme name, e.g. 'Twenty Nineteen'. |
245 |
* @type string $slug Theme slug, e.g. 'twentynineteen'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* @type string $version Theme version, e.g. '1.1'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* @type string $author Theme author username, e.g. 'melchoyce'. |
9 | 248 |
* @type string $preview_url Preview URL, e.g. 'http://2019.wordpress.net/'. |
249 |
* @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentynineteen/'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* @type float $rating Rating score. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* @type int $num_ratings The number of ratings. |
9 | 252 |
* @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentynineteen/'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* @type string $description Theme description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
* @type string $download_link Theme ZIP download URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* } |
0 | 256 |
*/ |
5 | 257 |
public function single_row( $theme ) { |
0 | 258 |
global $themes_allowedtags; |
259 |
||
9 | 260 |
if ( empty( $theme ) ) { |
0 | 261 |
return; |
9 | 262 |
} |
0 | 263 |
|
9 | 264 |
$name = wp_kses( $theme->name, $themes_allowedtags ); |
0 | 265 |
$author = wp_kses( $theme->author, $themes_allowedtags ); |
266 |
||
9 | 267 |
/* translators: %s: theme name */ |
268 |
$preview_title = sprintf( __( 'Preview “%s”' ), $name ); |
|
269 |
$preview_url = add_query_arg( |
|
270 |
array( |
|
271 |
'tab' => 'theme-information', |
|
272 |
'theme' => $theme->slug, |
|
273 |
), |
|
274 |
self_admin_url( 'theme-install.php' ) |
|
275 |
); |
|
0 | 276 |
|
277 |
$actions = array(); |
|
278 |
||
9 | 279 |
$install_url = add_query_arg( |
280 |
array( |
|
281 |
'action' => 'install-theme', |
|
282 |
'theme' => $theme->slug, |
|
283 |
), |
|
284 |
self_admin_url( 'update.php' ) |
|
285 |
); |
|
0 | 286 |
|
9 | 287 |
$update_url = add_query_arg( |
288 |
array( |
|
289 |
'action' => 'upgrade-theme', |
|
290 |
'theme' => $theme->slug, |
|
291 |
), |
|
292 |
self_admin_url( 'update.php' ) |
|
293 |
); |
|
0 | 294 |
|
295 |
$status = $this->_get_theme_status( $theme ); |
|
296 |
||
297 |
switch ( $status ) { |
|
298 |
case 'update_available': |
|
9 | 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 |
); |
|
0 | 306 |
break; |
307 |
case 'newer_installed': |
|
308 |
case 'latest_installed': |
|
9 | 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 |
); |
|
0 | 314 |
break; |
5 | 315 |
case 'install': |
316 |
default: |
|
9 | 317 |
$actions[] = sprintf( |
318 |
'<a class="install-now" href="%s" title="%s">%s</a>', |
|
319 |
esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ), |
|
320 |
/* translators: %s: theme name */ |
|
321 |
esc_attr( sprintf( __( 'Install %s' ), $name ) ), |
|
322 |
__( 'Install Now' ) |
|
323 |
); |
|
5 | 324 |
break; |
0 | 325 |
} |
326 |
||
9 | 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 |
); |
|
0 | 334 |
|
5 | 335 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* Filters the install action links for a theme in the Install Themes list table. |
5 | 337 |
* |
338 |
* @since 3.4.0 |
|
339 |
* |
|
9 | 340 |
* @param string[] $actions An array of theme action links. Defaults are |
5 | 341 |
* links to Install Now, Preview, and Details. |
342 |
* @param WP_Theme $theme Theme object. |
|
343 |
*/ |
|
0 | 344 |
$actions = apply_filters( 'theme_install_actions', $actions, $theme ); |
345 |
||
346 |
?> |
|
347 |
<a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
<img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" /> |
0 | 349 |
</a> |
350 |
||
351 |
<h3><?php echo $name; ?></h3> |
|
9 | 352 |
<div class="theme-author"> |
353 |
<?php |
|
354 |
/* translators: %s: theme author */ |
|
355 |
printf( __( 'By %s' ), $author ); |
|
356 |
?> |
|
357 |
</div> |
|
0 | 358 |
|
359 |
<div class="action-links"> |
|
360 |
<ul> |
|
9 | 361 |
<?php foreach ( $actions as $action ) : ?> |
0 | 362 |
<li><?php echo $action; ?></li> |
363 |
<?php endforeach; ?> |
|
9 | 364 |
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e( 'Details' ); ?></a></li> |
0 | 365 |
</ul> |
366 |
</div> |
|
367 |
||
368 |
<?php |
|
369 |
$this->install_theme_info( $theme ); |
|
370 |
} |
|
371 |
||
5 | 372 |
/** |
0 | 373 |
* Prints the wrapper for the theme installer. |
374 |
*/ |
|
5 | 375 |
public function theme_installer() { |
0 | 376 |
?> |
377 |
<div id="theme-installer" class="wp-full-overlay expanded"> |
|
378 |
<div class="wp-full-overlay-sidebar"> |
|
379 |
<div class="wp-full-overlay-header"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
<a href="#" class="close-full-overlay button"><?php _e( 'Close' ); ?></a> |
5 | 381 |
<span class="theme-install"></span> |
0 | 382 |
</div> |
383 |
<div class="wp-full-overlay-sidebar-content"> |
|
384 |
<div class="install-theme-info"></div> |
|
385 |
</div> |
|
386 |
<div class="wp-full-overlay-footer"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
<button type="button" class="collapse-sidebar button" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>"> |
0 | 388 |
<span class="collapse-sidebar-arrow"></span> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
<span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
</button> |
0 | 391 |
</div> |
392 |
</div> |
|
393 |
<div class="wp-full-overlay-main"></div> |
|
394 |
</div> |
|
395 |
<?php |
|
396 |
} |
|
397 |
||
5 | 398 |
/** |
0 | 399 |
* Prints the wrapper for the theme installer with a provided theme's data. |
400 |
* Used to make the theme installer work for no-js. |
|
401 |
* |
|
402 |
* @param object $theme - A WordPress.org Theme API object. |
|
403 |
*/ |
|
5 | 404 |
public function theme_installer_single( $theme ) { |
0 | 405 |
?> |
406 |
<div id="theme-installer" class="wp-full-overlay single-theme"> |
|
407 |
<div class="wp-full-overlay-sidebar"> |
|
408 |
<?php $this->install_theme_info( $theme ); ?> |
|
409 |
</div> |
|
410 |
<div class="wp-full-overlay-main"> |
|
411 |
<iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe> |
|
412 |
</div> |
|
413 |
</div> |
|
414 |
<?php |
|
415 |
} |
|
416 |
||
5 | 417 |
/** |
0 | 418 |
* Prints the info for a theme (to be used in the theme installer modal). |
419 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
420 |
* @global array $themes_allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
* |
0 | 422 |
* @param object $theme - A WordPress.org Theme API object. |
423 |
*/ |
|
5 | 424 |
public function install_theme_info( $theme ) { |
0 | 425 |
global $themes_allowedtags; |
426 |
||
9 | 427 |
if ( empty( $theme ) ) { |
0 | 428 |
return; |
9 | 429 |
} |
0 | 430 |
|
9 | 431 |
$name = wp_kses( $theme->name, $themes_allowedtags ); |
0 | 432 |
$author = wp_kses( $theme->author, $themes_allowedtags ); |
433 |
||
9 | 434 |
$install_url = add_query_arg( |
435 |
array( |
|
436 |
'action' => 'install-theme', |
|
437 |
'theme' => $theme->slug, |
|
438 |
), |
|
439 |
self_admin_url( 'update.php' ) |
|
440 |
); |
|
0 | 441 |
|
9 | 442 |
$update_url = add_query_arg( |
443 |
array( |
|
444 |
'action' => 'upgrade-theme', |
|
445 |
'theme' => $theme->slug, |
|
446 |
), |
|
447 |
self_admin_url( 'update.php' ) |
|
448 |
); |
|
0 | 449 |
|
450 |
$status = $this->_get_theme_status( $theme ); |
|
451 |
||
452 |
?> |
|
9 | 453 |
<div class="install-theme-info"> |
454 |
<?php |
|
455 |
switch ( $status ) { |
|
456 |
case 'update_available': |
|
457 |
printf( |
|
458 |
'<a class="theme-install button button-primary" href="%s" title="%s">%s</a>', |
|
459 |
esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ), |
|
460 |
/* translators: %s: theme version */ |
|
461 |
esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ), |
|
462 |
__( 'Update' ) |
|
463 |
); |
|
464 |
break; |
|
465 |
case 'newer_installed': |
|
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 |
?> |
|
0 | 483 |
<h3 class="theme-name"><?php echo $name; ?></h3> |
9 | 484 |
<span class="theme-by"> |
485 |
<?php |
|
486 |
/* translators: %s: theme author */ |
|
487 |
printf( __( 'By %s' ), $author ); |
|
488 |
?> |
|
489 |
</span> |
|
490 |
<?php if ( isset( $theme->screenshot_url ) ) : ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" /> |
0 | 492 |
<?php endif; ?> |
493 |
<div class="theme-details"> |
|
9 | 494 |
<?php |
495 |
wp_star_rating( |
|
496 |
array( |
|
497 |
'rating' => $theme->rating, |
|
498 |
'type' => 'percent', |
|
499 |
'number' => $theme->num_ratings, |
|
500 |
) |
|
501 |
); |
|
502 |
?> |
|
0 | 503 |
<div class="theme-version"> |
9 | 504 |
<strong><?php _e( 'Version:' ); ?> </strong> |
0 | 505 |
<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?> |
506 |
</div> |
|
507 |
<div class="theme-description"> |
|
508 |
<?php echo wp_kses( $theme->description, $themes_allowedtags ); ?> |
|
509 |
</div> |
|
510 |
</div> |
|
511 |
<input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" /> |
|
512 |
</div> |
|
513 |
<?php |
|
514 |
} |
|
515 |
||
516 |
/** |
|
517 |
* Send required variables to JavaScript land |
|
518 |
* |
|
5 | 519 |
* @since 3.4.0 |
0 | 520 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
* @global string $tab Current tab within Themes->Install screen |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
* @global string $type Type of search. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
* @param array $extra_args Unused. |
0 | 525 |
*/ |
5 | 526 |
public function _js_vars( $extra_args = array() ) { |
0 | 527 |
global $tab, $type; |
528 |
parent::_js_vars( compact( 'tab', 'type' ) ); |
|
529 |
} |
|
530 |
||
531 |
/** |
|
532 |
* Check to see if the theme is already installed. |
|
533 |
* |
|
5 | 534 |
* @since 3.4.0 |
0 | 535 |
* |
536 |
* @param object $theme - A WordPress.org Theme API object. |
|
537 |
* @return string Theme status. |
|
538 |
*/ |
|
539 |
private function _get_theme_status( $theme ) { |
|
540 |
$status = 'install'; |
|
541 |
||
542 |
$installed_theme = wp_get_theme( $theme->slug ); |
|
543 |
if ( $installed_theme->exists() ) { |
|
9 | 544 |
if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) { |
0 | 545 |
$status = 'latest_installed'; |
9 | 546 |
} elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) { |
0 | 547 |
$status = 'newer_installed'; |
9 | 548 |
} else { |
0 | 549 |
$status = 'update_available'; |
9 | 550 |
} |
0 | 551 |
} |
552 |
||
553 |
return $status; |
|
554 |
} |
|
555 |
} |