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 |
/** |
|
3 |
* WordPress Theme Administration API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Remove a theme |
|
11 |
* |
|
12 |
* @since 2.8.0 |
|
13 |
* |
|
9 | 14 |
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* |
9 | 16 |
* @param string $stylesheet Stylesheet of the theme to delete. |
17 |
* @param string $redirect Redirect to page when complete. |
|
18 |
* @return bool|null|WP_Error True on success, false if `$stylesheet` is empty, WP_Error on failure. |
|
19 |
* Null if filesystem credentials are required to proceed. |
|
0 | 20 |
*/ |
9 | 21 |
function delete_theme( $stylesheet, $redirect = '' ) { |
0 | 22 |
global $wp_filesystem; |
23 |
||
9 | 24 |
if ( empty( $stylesheet ) ) { |
0 | 25 |
return false; |
9 | 26 |
} |
0 | 27 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
if ( empty( $redirect ) ) { |
9 | 29 |
$redirect = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ); |
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 |
ob_start(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
$credentials = request_filesystem_credentials( $redirect ); |
9 | 34 |
$data = ob_get_clean(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
if ( false === $credentials ) { |
9 | 37 |
if ( ! empty( $data ) ) { |
16 | 38 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
0 | 39 |
echo $data; |
16 | 40 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |
0 | 41 |
exit; |
42 |
} |
|
43 |
return; |
|
44 |
} |
|
45 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
if ( ! WP_Filesystem( $credentials ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
ob_start(); |
16 | 48 |
// Failed to connect. Error and request again. |
49 |
request_filesystem_credentials( $redirect, '', true ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
$data = ob_get_clean(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
|
9 | 52 |
if ( ! empty( $data ) ) { |
16 | 53 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
0 | 54 |
echo $data; |
16 | 55 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |
0 | 56 |
exit; |
57 |
} |
|
58 |
return; |
|
59 |
} |
|
60 |
||
9 | 61 |
if ( ! is_object( $wp_filesystem ) ) { |
62 |
return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); |
|
63 |
} |
|
0 | 64 |
|
9 | 65 |
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
66 |
return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); |
|
67 |
} |
|
0 | 68 |
|
5 | 69 |
// Get the base plugin folder. |
0 | 70 |
$themes_dir = $wp_filesystem->wp_themes_dir(); |
5 | 71 |
if ( empty( $themes_dir ) ) { |
72 |
return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) ); |
|
73 |
} |
|
0 | 74 |
|
75 |
$themes_dir = trailingslashit( $themes_dir ); |
|
9 | 76 |
$theme_dir = trailingslashit( $themes_dir . $stylesheet ); |
77 |
$deleted = $wp_filesystem->delete( $theme_dir, true ); |
|
5 | 78 |
|
79 |
if ( ! $deleted ) { |
|
16 | 80 |
return new WP_Error( |
81 |
'could_not_remove_theme', |
|
82 |
/* translators: %s: Theme name. */ |
|
83 |
sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) |
|
84 |
); |
|
5 | 85 |
} |
86 |
||
87 |
$theme_translations = wp_get_installed_translations( 'themes' ); |
|
0 | 88 |
|
5 | 89 |
// Remove language files, silently. |
90 |
if ( ! empty( $theme_translations[ $stylesheet ] ) ) { |
|
91 |
$translations = $theme_translations[ $stylesheet ]; |
|
0 | 92 |
|
5 | 93 |
foreach ( $translations as $translation => $data ) { |
94 |
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' ); |
|
95 |
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' ); |
|
9 | 96 |
|
97 |
$json_translation_files = glob( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json' ); |
|
98 |
if ( $json_translation_files ) { |
|
99 |
array_map( array( $wp_filesystem, 'delete' ), $json_translation_files ); |
|
100 |
} |
|
5 | 101 |
} |
102 |
} |
|
103 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
// Remove the theme from allowed themes on the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
if ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
WP_Theme::network_disable_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
|
5 | 109 |
// Force refresh of theme update information. |
110 |
delete_site_transient( 'update_themes' ); |
|
0 | 111 |
|
112 |
return true; |
|
113 |
} |
|
114 |
||
115 |
/** |
|
16 | 116 |
* Gets the page templates available in this theme. |
0 | 117 |
* |
118 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
119 |
* @since 4.7.0 Added the `$post_type` parameter. |
0 | 120 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* @param WP_Post|null $post Optional. The post being edited, provided for context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
* @param string $post_type Optional. Post type to get the templates for. Default 'page'. |
16 | 123 |
* @return string[] Array of template file names keyed by the template header name. |
0 | 124 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
function get_page_templates( $post = null, $post_type = 'page' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) ); |
0 | 127 |
} |
128 |
||
129 |
/** |
|
130 |
* Tidies a filename for url display by the theme editor. |
|
131 |
* |
|
132 |
* @since 2.9.0 |
|
133 |
* @access private |
|
134 |
* |
|
135 |
* @param string $fullpath Full path to the theme file |
|
136 |
* @param string $containingfolder Path of the theme parent folder |
|
137 |
* @return string |
|
138 |
*/ |
|
9 | 139 |
function _get_template_edit_filename( $fullpath, $containingfolder ) { |
140 |
return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath ); |
|
0 | 141 |
} |
142 |
||
143 |
/** |
|
144 |
* Check if there is an update for a theme available. |
|
145 |
* |
|
146 |
* Will display link, if there is an update available. |
|
147 |
* |
|
148 |
* @since 2.7.0 |
|
16 | 149 |
* |
5 | 150 |
* @see get_theme_update_available() |
0 | 151 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
* @param WP_Theme $theme Theme data object. |
0 | 153 |
*/ |
154 |
function theme_update_available( $theme ) { |
|
5 | 155 |
echo get_theme_update_available( $theme ); |
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* Retrieve the update link if there is a theme update available. |
|
160 |
* |
|
161 |
* Will return a link if there is an update available. |
|
162 |
* |
|
163 |
* @since 3.8.0 |
|
164 |
* |
|
165 |
* @param WP_Theme $theme WP_Theme object. |
|
16 | 166 |
* @return string|false HTML for the update link, or false if invalid info was passed. |
5 | 167 |
*/ |
168 |
function get_theme_update_available( $theme ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
static $themes_update = null; |
0 | 170 |
|
9 | 171 |
if ( ! current_user_can( 'update_themes' ) ) { |
5 | 172 |
return false; |
9 | 173 |
} |
0 | 174 |
|
9 | 175 |
if ( ! isset( $themes_update ) ) { |
176 |
$themes_update = get_site_transient( 'update_themes' ); |
|
177 |
} |
|
0 | 178 |
|
5 | 179 |
if ( ! ( $theme instanceof WP_Theme ) ) { |
180 |
return false; |
|
181 |
} |
|
0 | 182 |
|
183 |
$stylesheet = $theme->get_stylesheet(); |
|
184 |
||
5 | 185 |
$html = ''; |
186 |
||
9 | 187 |
if ( isset( $themes_update->response[ $stylesheet ] ) ) { |
188 |
$update = $themes_update->response[ $stylesheet ]; |
|
189 |
$theme_name = $theme->display( 'Name' ); |
|
190 |
$details_url = add_query_arg( |
|
191 |
array( |
|
192 |
'TB_iframe' => 'true', |
|
193 |
'width' => 1024, |
|
194 |
'height' => 800, |
|
195 |
), |
|
196 |
$update['url'] |
|
16 | 197 |
); // Theme browser inside WP? Replace this. Also, theme preview JS will override this on the available list. |
9 | 198 |
$update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet ); |
0 | 199 |
|
9 | 200 |
if ( ! is_multisite() ) { |
201 |
if ( ! current_user_can( 'update_themes' ) ) { |
|
202 |
$html = sprintf( |
|
16 | 203 |
/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */ |
9 | 204 |
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ) . '</strong></p>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
$theme_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
esc_url( $details_url ), |
9 | 207 |
sprintf( |
208 |
'class="thickbox open-plugin-details-modal" aria-label="%s"', |
|
16 | 209 |
/* translators: 1: Theme name, 2: Version number. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
$update['new_version'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
); |
5 | 214 |
} elseif ( empty( $update['package'] ) ) { |
9 | 215 |
$html = sprintf( |
16 | 216 |
/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */ |
9 | 217 |
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
$theme_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
esc_url( $details_url ), |
9 | 220 |
sprintf( |
221 |
'class="thickbox open-plugin-details-modal" aria-label="%s"', |
|
16 | 222 |
/* translators: 1: Theme name, 2: Version number. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
$update['new_version'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
); |
5 | 227 |
} else { |
9 | 228 |
$html = sprintf( |
16 | 229 |
/* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */ |
9 | 230 |
'<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ) . '</strong></p>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
$theme_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
esc_url( $details_url ), |
9 | 233 |
sprintf( |
234 |
'class="thickbox open-plugin-details-modal" aria-label="%s"', |
|
16 | 235 |
/* translators: 1: Theme name, 2: Version number. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
$update['new_version'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
$update_url, |
9 | 240 |
sprintf( |
241 |
'aria-label="%s" id="update-theme" data-slug="%s"', |
|
16 | 242 |
/* translators: %s: Theme name. */ |
243 |
esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme_name ) ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
$stylesheet |
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 |
); |
5 | 247 |
} |
0 | 248 |
} |
249 |
} |
|
5 | 250 |
|
251 |
return $html; |
|
0 | 252 |
} |
253 |
||
254 |
/** |
|
9 | 255 |
* Retrieve list of WordPress theme features (aka theme tags). |
0 | 256 |
* |
257 |
* @since 3.1.0 |
|
16 | 258 |
* @since 3.2.0 Added 'Gray' color and 'Featured Image Header', 'Featured Images', |
259 |
* 'Full Width Template', and 'Post Formats' features. |
|
260 |
* @since 3.5.0 Added 'Flexible Header' feature. |
|
261 |
* @since 3.8.0 Renamed 'Width' filter to 'Layout'. |
|
262 |
* @since 3.8.0 Renamed 'Fixed Width' and 'Flexible Width' options |
|
263 |
* to 'Fixed Layout' and 'Fluid Layout'. |
|
264 |
* @since 3.8.0 Added 'Accessibility Ready' feature and 'Responsive Layout' option. |
|
265 |
* @since 3.9.0 Combined 'Layout' and 'Columns' filters. |
|
266 |
* @since 4.6.0 Removed 'Colors' filter. |
|
267 |
* @since 4.6.0 Added 'Grid Layout' option. |
|
268 |
* Removed 'Fixed Layout', 'Fluid Layout', and 'Responsive Layout' options. |
|
269 |
* @since 4.6.0 Added 'Custom Logo' and 'Footer Widgets' features. |
|
270 |
* Removed 'Blavatar' feature. |
|
271 |
* @since 4.6.0 Added 'Blog', 'E-Commerce', 'Education', 'Entertainment', 'Food & Drink', |
|
272 |
* 'Holiday', 'News', 'Photography', and 'Portfolio' subjects. |
|
273 |
* Removed 'Photoblogging' and 'Seasonal' subjects. |
|
274 |
* @since 4.9.0 Reordered the filters from 'Layout', 'Features', 'Subject' |
|
275 |
* to 'Subject', 'Features', 'Layout'. |
|
276 |
* @since 4.9.0 Removed 'BuddyPress', 'Custom Menu', 'Flexible Header', |
|
277 |
* 'Front Page Posting', 'Microformats', 'RTL Language Support', |
|
278 |
* 'Threaded Comments', and 'Translation Ready' features. |
|
279 |
* @since 5.5.0 Added 'Block Editor Patterns', 'Block Editor Styles', |
|
280 |
* and 'Full Site Editing' features. |
|
281 |
* @since 5.5.0 Added 'Wide Blocks' layout option. |
|
0 | 282 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
* @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true. |
0 | 284 |
* @return array Array of features keyed by category with translations keyed by slug. |
285 |
*/ |
|
286 |
function get_theme_feature_list( $api = true ) { |
|
16 | 287 |
// Hard-coded list is used if API is not accessible. |
0 | 288 |
$features = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
__( 'Subject' ) => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
'blog' => __( 'Blog' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
'e-commerce' => __( 'E-Commerce' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
'education' => __( 'Education' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
'entertainment' => __( 'Entertainment' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
'food-and-drink' => __( 'Food & Drink' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
'holiday' => __( 'Holiday' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
'news' => __( 'News' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
'photography' => __( 'Photography' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
'portfolio' => __( 'Portfolio' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
__( 'Features' ) => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
'accessibility-ready' => __( 'Accessibility Ready' ), |
16 | 304 |
'block-patterns' => __( 'Block Editor Patterns' ), |
305 |
'block-styles' => __( 'Block Editor Styles' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
'custom-background' => __( 'Custom Background' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
'custom-colors' => __( 'Custom Colors' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
308 |
'custom-header' => __( 'Custom Header' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
'custom-logo' => __( 'Custom Logo' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
'editor-style' => __( 'Editor Style' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
'featured-image-header' => __( 'Featured Image Header' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
'featured-images' => __( 'Featured Images' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
'footer-widgets' => __( 'Footer Widgets' ), |
16 | 314 |
'full-site-editing' => __( 'Full Site Editing' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
'full-width-template' => __( 'Full Width Template' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
'post-formats' => __( 'Post Formats' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
'sticky-post' => __( 'Sticky Post' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
'theme-options' => __( 'Theme Options' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
319 |
), |
0 | 320 |
|
9 | 321 |
__( 'Layout' ) => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
322 |
'grid-layout' => __( 'Grid Layout' ), |
0 | 323 |
'one-column' => __( 'One Column' ), |
324 |
'two-columns' => __( 'Two Columns' ), |
|
325 |
'three-columns' => __( 'Three Columns' ), |
|
326 |
'four-columns' => __( 'Four Columns' ), |
|
327 |
'left-sidebar' => __( 'Left Sidebar' ), |
|
328 |
'right-sidebar' => __( 'Right Sidebar' ), |
|
16 | 329 |
'wide-blocks' => __( 'Wide Blocks' ), |
9 | 330 |
), |
0 | 331 |
|
332 |
); |
|
333 |
||
9 | 334 |
if ( ! $api || ! current_user_can( 'install_themes' ) ) { |
0 | 335 |
return $features; |
9 | 336 |
} |
0 | 337 |
|
16 | 338 |
$feature_list = get_site_transient( 'wporg_theme_feature_list' ); |
339 |
if ( ! $feature_list ) { |
|
5 | 340 |
set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS ); |
0 | 341 |
} |
342 |
||
9 | 343 |
if ( ! $feature_list ) { |
344 |
$feature_list = themes_api( 'feature_list', array() ); |
|
345 |
if ( is_wp_error( $feature_list ) ) { |
|
346 |
return $features; |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
if ( ! $feature_list ) { |
|
0 | 351 |
return $features; |
9 | 352 |
} |
0 | 353 |
|
5 | 354 |
set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS ); |
0 | 355 |
|
5 | 356 |
$category_translations = array( |
357 |
'Layout' => __( 'Layout' ), |
|
358 |
'Features' => __( 'Features' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
'Subject' => __( 'Subject' ), |
5 | 360 |
); |
0 | 361 |
|
362 |
$wporg_features = array(); |
|
16 | 363 |
|
364 |
// Loop over the wp.org canonical list and apply translations. |
|
0 | 365 |
foreach ( (array) $feature_list as $feature_category => $feature_items ) { |
9 | 366 |
if ( isset( $category_translations[ $feature_category ] ) ) { |
367 |
$feature_category = $category_translations[ $feature_category ]; |
|
368 |
} |
|
16 | 369 |
|
9 | 370 |
$wporg_features[ $feature_category ] = array(); |
0 | 371 |
|
372 |
foreach ( $feature_items as $feature ) { |
|
9 | 373 |
if ( isset( $features[ $feature_category ][ $feature ] ) ) { |
374 |
$wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ]; |
|
375 |
} else { |
|
376 |
$wporg_features[ $feature_category ][ $feature ] = $feature; |
|
377 |
} |
|
0 | 378 |
} |
379 |
} |
|
380 |
||
381 |
return $wporg_features; |
|
382 |
} |
|
383 |
||
384 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* Retrieves theme installer pages from the WordPress.org Themes API. |
0 | 386 |
* |
387 |
* It is possible for a theme to override the Themes API result with three |
|
388 |
* filters. Assume this is for themes, which can extend on the Theme Info to |
|
389 |
* offer more choices. This is very powerful and must be used with care, when |
|
5 | 390 |
* overriding the filters. |
0 | 391 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* The first filter, {@see 'themes_api_args'}, is for the args and gives the action |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
* as the second parameter. The hook for {@see 'themes_api_args'} must ensure that |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* an object is returned. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* The second filter, {@see 'themes_api'}, allows a plugin to override the WordPress.org |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* Theme API entirely. If `$action` is 'query_themes', 'theme_information', or 'feature_list', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
* an object MUST be passed. If `$action` is 'hot_tags', an array should be passed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
* Finally, the third filter, {@see 'themes_api_result'}, makes it possible to filter the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
* response object or array, depending on the `$action` type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
403 |
* Supported arguments per action: |
0 | 404 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
405 |
* | Argument Name | 'query_themes' | 'theme_information' | 'hot_tags' | 'feature_list' | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
* | -------------------| :------------: | :-----------------: | :--------: | :--------------: | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
* | `$slug` | No | Yes | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* | `$per_page` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* | `$page` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
* | `$number` | No | No | Yes | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* | `$search` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
* | `$tag` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
* | `$author` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
* | `$user` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
* | `$browse` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
* | `$locale` | Yes | Yes | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
* | `$fields` | Yes | Yes | No | No | |
0 | 418 |
* |
419 |
* @since 2.8.0 |
|
420 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
421 |
* @param string $action API action to perform: 'query_themes', 'theme_information', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
* 'hot_tags' or 'feature_list'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
423 |
* @param array|object $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
* Optional. Array or object of arguments to serialize for the Themes API. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* @type string $slug The theme slug. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @type int $per_page Number of themes per page. Default 24. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* @type int $page Number of current page. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
* @type int $number Number of tags to be queried. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
* @type string $search A search term. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
* @type string $tag Tag to filter themes. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
* @type string $author Username of an author to filter themes. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
* @type string $user Username to query for their favorites. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
* @type string $browse Browse view: 'featured', 'popular', 'updated', 'favorites'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
* @type string $locale Locale to provide context-sensitive results. Default is the value of get_locale(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
* @type array $fields { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* Array of fields which should or should not be returned. |
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 |
* @type bool $description Whether to return the theme full description. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
* @type bool $sections Whether to return the theme readme sections: description, installation, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
* FAQ, screenshots, other notes, and changelog. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
442 |
* @type bool $rating Whether to return the rating in percent and total number of ratings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
* @type bool $ratings Whether to return the number of rating for each star (1-5). Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* @type bool $downloaded Whether to return the download count. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
* @type bool $downloadlink Whether to return the download link for the package. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
* @type bool $last_updated Whether to return the date of the last update. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* @type bool $tags Whether to return the assigned tags. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* @type bool $homepage Whether to return the theme homepage link. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* @type bool $screenshots Whether to return the screenshots. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
* @type int $screenshot_count Number of screenshots to return. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* @type bool $screenshot_url Whether to return the URL of the first screenshot. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* @type bool $photon_screenshots Whether to return the screenshots via Photon. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* @type bool $template Whether to return the slug of the parent theme. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* @type bool $parent Whether to return the slug, name and homepage of the parent theme. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* @type bool $versions Whether to return the list of all available versions. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
* @type bool $theme_url Whether to return theme's URL. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
458 |
* @type bool $extended_author Whether to return nicename or nicename and display name. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
461 |
* @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
462 |
* {@link https://developer.wordpress.org/reference/functions/themes_api/ function reference article} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
* for more information on the make-up of possible return objects depending on the value of `$action`. |
0 | 464 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
function themes_api( $action, $args = array() ) { |
16 | 466 |
// Include an unmodified $wp_version. |
467 |
require ABSPATH . WPINC . '/version.php'; |
|
5 | 468 |
|
469 |
if ( is_array( $args ) ) { |
|
470 |
$args = (object) $args; |
|
471 |
} |
|
0 | 472 |
|
16 | 473 |
if ( 'query_themes' === $action ) { |
9 | 474 |
if ( ! isset( $args->per_page ) ) { |
475 |
$args->per_page = 24; |
|
476 |
} |
|
5 | 477 |
} |
478 |
||
479 |
if ( ! isset( $args->locale ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
$args->locale = get_user_locale(); |
5 | 481 |
} |
0 | 482 |
|
9 | 483 |
if ( ! isset( $args->wp_version ) ) { |
16 | 484 |
$args->wp_version = substr( $wp_version, 0, 3 ); // x.y |
9 | 485 |
} |
486 |
||
5 | 487 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
* Filters arguments used to query for installer pages from the WordPress.org Themes API. |
5 | 489 |
* |
490 |
* Important: An object MUST be returned to this filter. |
|
491 |
* |
|
492 |
* @since 2.8.0 |
|
493 |
* |
|
494 |
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. |
|
495 |
* @param string $action Requested action. Likely values are 'theme_information', |
|
496 |
* 'feature_list', or 'query_themes'. |
|
497 |
*/ |
|
498 |
$args = apply_filters( 'themes_api_args', $args, $action ); |
|
0 | 499 |
|
5 | 500 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* Filters whether to override the WordPress.org Themes API. |
5 | 502 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
* Passing a non-false value will effectively short-circuit the WordPress.org API request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
* If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
* be passed. If `$action` is 'hot_tags', an array should be passed. |
5 | 507 |
* |
508 |
* @since 2.8.0 |
|
509 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
* @param false|object|array $override Whether to override the WordPress.org Themes API. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
511 |
* @param string $action Requested action. Likely values are 'theme_information', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
* 'feature_list', or 'query_themes'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
* @param object $args Arguments used to query for installer pages from the Themes API. |
5 | 514 |
*/ |
515 |
$res = apply_filters( 'themes_api', false, $action, $args ); |
|
0 | 516 |
|
517 |
if ( ! $res ) { |
|
9 | 518 |
$url = 'http://api.wordpress.org/themes/info/1.2/'; |
519 |
$url = add_query_arg( |
|
520 |
array( |
|
521 |
'action' => $action, |
|
522 |
'request' => $args, |
|
523 |
), |
|
524 |
$url |
|
525 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
|
9 | 527 |
$http_url = $url; |
16 | 528 |
$ssl = wp_http_supports( array( 'ssl' ) ); |
529 |
if ( $ssl ) { |
|
0 | 530 |
$url = set_url_scheme( $url, 'https' ); |
9 | 531 |
} |
0 | 532 |
|
5 | 533 |
$http_args = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
0 | 535 |
); |
9 | 536 |
$request = wp_remote_get( $url, $http_args ); |
0 | 537 |
|
538 |
if ( $ssl && is_wp_error( $request ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
if ( ! wp_doing_ajax() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
trigger_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
sprintf( |
16 | 542 |
/* translators: %s: Support forums URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
16 | 544 |
__( 'https://wordpress.org/support/forums/' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
546 |
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
547 |
); |
5 | 548 |
} |
9 | 549 |
$request = wp_remote_get( $http_url, $http_args ); |
0 | 550 |
} |
551 |
||
9 | 552 |
if ( is_wp_error( $request ) ) { |
553 |
$res = new WP_Error( |
|
554 |
'themes_api_failed', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
555 |
sprintf( |
16 | 556 |
/* translators: %s: Support forums URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
16 | 558 |
__( 'https://wordpress.org/support/forums/' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
559 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
$request->get_error_message() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
); |
0 | 562 |
} else { |
9 | 563 |
$res = json_decode( wp_remote_retrieve_body( $request ), true ); |
564 |
if ( is_array( $res ) ) { |
|
565 |
// Object casting is required in order to match the info/1.0 format. |
|
566 |
$res = (object) $res; |
|
567 |
} elseif ( null === $res ) { |
|
568 |
$res = new WP_Error( |
|
569 |
'themes_api_failed', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
sprintf( |
16 | 571 |
/* translators: %s: Support forums URL. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), |
16 | 573 |
__( 'https://wordpress.org/support/forums/' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
574 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
wp_remote_retrieve_body( $request ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
} |
9 | 578 |
|
579 |
if ( isset( $res->error ) ) { |
|
580 |
$res = new WP_Error( 'themes_api_failed', $res->error ); |
|
581 |
} |
|
582 |
} |
|
583 |
||
584 |
// Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects. |
|
16 | 585 |
if ( 'query_themes' === $action ) { |
9 | 586 |
foreach ( $res->themes as $i => $theme ) { |
587 |
$res->themes[ $i ] = (object) $theme; |
|
588 |
} |
|
589 |
} |
|
590 |
// Back-compat for info/1.2 API, downgrade the feature_list result back to an array. |
|
16 | 591 |
if ( 'feature_list' === $action ) { |
9 | 592 |
$res = (array) $res; |
5 | 593 |
} |
594 |
} |
|
595 |
||
596 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
597 |
* Filters the returned WordPress.org Themes API response. |
5 | 598 |
* |
599 |
* @since 2.8.0 |
|
600 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
* @param array|object|WP_Error $res WordPress.org Themes API response. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
602 |
* @param string $action Requested action. Likely values are 'theme_information', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
* 'feature_list', or 'query_themes'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
604 |
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. |
5 | 605 |
*/ |
606 |
return apply_filters( 'themes_api_result', $res, $action, $args ); |
|
607 |
} |
|
608 |
||
609 |
/** |
|
610 |
* Prepare themes for JavaScript. |
|
611 |
* |
|
612 |
* @since 3.8.0 |
|
613 |
* |
|
9 | 614 |
* @param WP_Theme[] $themes Optional. Array of theme objects to prepare. |
615 |
* Defaults to all allowed themes. |
|
5 | 616 |
* |
617 |
* @return array An associative array of theme data, sorted by name. |
|
618 |
*/ |
|
619 |
function wp_prepare_themes_for_js( $themes = null ) { |
|
620 |
$current_theme = get_stylesheet(); |
|
621 |
||
622 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* Filters theme data before it is prepared for JavaScript. |
5 | 624 |
* |
625 |
* Passing a non-empty array will result in wp_prepare_themes_for_js() returning |
|
626 |
* early with that value instead. |
|
627 |
* |
|
628 |
* @since 4.2.0 |
|
629 |
* |
|
9 | 630 |
* @param array $prepared_themes An associative array of theme data. Default empty array. |
631 |
* @param WP_Theme[]|null $themes An array of theme objects to prepare, if any. |
|
632 |
* @param string $current_theme The current theme slug. |
|
5 | 633 |
*/ |
634 |
$prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme ); |
|
635 |
||
636 |
if ( ! empty( $prepared_themes ) ) { |
|
637 |
return $prepared_themes; |
|
638 |
} |
|
639 |
||
640 |
// Make sure the current theme is listed first. |
|
641 |
$prepared_themes[ $current_theme ] = array(); |
|
642 |
||
643 |
if ( null === $themes ) { |
|
644 |
$themes = wp_get_themes( array( 'allowed' => true ) ); |
|
645 |
if ( ! isset( $themes[ $current_theme ] ) ) { |
|
646 |
$themes[ $current_theme ] = wp_get_theme(); |
|
647 |
} |
|
648 |
} |
|
649 |
||
16 | 650 |
$updates = array(); |
651 |
$no_updates = array(); |
|
5 | 652 |
if ( current_user_can( 'update_themes' ) ) { |
653 |
$updates_transient = get_site_transient( 'update_themes' ); |
|
654 |
if ( isset( $updates_transient->response ) ) { |
|
655 |
$updates = $updates_transient->response; |
|
0 | 656 |
} |
16 | 657 |
if ( isset( $updates_transient->no_update ) ) { |
658 |
$no_updates = $updates_transient->no_update; |
|
659 |
} |
|
0 | 660 |
} |
661 |
||
5 | 662 |
WP_Theme::sort_by_name( $themes ); |
663 |
||
664 |
$parents = array(); |
|
665 |
||
16 | 666 |
$auto_updates = (array) get_site_option( 'auto_update_themes', array() ); |
667 |
||
5 | 668 |
foreach ( $themes as $theme ) { |
9 | 669 |
$slug = $theme->get_stylesheet(); |
5 | 670 |
$encoded_slug = urlencode( $slug ); |
671 |
||
672 |
$parent = false; |
|
673 |
if ( $theme->parent() ) { |
|
9 | 674 |
$parent = $theme->parent(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
$parents[ $slug ] = $parent->get_stylesheet(); |
9 | 676 |
$parent = $parent->display( 'Name' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
678 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
679 |
$customize_action = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
680 |
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
9 | 681 |
$customize_action = esc_url( |
682 |
add_query_arg( |
|
683 |
array( |
|
684 |
'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), |
|
685 |
), |
|
686 |
wp_customize_url( $slug ) |
|
687 |
) |
|
688 |
); |
|
5 | 689 |
} |
690 |
||
16 | 691 |
$update_requires_wp = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null; |
692 |
$update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null; |
|
693 |
||
694 |
$auto_update = in_array( $slug, $auto_updates, true ); |
|
695 |
$auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update'; |
|
696 |
||
697 |
if ( isset( $updates[ $slug ] ) ) { |
|
698 |
$auto_update_supported = true; |
|
699 |
$auto_update_filter_payload = (object) $updates[ $slug ]; |
|
700 |
} elseif ( isset( $no_updates[ $slug ] ) ) { |
|
701 |
$auto_update_supported = true; |
|
702 |
$auto_update_filter_payload = (object) $no_updates[ $slug ]; |
|
703 |
} else { |
|
704 |
$auto_update_supported = false; |
|
705 |
/* |
|
706 |
* Create the expected payload for the auto_update_theme filter, this is the same data |
|
707 |
* as contained within $updates or $no_updates but used when the Theme is not known. |
|
708 |
*/ |
|
709 |
$auto_update_filter_payload = (object) array( |
|
710 |
'theme' => $slug, |
|
711 |
'new_version' => $theme->get( 'Version' ), |
|
712 |
'url' => '', |
|
713 |
'package' => '', |
|
714 |
'requires' => $theme->get( 'RequiresWP' ), |
|
715 |
'requires_php' => $theme->get( 'RequiresPHP' ), |
|
716 |
); |
|
717 |
} |
|
718 |
||
719 |
$type = 'theme'; |
|
720 |
/** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */ |
|
721 |
$auto_update_forced = apply_filters( "auto_update_{$type}", null, $auto_update_filter_payload ); |
|
722 |
||
5 | 723 |
$prepared_themes[ $slug ] = array( |
16 | 724 |
'id' => $slug, |
725 |
'name' => $theme->display( 'Name' ), |
|
726 |
'screenshot' => array( $theme->get_screenshot() ), // @todo Multiple screenshots. |
|
727 |
'description' => $theme->display( 'Description' ), |
|
728 |
'author' => $theme->display( 'Author', false, true ), |
|
729 |
'authorAndUri' => $theme->display( 'Author' ), |
|
730 |
'tags' => $theme->display( 'Tags' ), |
|
731 |
'version' => $theme->get( 'Version' ), |
|
732 |
'compatibleWP' => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ), |
|
733 |
'compatiblePHP' => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ), |
|
734 |
'updateResponse' => array( |
|
735 |
'compatibleWP' => is_wp_version_compatible( $update_requires_wp ), |
|
736 |
'compatiblePHP' => is_php_version_compatible( $update_requires_php ), |
|
737 |
), |
|
738 |
'parent' => $parent, |
|
739 |
'active' => $slug === $current_theme, |
|
740 |
'hasUpdate' => isset( $updates[ $slug ] ), |
|
741 |
'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ), |
|
742 |
'update' => get_theme_update_available( $theme ), |
|
743 |
'autoupdate' => array( |
|
744 |
'enabled' => $auto_update || $auto_update_forced, |
|
745 |
'supported' => $auto_update_supported, |
|
746 |
'forced' => $auto_update_forced, |
|
747 |
), |
|
748 |
'actions' => array( |
|
749 |
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, |
|
750 |
'customize' => $customize_action, |
|
751 |
'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, |
|
752 |
'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' ) |
|
753 |
? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&stylesheet=' . $encoded_slug ), 'updates' ) |
|
754 |
: null, |
|
5 | 755 |
), |
756 |
); |
|
757 |
} |
|
758 |
||
16 | 759 |
// Remove 'delete' action if theme has an active child. |
5 | 760 |
if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) { |
761 |
unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] ); |
|
762 |
} |
|
763 |
||
764 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
* Filters the themes prepared for JavaScript, for themes.php. |
5 | 766 |
* |
767 |
* Could be useful for changing the order, which is by name by default. |
|
768 |
* |
|
769 |
* @since 3.8.0 |
|
770 |
* |
|
16 | 771 |
* @param array $prepared_themes Array of theme data. |
5 | 772 |
*/ |
773 |
$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes ); |
|
774 |
$prepared_themes = array_values( $prepared_themes ); |
|
775 |
return array_filter( $prepared_themes ); |
|
0 | 776 |
} |
5 | 777 |
|
778 |
/** |
|
779 |
* Print JS templates for the theme-browsing UI in the Customizer. |
|
780 |
* |
|
781 |
* @since 4.2.0 |
|
782 |
*/ |
|
783 |
function customize_themes_print_templates() { |
|
784 |
?> |
|
785 |
<script type="text/html" id="tmpl-customize-themes-details-view"> |
|
786 |
<div class="theme-backdrop"></div> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
787 |
<div class="theme-wrap wp-clearfix" role="document"> |
5 | 788 |
<div class="theme-header"> |
789 |
<button type="button" class="left dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show previous theme' ); ?></span></button> |
|
790 |
<button type="button" class="right dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show next theme' ); ?></span></button> |
|
791 |
<button type="button" class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close details dialog' ); ?></span></button> |
|
792 |
</div> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
<div class="theme-about wp-clearfix"> |
5 | 794 |
<div class="theme-screenshots"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
<# if ( data.screenshot && data.screenshot[0] ) { #> |
5 | 796 |
<div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div> |
797 |
<# } else { #> |
|
798 |
<div class="screenshot blank"></div> |
|
799 |
<# } #> |
|
800 |
</div> |
|
801 |
||
802 |
<div class="theme-info"> |
|
803 |
<# if ( data.active ) { #> |
|
804 |
<span class="current-label"><?php _e( 'Current Theme' ); ?></span> |
|
805 |
<# } #> |
|
16 | 806 |
<h2 class="theme-name">{{{ data.name }}}<span class="theme-version"> |
807 |
<?php |
|
808 |
/* translators: %s: Theme version. */ |
|
809 |
printf( __( 'Version: %s' ), '{{ data.version }}' ); |
|
810 |
?> |
|
811 |
</span></h2> |
|
812 |
<h3 class="theme-author"> |
|
813 |
<?php |
|
814 |
/* translators: %s: Theme author link. */ |
|
815 |
printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); |
|
816 |
?> |
|
817 |
</h3> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
818 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
819 |
<# if ( data.stars && 0 != data.num_ratings ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
<div class="theme-rating"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
821 |
{{{ data.stars }}} |
9 | 822 |
<a class="num-ratings" target="_blank" href="{{ data.reviews_url }}"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
<?php |
9 | 824 |
printf( |
825 |
'%1$s <span class="screen-reader-text">%2$s</span>', |
|
16 | 826 |
/* translators: %s: Number of ratings. */ |
9 | 827 |
sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' ), |
16 | 828 |
/* translators: Accessibility text. */ |
9 | 829 |
__( '(opens in a new tab)' ) |
830 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
?> |
9 | 832 |
</a> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
833 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
834 |
<# } #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
<# if ( data.hasUpdate ) { #> |
16 | 837 |
<# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #> |
838 |
<div class="notice notice-warning notice-alt notice-large" data-slug="{{ data.id }}"> |
|
839 |
<h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3> |
|
840 |
{{{ data.update }}} |
|
841 |
</div> |
|
842 |
<# } else { #> |
|
843 |
<div class="notice notice-error notice-alt notice-large" data-slug="{{ data.id }}"> |
|
844 |
<h3 class="notice-title"><?php _e( 'Update Incompatible' ); ?></h3> |
|
845 |
<p> |
|
846 |
<# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #> |
|
847 |
<?php |
|
848 |
printf( |
|
849 |
/* translators: %s: Theme name. */ |
|
850 |
__( 'There is a new version of %s available, but it doesn’t work with your versions of WordPress and PHP.' ), |
|
851 |
'{{{ data.name }}}' |
|
852 |
); |
|
853 |
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { |
|
854 |
printf( |
|
855 |
/* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ |
|
856 |
' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), |
|
857 |
self_admin_url( 'update-core.php' ), |
|
858 |
esc_url( wp_get_update_php_url() ) |
|
859 |
); |
|
860 |
wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
861 |
} elseif ( current_user_can( 'update_core' ) ) { |
|
862 |
printf( |
|
863 |
/* translators: %s: URL to WordPress Updates screen. */ |
|
864 |
' ' . __( '<a href="%s">Please update WordPress</a>.' ), |
|
865 |
self_admin_url( 'update-core.php' ) |
|
866 |
); |
|
867 |
} elseif ( current_user_can( 'update_php' ) ) { |
|
868 |
printf( |
|
869 |
/* translators: %s: URL to Update PHP page. */ |
|
870 |
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), |
|
871 |
esc_url( wp_get_update_php_url() ) |
|
872 |
); |
|
873 |
wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
874 |
} |
|
875 |
?> |
|
876 |
<# } else if ( ! data.updateResponse.compatibleWP ) { #> |
|
877 |
<?php |
|
878 |
printf( |
|
879 |
/* translators: %s: Theme name. */ |
|
880 |
__( 'There is a new version of %s available, but it doesn’t work with your version of WordPress.' ), |
|
881 |
'{{{ data.name }}}' |
|
882 |
); |
|
883 |
if ( current_user_can( 'update_core' ) ) { |
|
884 |
printf( |
|
885 |
/* translators: %s: URL to WordPress Updates screen. */ |
|
886 |
' ' . __( '<a href="%s">Please update WordPress</a>.' ), |
|
887 |
self_admin_url( 'update-core.php' ) |
|
888 |
); |
|
889 |
} |
|
890 |
?> |
|
891 |
<# } else if ( ! data.updateResponse.compatiblePHP ) { #> |
|
892 |
<?php |
|
893 |
printf( |
|
894 |
/* translators: %s: Theme name. */ |
|
895 |
__( 'There is a new version of %s available, but it doesn’t work with your version of PHP.' ), |
|
896 |
'{{{ data.name }}}' |
|
897 |
); |
|
898 |
if ( current_user_can( 'update_php' ) ) { |
|
899 |
printf( |
|
900 |
/* translators: %s: URL to Update PHP page. */ |
|
901 |
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), |
|
902 |
esc_url( wp_get_update_php_url() ) |
|
903 |
); |
|
904 |
wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
905 |
} |
|
906 |
?> |
|
907 |
<# } #> |
|
908 |
</p> |
|
909 |
</div> |
|
910 |
<# } #> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
<# } #> |
5 | 912 |
|
913 |
<# if ( data.parent ) { #> |
|
16 | 914 |
<p class="parent-theme"> |
915 |
<?php |
|
916 |
printf( |
|
917 |
/* translators: %s: Theme name. */ |
|
918 |
__( 'This is a child theme of %s.' ), |
|
919 |
'<strong>{{{ data.parent }}}</strong>' |
|
920 |
); |
|
921 |
?> |
|
922 |
</p> |
|
923 |
<# } #> |
|
924 |
||
925 |
<# if ( ! data.compatibleWP || ! data.compatiblePHP ) { #> |
|
926 |
<div class="notice notice-error notice-alt notice-large"><p> |
|
927 |
<# if ( ! data.compatibleWP && ! data.compatiblePHP ) { #> |
|
928 |
<?php |
|
929 |
_e( 'This theme doesn’t work with your versions of WordPress and PHP.' ); |
|
930 |
if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) { |
|
931 |
printf( |
|
932 |
/* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */ |
|
933 |
' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ), |
|
934 |
self_admin_url( 'update-core.php' ), |
|
935 |
esc_url( wp_get_update_php_url() ) |
|
936 |
); |
|
937 |
wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
938 |
} elseif ( current_user_can( 'update_core' ) ) { |
|
939 |
printf( |
|
940 |
/* translators: %s: URL to WordPress Updates screen. */ |
|
941 |
' ' . __( '<a href="%s">Please update WordPress</a>.' ), |
|
942 |
self_admin_url( 'update-core.php' ) |
|
943 |
); |
|
944 |
} elseif ( current_user_can( 'update_php' ) ) { |
|
945 |
printf( |
|
946 |
/* translators: %s: URL to Update PHP page. */ |
|
947 |
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), |
|
948 |
esc_url( wp_get_update_php_url() ) |
|
949 |
); |
|
950 |
wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
951 |
} |
|
952 |
?> |
|
953 |
<# } else if ( ! data.compatibleWP ) { #> |
|
954 |
<?php |
|
955 |
_e( 'This theme doesn’t work with your version of WordPress.' ); |
|
956 |
if ( current_user_can( 'update_core' ) ) { |
|
957 |
printf( |
|
958 |
/* translators: %s: URL to WordPress Updates screen. */ |
|
959 |
' ' . __( '<a href="%s">Please update WordPress</a>.' ), |
|
960 |
self_admin_url( 'update-core.php' ) |
|
961 |
); |
|
962 |
} |
|
963 |
?> |
|
964 |
<# } else if ( ! data.compatiblePHP ) { #> |
|
965 |
<?php |
|
966 |
_e( 'This theme doesn’t work with your version of PHP.' ); |
|
967 |
if ( current_user_can( 'update_php' ) ) { |
|
968 |
printf( |
|
969 |
/* translators: %s: URL to Update PHP page. */ |
|
970 |
' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ), |
|
971 |
esc_url( wp_get_update_php_url() ) |
|
972 |
); |
|
973 |
wp_update_php_annotation( '</p><p><em>', '</em>' ); |
|
974 |
} |
|
975 |
?> |
|
976 |
<# } #> |
|
977 |
</p></div> |
|
5 | 978 |
<# } #> |
979 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
<p class="theme-description">{{{ data.description }}}</p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
|
5 | 982 |
<# if ( data.tags ) { #> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
<p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{{ data.tags }}}</p> |
5 | 984 |
<# } #> |
985 |
</div> |
|
986 |
</div> |
|
987 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
<div class="theme-actions"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
<# if ( data.active ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
<button type="button" class="button button-primary customize-theme"><?php _e( 'Customize' ); ?></button> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
<# } else if ( 'installed' === data.type ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
<?php if ( current_user_can( 'delete_themes' ) ) { ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
<# if ( data.actions && data.actions['delete'] ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
<a href="{{{ data.actions['delete'] }}}" data-slug="{{ data.id }}" class="button button-secondary delete-theme"><?php _e( 'Delete' ); ?></a> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
<# } #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
<?php } ?> |
16 | 997 |
|
998 |
<# if ( data.compatibleWP && data.compatiblePHP ) { #> |
|
999 |
<button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button> |
|
1000 |
<# } else { #> |
|
1001 |
<button class="button button-primary disabled"><?php _e( 'Live Preview' ); ?></button> |
|
1002 |
<# } #> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
<# } else { #> |
16 | 1004 |
<# if ( data.compatibleWP && data.compatiblePHP ) { #> |
1005 |
<button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button> |
|
1006 |
<button type="button" class="button button-primary theme-install preview" data-slug="{{ data.id }}"><?php _e( 'Install & Preview' ); ?></button> |
|
1007 |
<# } else { #> |
|
1008 |
<button type="button" class="button disabled"><?php _ex( 'Cannot Install', 'theme' ); ?></button> |
|
1009 |
<button type="button" class="button button-primary disabled"><?php _e( 'Install & Preview' ); ?></button> |
|
1010 |
<# } #> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
<# } #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
</div> |
5 | 1013 |
</div> |
1014 |
</script> |
|
1015 |
<?php |
|
1016 |
} |
|
9 | 1017 |
|
1018 |
/** |
|
1019 |
* Determines whether a theme is technically active but was paused while |
|
1020 |
* loading. |
|
1021 |
* |
|
1022 |
* For more information on this and similar theme functions, check out |
|
1023 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
1024 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
1025 |
* |
|
1026 |
* @since 5.2.0 |
|
1027 |
* |
|
1028 |
* @param string $theme Path to the theme directory relative to the themes directory. |
|
1029 |
* @return bool True, if in the list of paused themes. False, not in the list. |
|
1030 |
*/ |
|
1031 |
function is_theme_paused( $theme ) { |
|
1032 |
if ( ! isset( $GLOBALS['_paused_themes'] ) ) { |
|
1033 |
return false; |
|
1034 |
} |
|
1035 |
||
1036 |
if ( get_stylesheet() !== $theme && get_template() !== $theme ) { |
|
1037 |
return false; |
|
1038 |
} |
|
1039 |
||
1040 |
return array_key_exists( $theme, $GLOBALS['_paused_themes'] ); |
|
1041 |
} |
|
1042 |
||
1043 |
/** |
|
1044 |
* Gets the error that was recorded for a paused theme. |
|
1045 |
* |
|
1046 |
* @since 5.2.0 |
|
1047 |
* |
|
1048 |
* @param string $theme Path to the theme directory relative to the themes |
|
1049 |
* directory. |
|
1050 |
* @return array|false Array of error information as it was returned by |
|
1051 |
* `error_get_last()`, or false if none was recorded. |
|
1052 |
*/ |
|
1053 |
function wp_get_theme_error( $theme ) { |
|
1054 |
if ( ! isset( $GLOBALS['_paused_themes'] ) ) { |
|
1055 |
return false; |
|
1056 |
} |
|
1057 |
||
1058 |
if ( ! array_key_exists( $theme, $GLOBALS['_paused_themes'] ) ) { |
|
1059 |
return false; |
|
1060 |
} |
|
1061 |
||
1062 |
return $GLOBALS['_paused_themes'][ $theme ]; |
|
1063 |
} |
|
1064 |
||
1065 |
/** |
|
1066 |
* Tries to resume a single theme. |
|
1067 |
* |
|
1068 |
* If a redirect was provided and a functions.php file was found, we first ensure that |
|
1069 |
* functions.php file does not throw fatal errors anymore. |
|
1070 |
* |
|
1071 |
* The way it works is by setting the redirection to the error before trying to |
|
1072 |
* include the file. If the theme fails, then the redirection will not be overwritten |
|
1073 |
* with the success message and the theme will not be resumed. |
|
1074 |
* |
|
1075 |
* @since 5.2.0 |
|
1076 |
* |
|
1077 |
* @param string $theme Single theme to resume. |
|
1078 |
* @param string $redirect Optional. URL to redirect to. Default empty string. |
|
1079 |
* @return bool|WP_Error True on success, false if `$theme` was not paused, |
|
1080 |
* `WP_Error` on failure. |
|
1081 |
*/ |
|
1082 |
function resume_theme( $theme, $redirect = '' ) { |
|
1083 |
list( $extension ) = explode( '/', $theme ); |
|
1084 |
||
1085 |
/* |
|
1086 |
* We'll override this later if the theme could be resumed without |
|
1087 |
* creating a fatal error. |
|
1088 |
*/ |
|
1089 |
if ( ! empty( $redirect ) ) { |
|
1090 |
$functions_path = ''; |
|
1091 |
if ( strpos( STYLESHEETPATH, $extension ) ) { |
|
1092 |
$functions_path = STYLESHEETPATH . '/functions.php'; |
|
1093 |
} elseif ( strpos( TEMPLATEPATH, $extension ) ) { |
|
1094 |
$functions_path = TEMPLATEPATH . '/functions.php'; |
|
1095 |
} |
|
1096 |
||
1097 |
if ( ! empty( $functions_path ) ) { |
|
1098 |
wp_redirect( |
|
1099 |
add_query_arg( |
|
1100 |
'_error_nonce', |
|
1101 |
wp_create_nonce( 'theme-resume-error_' . $theme ), |
|
1102 |
$redirect |
|
1103 |
) |
|
1104 |
); |
|
1105 |
||
1106 |
// Load the theme's functions.php to test whether it throws a fatal error. |
|
1107 |
ob_start(); |
|
1108 |
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
|
1109 |
define( 'WP_SANDBOX_SCRAPING', true ); |
|
1110 |
} |
|
1111 |
include $functions_path; |
|
1112 |
ob_clean(); |
|
1113 |
} |
|
1114 |
} |
|
1115 |
||
1116 |
$result = wp_paused_themes()->delete( $extension ); |
|
1117 |
||
1118 |
if ( ! $result ) { |
|
1119 |
return new WP_Error( |
|
1120 |
'could_not_resume_theme', |
|
1121 |
__( 'Could not resume the theme.' ) |
|
1122 |
); |
|
1123 |
} |
|
1124 |
||
1125 |
return true; |
|
1126 |
} |
|
1127 |
||
1128 |
/** |
|
1129 |
* Renders an admin notice in case some themes have been paused due to errors. |
|
1130 |
* |
|
1131 |
* @since 5.2.0 |
|
1132 |
*/ |
|
1133 |
function paused_themes_notice() { |
|
1134 |
if ( 'themes.php' === $GLOBALS['pagenow'] ) { |
|
1135 |
return; |
|
1136 |
} |
|
1137 |
||
1138 |
if ( ! current_user_can( 'resume_themes' ) ) { |
|
1139 |
return; |
|
1140 |
} |
|
1141 |
||
1142 |
if ( ! isset( $GLOBALS['_paused_themes'] ) || empty( $GLOBALS['_paused_themes'] ) ) { |
|
1143 |
return; |
|
1144 |
} |
|
1145 |
||
1146 |
printf( |
|
1147 |
'<div class="notice notice-error"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>', |
|
1148 |
__( 'One or more themes failed to load properly.' ), |
|
1149 |
__( 'You can find more details and make changes on the Themes screen.' ), |
|
1150 |
esc_url( admin_url( 'themes.php' ) ), |
|
1151 |
__( 'Go to the Themes screen' ) |
|
1152 |
); |
|
1153 |
} |