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