author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
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() { |
16 | 37 |
require ABSPATH . 'wp-admin/includes/theme-install.php'; |
0 | 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. |
|
16 | 85 |
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs, true ) ) ) { |
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 |
* |
|
16 | 140 |
* @param array|false $args Theme install API arguments. |
5 | 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 ) ) { |
16 | 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 |
/** |
16 | 190 |
* Displays the theme install table. |
191 |
* |
|
192 |
* Overrides the parent display() method to provide a different container. |
|
193 |
* |
|
194 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
*/ |
5 | 196 |
public function display() { |
9 | 197 |
wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); |
198 |
?> |
|
0 | 199 |
<div class="tablenav top themes"> |
200 |
<div class="alignleft actions"> |
|
5 | 201 |
<?php |
202 |
/** |
|
203 |
* Fires in the Install Themes list table header. |
|
204 |
* |
|
205 |
* @since 2.8.0 |
|
206 |
*/ |
|
207 |
do_action( 'install_themes_table_header' ); |
|
208 |
?> |
|
0 | 209 |
</div> |
210 |
<?php $this->pagination( 'top' ); ?> |
|
211 |
<br class="clear" /> |
|
212 |
</div> |
|
213 |
||
214 |
<div id="availablethemes"> |
|
215 |
<?php $this->display_rows_or_placeholder(); ?> |
|
216 |
</div> |
|
217 |
||
218 |
<?php |
|
5 | 219 |
$this->tablenav( 'bottom' ); |
0 | 220 |
} |
221 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
*/ |
5 | 224 |
public function display_rows() { |
0 | 225 |
$themes = $this->items; |
226 |
foreach ( $themes as $theme ) { |
|
9 | 227 |
?> |
228 |
<div class="available-theme installable-theme"> |
|
229 |
<?php |
|
0 | 230 |
$this->single_row( $theme ); |
9 | 231 |
?> |
232 |
</div> |
|
233 |
<?php |
|
16 | 234 |
} // End foreach $theme_names. |
0 | 235 |
|
236 |
$this->theme_installer(); |
|
237 |
} |
|
238 |
||
5 | 239 |
/** |
0 | 240 |
* Prints a theme from the WordPress.org API. |
241 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* @global array $themes_allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* @param object $theme { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* An object that contains theme data returned by the WordPress.org API. |
0 | 248 |
* |
16 | 249 |
* @type string $name Theme name, e.g. 'Twenty Twenty'. |
250 |
* @type string $slug Theme slug, e.g. 'twentytwenty'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* @type string $version Theme version, e.g. '1.1'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
* @type string $author Theme author username, e.g. 'melchoyce'. |
16 | 253 |
* @type string $preview_url Preview URL, e.g. 'https://2020.wordpress.net/'. |
254 |
* @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentytwenty/'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* @type float $rating Rating score. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
* @type int $num_ratings The number of ratings. |
16 | 257 |
* @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentytwenty/'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
* @type string $description Theme description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
* @type string $download_link Theme ZIP download URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
* } |
0 | 261 |
*/ |
5 | 262 |
public function single_row( $theme ) { |
0 | 263 |
global $themes_allowedtags; |
264 |
||
9 | 265 |
if ( empty( $theme ) ) { |
0 | 266 |
return; |
9 | 267 |
} |
0 | 268 |
|
9 | 269 |
$name = wp_kses( $theme->name, $themes_allowedtags ); |
0 | 270 |
$author = wp_kses( $theme->author, $themes_allowedtags ); |
271 |
||
16 | 272 |
/* translators: %s: Theme name. */ |
9 | 273 |
$preview_title = sprintf( __( 'Preview “%s”' ), $name ); |
274 |
$preview_url = add_query_arg( |
|
275 |
array( |
|
276 |
'tab' => 'theme-information', |
|
277 |
'theme' => $theme->slug, |
|
278 |
), |
|
279 |
self_admin_url( 'theme-install.php' ) |
|
280 |
); |
|
0 | 281 |
|
282 |
$actions = array(); |
|
283 |
||
9 | 284 |
$install_url = add_query_arg( |
285 |
array( |
|
286 |
'action' => 'install-theme', |
|
287 |
'theme' => $theme->slug, |
|
288 |
), |
|
289 |
self_admin_url( 'update.php' ) |
|
290 |
); |
|
0 | 291 |
|
9 | 292 |
$update_url = add_query_arg( |
293 |
array( |
|
294 |
'action' => 'upgrade-theme', |
|
295 |
'theme' => $theme->slug, |
|
296 |
), |
|
297 |
self_admin_url( 'update.php' ) |
|
298 |
); |
|
0 | 299 |
|
300 |
$status = $this->_get_theme_status( $theme ); |
|
301 |
||
302 |
switch ( $status ) { |
|
303 |
case 'update_available': |
|
9 | 304 |
$actions[] = sprintf( |
305 |
'<a class="install-now" href="%s" title="%s">%s</a>', |
|
306 |
esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ), |
|
16 | 307 |
/* translators: %s: Theme version. */ |
9 | 308 |
esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ), |
309 |
__( 'Update' ) |
|
310 |
); |
|
0 | 311 |
break; |
312 |
case 'newer_installed': |
|
313 |
case 'latest_installed': |
|
9 | 314 |
$actions[] = sprintf( |
315 |
'<span class="install-now" title="%s">%s</span>', |
|
316 |
esc_attr__( 'This theme is already installed and is up to date' ), |
|
317 |
_x( 'Installed', 'theme' ) |
|
318 |
); |
|
0 | 319 |
break; |
5 | 320 |
case 'install': |
321 |
default: |
|
9 | 322 |
$actions[] = sprintf( |
323 |
'<a class="install-now" href="%s" title="%s">%s</a>', |
|
324 |
esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ), |
|
16 | 325 |
/* translators: %s: Theme name. */ |
326 |
esc_attr( sprintf( _x( 'Install %s', 'theme' ), $name ) ), |
|
9 | 327 |
__( 'Install Now' ) |
328 |
); |
|
5 | 329 |
break; |
0 | 330 |
} |
331 |
||
9 | 332 |
$actions[] = sprintf( |
333 |
'<a class="install-theme-preview" href="%s" title="%s">%s</a>', |
|
334 |
esc_url( $preview_url ), |
|
16 | 335 |
/* translators: %s: Theme name. */ |
9 | 336 |
esc_attr( sprintf( __( 'Preview %s' ), $name ) ), |
337 |
__( 'Preview' ) |
|
338 |
); |
|
0 | 339 |
|
5 | 340 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
* Filters the install action links for a theme in the Install Themes list table. |
5 | 342 |
* |
343 |
* @since 3.4.0 |
|
344 |
* |
|
9 | 345 |
* @param string[] $actions An array of theme action links. Defaults are |
5 | 346 |
* links to Install Now, Preview, and Details. |
347 |
* @param WP_Theme $theme Theme object. |
|
348 |
*/ |
|
0 | 349 |
$actions = apply_filters( 'theme_install_actions', $actions, $theme ); |
350 |
||
351 |
?> |
|
352 |
<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
|
353 |
<img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" /> |
0 | 354 |
</a> |
355 |
||
356 |
<h3><?php echo $name; ?></h3> |
|
9 | 357 |
<div class="theme-author"> |
358 |
<?php |
|
16 | 359 |
/* translators: %s: Theme author. */ |
9 | 360 |
printf( __( 'By %s' ), $author ); |
361 |
?> |
|
362 |
</div> |
|
0 | 363 |
|
364 |
<div class="action-links"> |
|
365 |
<ul> |
|
9 | 366 |
<?php foreach ( $actions as $action ) : ?> |
0 | 367 |
<li><?php echo $action; ?></li> |
368 |
<?php endforeach; ?> |
|
9 | 369 |
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e( 'Details' ); ?></a></li> |
0 | 370 |
</ul> |
371 |
</div> |
|
372 |
||
373 |
<?php |
|
374 |
$this->install_theme_info( $theme ); |
|
375 |
} |
|
376 |
||
5 | 377 |
/** |
0 | 378 |
* Prints the wrapper for the theme installer. |
379 |
*/ |
|
5 | 380 |
public function theme_installer() { |
0 | 381 |
?> |
382 |
<div id="theme-installer" class="wp-full-overlay expanded"> |
|
383 |
<div class="wp-full-overlay-sidebar"> |
|
384 |
<div class="wp-full-overlay-header"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
<a href="#" class="close-full-overlay button"><?php _e( 'Close' ); ?></a> |
5 | 386 |
<span class="theme-install"></span> |
0 | 387 |
</div> |
388 |
<div class="wp-full-overlay-sidebar-content"> |
|
389 |
<div class="install-theme-info"></div> |
|
390 |
</div> |
|
391 |
<div class="wp-full-overlay-footer"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
<button type="button" class="collapse-sidebar button" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>"> |
0 | 393 |
<span class="collapse-sidebar-arrow"></span> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
<span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
</button> |
0 | 396 |
</div> |
397 |
</div> |
|
398 |
<div class="wp-full-overlay-main"></div> |
|
399 |
</div> |
|
400 |
<?php |
|
401 |
} |
|
402 |
||
5 | 403 |
/** |
0 | 404 |
* Prints the wrapper for the theme installer with a provided theme's data. |
405 |
* Used to make the theme installer work for no-js. |
|
406 |
* |
|
407 |
* @param object $theme - A WordPress.org Theme API object. |
|
408 |
*/ |
|
5 | 409 |
public function theme_installer_single( $theme ) { |
0 | 410 |
?> |
411 |
<div id="theme-installer" class="wp-full-overlay single-theme"> |
|
412 |
<div class="wp-full-overlay-sidebar"> |
|
413 |
<?php $this->install_theme_info( $theme ); ?> |
|
414 |
</div> |
|
415 |
<div class="wp-full-overlay-main"> |
|
416 |
<iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe> |
|
417 |
</div> |
|
418 |
</div> |
|
419 |
<?php |
|
420 |
} |
|
421 |
||
5 | 422 |
/** |
0 | 423 |
* Prints the info for a theme (to be used in the theme installer modal). |
424 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
* @global array $themes_allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* |
0 | 427 |
* @param object $theme - A WordPress.org Theme API object. |
428 |
*/ |
|
5 | 429 |
public function install_theme_info( $theme ) { |
0 | 430 |
global $themes_allowedtags; |
431 |
||
9 | 432 |
if ( empty( $theme ) ) { |
0 | 433 |
return; |
9 | 434 |
} |
0 | 435 |
|
9 | 436 |
$name = wp_kses( $theme->name, $themes_allowedtags ); |
0 | 437 |
$author = wp_kses( $theme->author, $themes_allowedtags ); |
438 |
||
9 | 439 |
$install_url = add_query_arg( |
440 |
array( |
|
441 |
'action' => 'install-theme', |
|
442 |
'theme' => $theme->slug, |
|
443 |
), |
|
444 |
self_admin_url( 'update.php' ) |
|
445 |
); |
|
0 | 446 |
|
9 | 447 |
$update_url = add_query_arg( |
448 |
array( |
|
449 |
'action' => 'upgrade-theme', |
|
450 |
'theme' => $theme->slug, |
|
451 |
), |
|
452 |
self_admin_url( 'update.php' ) |
|
453 |
); |
|
0 | 454 |
|
455 |
$status = $this->_get_theme_status( $theme ); |
|
456 |
||
457 |
?> |
|
9 | 458 |
<div class="install-theme-info"> |
459 |
<?php |
|
460 |
switch ( $status ) { |
|
461 |
case 'update_available': |
|
462 |
printf( |
|
463 |
'<a class="theme-install button button-primary" href="%s" title="%s">%s</a>', |
|
464 |
esc_url( wp_nonce_url( $update_url, 'upgrade-theme_' . $theme->slug ) ), |
|
16 | 465 |
/* translators: %s: Theme version. */ |
9 | 466 |
esc_attr( sprintf( __( 'Update to version %s' ), $theme->version ) ), |
467 |
__( 'Update' ) |
|
468 |
); |
|
469 |
break; |
|
470 |
case 'newer_installed': |
|
471 |
case 'latest_installed': |
|
472 |
printf( |
|
473 |
'<span class="theme-install" title="%s">%s</span>', |
|
474 |
esc_attr__( 'This theme is already installed and is up to date' ), |
|
475 |
_x( 'Installed', 'theme' ) |
|
476 |
); |
|
477 |
break; |
|
478 |
case 'install': |
|
479 |
default: |
|
480 |
printf( |
|
481 |
'<a class="theme-install button button-primary" href="%s">%s</a>', |
|
482 |
esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ), |
|
483 |
__( 'Install' ) |
|
484 |
); |
|
485 |
break; |
|
486 |
} |
|
487 |
?> |
|
0 | 488 |
<h3 class="theme-name"><?php echo $name; ?></h3> |
9 | 489 |
<span class="theme-by"> |
490 |
<?php |
|
16 | 491 |
/* translators: %s: Theme author. */ |
9 | 492 |
printf( __( 'By %s' ), $author ); |
493 |
?> |
|
494 |
</span> |
|
495 |
<?php if ( isset( $theme->screenshot_url ) ) : ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" /> |
0 | 497 |
<?php endif; ?> |
498 |
<div class="theme-details"> |
|
9 | 499 |
<?php |
500 |
wp_star_rating( |
|
501 |
array( |
|
502 |
'rating' => $theme->rating, |
|
503 |
'type' => 'percent', |
|
504 |
'number' => $theme->num_ratings, |
|
505 |
) |
|
506 |
); |
|
507 |
?> |
|
0 | 508 |
<div class="theme-version"> |
9 | 509 |
<strong><?php _e( 'Version:' ); ?> </strong> |
0 | 510 |
<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?> |
511 |
</div> |
|
512 |
<div class="theme-description"> |
|
513 |
<?php echo wp_kses( $theme->description, $themes_allowedtags ); ?> |
|
514 |
</div> |
|
515 |
</div> |
|
516 |
<input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" /> |
|
517 |
</div> |
|
518 |
<?php |
|
519 |
} |
|
520 |
||
521 |
/** |
|
522 |
* Send required variables to JavaScript land |
|
523 |
* |
|
5 | 524 |
* @since 3.4.0 |
0 | 525 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
* @global string $tab Current tab within Themes->Install screen |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
527 |
* @global string $type Type of search. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
528 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
529 |
* @param array $extra_args Unused. |
0 | 530 |
*/ |
5 | 531 |
public function _js_vars( $extra_args = array() ) { |
0 | 532 |
global $tab, $type; |
533 |
parent::_js_vars( compact( 'tab', 'type' ) ); |
|
534 |
} |
|
535 |
||
536 |
/** |
|
537 |
* Check to see if the theme is already installed. |
|
538 |
* |
|
5 | 539 |
* @since 3.4.0 |
0 | 540 |
* |
541 |
* @param object $theme - A WordPress.org Theme API object. |
|
542 |
* @return string Theme status. |
|
543 |
*/ |
|
544 |
private function _get_theme_status( $theme ) { |
|
545 |
$status = 'install'; |
|
546 |
||
547 |
$installed_theme = wp_get_theme( $theme->slug ); |
|
548 |
if ( $installed_theme->exists() ) { |
|
9 | 549 |
if ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '=' ) ) { |
0 | 550 |
$status = 'latest_installed'; |
9 | 551 |
} elseif ( version_compare( $installed_theme->get( 'Version' ), $theme->version, '>' ) ) { |
0 | 552 |
$status = 'newer_installed'; |
9 | 553 |
} else { |
0 | 554 |
$status = 'update_available'; |
9 | 555 |
} |
0 | 556 |
} |
557 |
||
558 |
return $status; |
|
559 |
} |
|
560 |
} |