author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
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 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @return bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
*/ |
5 | 26 |
public function ajax_user_can() { |
0 | 27 |
return current_user_can( 'install_themes' ); |
28 |
} |
|
29 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* @global array $tabs |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* @global string $tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* @global int $paged |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* @global string $type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* @global array $theme_field_defaults |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
*/ |
5 | 38 |
public function prepare_items() { |
0 | 39 |
include( ABSPATH . 'wp-admin/includes/theme-install.php' ); |
40 |
||
41 |
global $tabs, $tab, $paged, $type, $theme_field_defaults; |
|
42 |
wp_reset_vars( array( 'tab' ) ); |
|
43 |
||
44 |
$search_terms = array(); |
|
45 |
$search_string = ''; |
|
46 |
if ( ! empty( $_REQUEST['s'] ) ){ |
|
47 |
$search_string = strtolower( wp_unslash( $_REQUEST['s'] ) ); |
|
48 |
$search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', $search_string ) ) ) ); |
|
49 |
} |
|
50 |
||
51 |
if ( ! empty( $_REQUEST['features'] ) ) |
|
52 |
$this->features = $_REQUEST['features']; |
|
53 |
||
54 |
$paged = $this->get_pagenum(); |
|
55 |
||
56 |
$per_page = 36; |
|
57 |
||
58 |
// These are the tabs which are shown on the page, |
|
59 |
$tabs = array(); |
|
60 |
$tabs['dashboard'] = __( 'Search' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
if ( 'search' === $tab ) |
0 | 62 |
$tabs['search'] = __( 'Search Results' ); |
63 |
$tabs['upload'] = __( 'Upload' ); |
|
5 | 64 |
$tabs['featured'] = _x( 'Featured', 'themes' ); |
65 |
//$tabs['popular'] = _x( 'Popular', 'themes' ); |
|
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 |
* |
|
79 |
* @param array $nonmenu_tabs The tabs that don't have a menu item on |
|
80 |
* the Install Themes screen. |
|
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. |
|
85 |
if ( empty( $tab ) || ( ! isset( $tabs[ $tab ] ) && ! in_array( $tab, (array) $nonmenu_tabs ) ) ) |
|
86 |
$tab = key( $tabs ); |
|
87 |
||
88 |
$args = array( 'page' => $paged, 'per_page' => $per_page, 'fields' => $theme_field_defaults ); |
|
89 |
||
90 |
switch ( $tab ) { |
|
91 |
case 'search': |
|
92 |
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term'; |
|
93 |
switch ( $type ) { |
|
94 |
case 'tag': |
|
95 |
$args['tag'] = array_map( 'sanitize_key', $search_terms ); |
|
96 |
break; |
|
97 |
case 'term': |
|
98 |
$args['search'] = $search_string; |
|
99 |
break; |
|
100 |
case 'author': |
|
101 |
$args['author'] = $search_string; |
|
102 |
break; |
|
103 |
} |
|
104 |
||
105 |
if ( ! empty( $this->features ) ) { |
|
106 |
$args['tag'] = $this->features; |
|
107 |
$_REQUEST['s'] = implode( ',', $this->features ); |
|
108 |
$_REQUEST['type'] = 'tag'; |
|
109 |
} |
|
110 |
||
111 |
add_action( 'install_themes_table_header', 'install_theme_search_form', 10, 0 ); |
|
112 |
break; |
|
113 |
||
114 |
case 'featured': |
|
5 | 115 |
// case 'popular': |
0 | 116 |
case 'new': |
117 |
case 'updated': |
|
118 |
$args['browse'] = $tab; |
|
119 |
break; |
|
120 |
||
121 |
default: |
|
122 |
$args = false; |
|
123 |
break; |
|
124 |
} |
|
125 |
||
5 | 126 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* Filters API request arguments for each Install Themes screen tab. |
5 | 128 |
* |
129 |
* The dynamic portion of the hook name, `$tab`, refers to the theme install |
|
130 |
* tabs. Default tabs are 'dashboard', 'search', 'upload', 'featured', |
|
131 |
* 'new', and 'updated'. |
|
132 |
* |
|
133 |
* @since 3.7.0 |
|
134 |
* |
|
135 |
* @param array $args An array of themes API arguments. |
|
136 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
$args = apply_filters( "install_themes_table_api_args_{$tab}", $args ); |
0 | 138 |
|
139 |
if ( ! $args ) |
|
140 |
return; |
|
141 |
||
142 |
$api = themes_api( 'query_themes', $args ); |
|
143 |
||
144 |
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>' ); |
|
146 |
||
147 |
$this->items = $api->themes; |
|
148 |
||
149 |
$this->set_pagination_args( array( |
|
150 |
'total_items' => $api->info['results'], |
|
5 | 151 |
'per_page' => $args['per_page'], |
0 | 152 |
'infinite_scroll' => true, |
153 |
) ); |
|
154 |
} |
|
155 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
*/ |
5 | 158 |
public function no_items() { |
0 | 159 |
_e( 'No themes match your request.' ); |
160 |
} |
|
161 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
* @global array $tabs |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* @global string $tab |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
*/ |
5 | 168 |
protected function get_views() { |
0 | 169 |
global $tabs, $tab; |
170 |
||
171 |
$display_tabs = array(); |
|
172 |
foreach ( (array) $tabs as $action => $text ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
$current_link_attributes = ( $action === $tab ) ? ' class="current" aria-current="page"' : ''; |
0 | 174 |
$href = self_admin_url('theme-install.php?tab=' . $action); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
$display_tabs['theme-install-'.$action] = "<a href='$href'$current_link_attributes>$text</a>"; |
0 | 176 |
} |
177 |
||
178 |
return $display_tabs; |
|
179 |
} |
|
180 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
*/ |
5 | 183 |
public function display() { |
0 | 184 |
wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' ); |
185 |
?> |
|
186 |
<div class="tablenav top themes"> |
|
187 |
<div class="alignleft actions"> |
|
5 | 188 |
<?php |
189 |
/** |
|
190 |
* Fires in the Install Themes list table header. |
|
191 |
* |
|
192 |
* @since 2.8.0 |
|
193 |
*/ |
|
194 |
do_action( 'install_themes_table_header' ); |
|
195 |
?> |
|
0 | 196 |
</div> |
197 |
<?php $this->pagination( 'top' ); ?> |
|
198 |
<br class="clear" /> |
|
199 |
</div> |
|
200 |
||
201 |
<div id="availablethemes"> |
|
202 |
<?php $this->display_rows_or_placeholder(); ?> |
|
203 |
</div> |
|
204 |
||
205 |
<?php |
|
5 | 206 |
$this->tablenav( 'bottom' ); |
0 | 207 |
} |
208 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
*/ |
5 | 211 |
public function display_rows() { |
0 | 212 |
$themes = $this->items; |
213 |
foreach ( $themes as $theme ) { |
|
214 |
?> |
|
215 |
<div class="available-theme installable-theme"><?php |
|
216 |
$this->single_row( $theme ); |
|
217 |
?></div> |
|
218 |
<?php } // end foreach $theme_names |
|
219 |
||
220 |
$this->theme_installer(); |
|
221 |
} |
|
222 |
||
5 | 223 |
/** |
0 | 224 |
* Prints a theme from the WordPress.org API. |
225 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
* @since 3.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
* @global array $themes_allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
* @param object $theme { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
* An object that contains theme data returned by the WordPress.org API. |
0 | 232 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
* @type string $name Theme name, e.g. 'Twenty Seventeen'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
* @type string $slug Theme slug, e.g. 'twentyseventeen'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
* @type string $version Theme version, e.g. '1.1'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
* @type string $author Theme author username, e.g. 'melchoyce'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* @type string $preview_url Preview URL, e.g. 'http://2017.wordpress.net/'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* @type string $screenshot_url Screenshot URL, e.g. 'https://wordpress.org/themes/twentyseventeen/'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* @type float $rating Rating score. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* @type int $num_ratings The number of ratings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* @type string $homepage Theme homepage, e.g. 'https://wordpress.org/themes/twentyseventeen/'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* @type string $description Theme description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* @type string $download_link Theme ZIP download URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* } |
0 | 245 |
*/ |
5 | 246 |
public function single_row( $theme ) { |
0 | 247 |
global $themes_allowedtags; |
248 |
||
249 |
if ( empty( $theme ) ) |
|
250 |
return; |
|
251 |
||
252 |
$name = wp_kses( $theme->name, $themes_allowedtags ); |
|
253 |
$author = wp_kses( $theme->author, $themes_allowedtags ); |
|
254 |
||
255 |
$preview_title = sprintf( __('Preview “%s”'), $name ); |
|
256 |
$preview_url = add_query_arg( array( |
|
257 |
'tab' => 'theme-information', |
|
258 |
'theme' => $theme->slug, |
|
5 | 259 |
), self_admin_url( 'theme-install.php' ) ); |
0 | 260 |
|
261 |
$actions = array(); |
|
262 |
||
263 |
$install_url = add_query_arg( array( |
|
264 |
'action' => 'install-theme', |
|
265 |
'theme' => $theme->slug, |
|
266 |
), self_admin_url( 'update.php' ) ); |
|
267 |
||
268 |
$update_url = add_query_arg( array( |
|
269 |
'action' => 'upgrade-theme', |
|
270 |
'theme' => $theme->slug, |
|
271 |
), self_admin_url( 'update.php' ) ); |
|
272 |
||
273 |
$status = $this->_get_theme_status( $theme ); |
|
274 |
||
275 |
switch ( $status ) { |
|
276 |
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>'; |
|
278 |
break; |
|
279 |
case 'newer_installed': |
|
280 |
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>'; |
|
282 |
break; |
|
5 | 283 |
case 'install': |
284 |
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>'; |
|
286 |
break; |
|
0 | 287 |
} |
288 |
||
289 |
$actions[] = '<a class="install-theme-preview" href="' . esc_url( $preview_url ) . '" title="' . esc_attr( sprintf( __( 'Preview %s' ), $name ) ) . '">' . __( 'Preview' ) . '</a>'; |
|
290 |
||
5 | 291 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
* Filters the install action links for a theme in the Install Themes list table. |
5 | 293 |
* |
294 |
* @since 3.4.0 |
|
295 |
* |
|
296 |
* @param array $actions An array of theme action hyperlinks. Defaults are |
|
297 |
* links to Install Now, Preview, and Details. |
|
298 |
* @param WP_Theme $theme Theme object. |
|
299 |
*/ |
|
0 | 300 |
$actions = apply_filters( 'theme_install_actions', $actions, $theme ); |
301 |
||
302 |
?> |
|
303 |
<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
|
304 |
<img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" /> |
0 | 305 |
</a> |
306 |
||
307 |
<h3><?php echo $name; ?></h3> |
|
308 |
<div class="theme-author"><?php printf( __( 'By %s' ), $author ); ?></div> |
|
309 |
||
310 |
<div class="action-links"> |
|
311 |
<ul> |
|
312 |
<?php foreach ( $actions as $action ): ?> |
|
313 |
<li><?php echo $action; ?></li> |
|
314 |
<?php endforeach; ?> |
|
315 |
<li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li> |
|
316 |
</ul> |
|
317 |
</div> |
|
318 |
||
319 |
<?php |
|
320 |
$this->install_theme_info( $theme ); |
|
321 |
} |
|
322 |
||
5 | 323 |
/** |
0 | 324 |
* Prints the wrapper for the theme installer. |
325 |
*/ |
|
5 | 326 |
public function theme_installer() { |
0 | 327 |
?> |
328 |
<div id="theme-installer" class="wp-full-overlay expanded"> |
|
329 |
<div class="wp-full-overlay-sidebar"> |
|
330 |
<div class="wp-full-overlay-header"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
331 |
<a href="#" class="close-full-overlay button"><?php _e( 'Close' ); ?></a> |
5 | 332 |
<span class="theme-install"></span> |
0 | 333 |
</div> |
334 |
<div class="wp-full-overlay-sidebar-content"> |
|
335 |
<div class="install-theme-info"></div> |
|
336 |
</div> |
|
337 |
<div class="wp-full-overlay-footer"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
<button type="button" class="collapse-sidebar button" aria-expanded="true" aria-label="<?php esc_attr_e( 'Collapse Sidebar' ); ?>"> |
0 | 339 |
<span class="collapse-sidebar-arrow"></span> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
<span class="collapse-sidebar-label"><?php _e( 'Collapse' ); ?></span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
</button> |
0 | 342 |
</div> |
343 |
</div> |
|
344 |
<div class="wp-full-overlay-main"></div> |
|
345 |
</div> |
|
346 |
<?php |
|
347 |
} |
|
348 |
||
5 | 349 |
/** |
0 | 350 |
* Prints the wrapper for the theme installer with a provided theme's data. |
351 |
* Used to make the theme installer work for no-js. |
|
352 |
* |
|
353 |
* @param object $theme - A WordPress.org Theme API object. |
|
354 |
*/ |
|
5 | 355 |
public function theme_installer_single( $theme ) { |
0 | 356 |
?> |
357 |
<div id="theme-installer" class="wp-full-overlay single-theme"> |
|
358 |
<div class="wp-full-overlay-sidebar"> |
|
359 |
<?php $this->install_theme_info( $theme ); ?> |
|
360 |
</div> |
|
361 |
<div class="wp-full-overlay-main"> |
|
362 |
<iframe src="<?php echo esc_url( $theme->preview_url ); ?>"></iframe> |
|
363 |
</div> |
|
364 |
</div> |
|
365 |
<?php |
|
366 |
} |
|
367 |
||
5 | 368 |
/** |
0 | 369 |
* Prints the info for a theme (to be used in the theme installer modal). |
370 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
371 |
* @global array $themes_allowedtags |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
* |
0 | 373 |
* @param object $theme - A WordPress.org Theme API object. |
374 |
*/ |
|
5 | 375 |
public function install_theme_info( $theme ) { |
0 | 376 |
global $themes_allowedtags; |
377 |
||
378 |
if ( empty( $theme ) ) |
|
379 |
return; |
|
380 |
||
381 |
$name = wp_kses( $theme->name, $themes_allowedtags ); |
|
382 |
$author = wp_kses( $theme->author, $themes_allowedtags ); |
|
383 |
||
384 |
$install_url = add_query_arg( array( |
|
385 |
'action' => 'install-theme', |
|
386 |
'theme' => $theme->slug, |
|
387 |
), self_admin_url( 'update.php' ) ); |
|
388 |
||
389 |
$update_url = add_query_arg( array( |
|
390 |
'action' => 'upgrade-theme', |
|
391 |
'theme' => $theme->slug, |
|
392 |
), self_admin_url( 'update.php' ) ); |
|
393 |
||
394 |
$status = $this->_get_theme_status( $theme ); |
|
395 |
||
396 |
?> |
|
397 |
<div class="install-theme-info"><?php |
|
398 |
switch ( $status ) { |
|
399 |
case 'update_available': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
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>'; |
0 | 401 |
break; |
402 |
case 'newer_installed': |
|
403 |
case 'latest_installed': |
|
404 |
echo '<span class="theme-install" title="' . esc_attr__( 'This theme is already installed and is up to date' ) . '">' . _x( 'Installed', 'theme' ) . '</span>'; |
|
405 |
break; |
|
5 | 406 |
case 'install': |
407 |
default: |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
echo '<a class="theme-install button button-primary" href="' . esc_url( wp_nonce_url( $install_url, 'install-theme_' . $theme->slug ) ) . '">' . __( 'Install' ) . '</a>'; |
5 | 409 |
break; |
0 | 410 |
} ?> |
411 |
<h3 class="theme-name"><?php echo $name; ?></h3> |
|
412 |
<span class="theme-by"><?php printf( __( 'By %s' ), $author ); ?></span> |
|
413 |
<?php if ( isset( $theme->screenshot_url ) ): ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" /> |
0 | 415 |
<?php endif; ?> |
416 |
<div class="theme-details"> |
|
5 | 417 |
<?php wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings ) ); ?> |
0 | 418 |
<div class="theme-version"> |
419 |
<strong><?php _e('Version:') ?> </strong> |
|
420 |
<?php echo wp_kses( $theme->version, $themes_allowedtags ); ?> |
|
421 |
</div> |
|
422 |
<div class="theme-description"> |
|
423 |
<?php echo wp_kses( $theme->description, $themes_allowedtags ); ?> |
|
424 |
</div> |
|
425 |
</div> |
|
426 |
<input class="theme-preview-url" type="hidden" value="<?php echo esc_url( $theme->preview_url ); ?>" /> |
|
427 |
</div> |
|
428 |
<?php |
|
429 |
} |
|
430 |
||
431 |
/** |
|
432 |
* Send required variables to JavaScript land |
|
433 |
* |
|
5 | 434 |
* @since 3.4.0 |
0 | 435 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
* @global string $tab Current tab within Themes->Install screen |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* @global string $type Type of search. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
* @param array $extra_args Unused. |
0 | 440 |
*/ |
5 | 441 |
public function _js_vars( $extra_args = array() ) { |
0 | 442 |
global $tab, $type; |
443 |
parent::_js_vars( compact( 'tab', 'type' ) ); |
|
444 |
} |
|
445 |
||
446 |
/** |
|
447 |
* Check to see if the theme is already installed. |
|
448 |
* |
|
5 | 449 |
* @since 3.4.0 |
0 | 450 |
* |
451 |
* @param object $theme - A WordPress.org Theme API object. |
|
452 |
* @return string Theme status. |
|
453 |
*/ |
|
454 |
private function _get_theme_status( $theme ) { |
|
455 |
$status = 'install'; |
|
456 |
||
457 |
$installed_theme = wp_get_theme( $theme->slug ); |
|
458 |
if ( $installed_theme->exists() ) { |
|
459 |
if ( version_compare( $installed_theme->get('Version'), $theme->version, '=' ) ) |
|
460 |
$status = 'latest_installed'; |
|
461 |
elseif ( version_compare( $installed_theme->get('Version'), $theme->version, '>' ) ) |
|
462 |
$status = 'newer_installed'; |
|
463 |
else |
|
464 |
$status = 'update_available'; |
|
465 |
} |
|
466 |
||
467 |
return $status; |
|
468 |
} |
|
469 |
} |