author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
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 ) ) { |
38 |
include_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
0 | 39 |
echo $data; |
9 | 40 |
include( 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(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
request_filesystem_credentials( $redirect, '', true ); // Failed to connect, Error and request again. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
$data = ob_get_clean(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
|
9 | 51 |
if ( ! empty( $data ) ) { |
52 |
include_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
0 | 53 |
echo $data; |
9 | 54 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |
0 | 55 |
exit; |
56 |
} |
|
57 |
return; |
|
58 |
} |
|
59 |
||
9 | 60 |
if ( ! is_object( $wp_filesystem ) ) { |
61 |
return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); |
|
62 |
} |
|
0 | 63 |
|
9 | 64 |
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) { |
65 |
return new WP_Error( 'fs_error', __( 'Filesystem error.' ), $wp_filesystem->errors ); |
|
66 |
} |
|
0 | 67 |
|
5 | 68 |
// Get the base plugin folder. |
0 | 69 |
$themes_dir = $wp_filesystem->wp_themes_dir(); |
5 | 70 |
if ( empty( $themes_dir ) ) { |
71 |
return new WP_Error( 'fs_no_themes_dir', __( 'Unable to locate WordPress theme directory.' ) ); |
|
72 |
} |
|
0 | 73 |
|
74 |
$themes_dir = trailingslashit( $themes_dir ); |
|
9 | 75 |
$theme_dir = trailingslashit( $themes_dir . $stylesheet ); |
76 |
$deleted = $wp_filesystem->delete( $theme_dir, true ); |
|
5 | 77 |
|
78 |
if ( ! $deleted ) { |
|
79 |
return new WP_Error( 'could_not_remove_theme', sprintf( __( 'Could not fully remove the theme %s.' ), $stylesheet ) ); |
|
80 |
} |
|
81 |
||
82 |
$theme_translations = wp_get_installed_translations( 'themes' ); |
|
0 | 83 |
|
5 | 84 |
// Remove language files, silently. |
85 |
if ( ! empty( $theme_translations[ $stylesheet ] ) ) { |
|
86 |
$translations = $theme_translations[ $stylesheet ]; |
|
0 | 87 |
|
5 | 88 |
foreach ( $translations as $translation => $data ) { |
89 |
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po' ); |
|
90 |
$wp_filesystem->delete( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo' ); |
|
9 | 91 |
|
92 |
$json_translation_files = glob( WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '-*.json' ); |
|
93 |
if ( $json_translation_files ) { |
|
94 |
array_map( array( $wp_filesystem, 'delete' ), $json_translation_files ); |
|
95 |
} |
|
5 | 96 |
} |
97 |
} |
|
98 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
// Remove the theme from allowed themes on the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
if ( is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
WP_Theme::network_disable_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
|
5 | 104 |
// Force refresh of theme update information. |
105 |
delete_site_transient( 'update_themes' ); |
|
0 | 106 |
|
107 |
return true; |
|
108 |
} |
|
109 |
||
110 |
/** |
|
111 |
* Get the Page Templates available in this theme |
|
112 |
* |
|
113 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
* @since 4.7.0 Added the `$post_type` parameter. |
0 | 115 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
* @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
|
117 |
* @param string $post_type Optional. Post type to get the templates for. Default 'page'. |
0 | 118 |
* @return array Key is the template name, value is the filename of the template |
119 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
function get_page_templates( $post = null, $post_type = 'page' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) ); |
0 | 122 |
} |
123 |
||
124 |
/** |
|
125 |
* Tidies a filename for url display by the theme editor. |
|
126 |
* |
|
127 |
* @since 2.9.0 |
|
128 |
* @access private |
|
129 |
* |
|
130 |
* @param string $fullpath Full path to the theme file |
|
131 |
* @param string $containingfolder Path of the theme parent folder |
|
132 |
* @return string |
|
133 |
*/ |
|
9 | 134 |
function _get_template_edit_filename( $fullpath, $containingfolder ) { |
135 |
return str_replace( dirname( dirname( $containingfolder ) ), '', $fullpath ); |
|
0 | 136 |
} |
137 |
||
138 |
/** |
|
139 |
* Check if there is an update for a theme available. |
|
140 |
* |
|
141 |
* Will display link, if there is an update available. |
|
142 |
* |
|
143 |
* @since 2.7.0 |
|
5 | 144 |
* @see get_theme_update_available() |
0 | 145 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* @param WP_Theme $theme Theme data object. |
0 | 147 |
*/ |
148 |
function theme_update_available( $theme ) { |
|
5 | 149 |
echo get_theme_update_available( $theme ); |
150 |
} |
|
151 |
||
152 |
/** |
|
153 |
* Retrieve the update link if there is a theme update available. |
|
154 |
* |
|
155 |
* Will return a link if there is an update available. |
|
156 |
* |
|
157 |
* @since 3.8.0 |
|
158 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
* @staticvar object $themes_update |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* |
5 | 161 |
* @param WP_Theme $theme WP_Theme object. |
162 |
* @return false|string HTML for the update link, or false if invalid info was passed. |
|
163 |
*/ |
|
164 |
function get_theme_update_available( $theme ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
static $themes_update = null; |
0 | 166 |
|
9 | 167 |
if ( ! current_user_can( 'update_themes' ) ) { |
5 | 168 |
return false; |
9 | 169 |
} |
0 | 170 |
|
9 | 171 |
if ( ! isset( $themes_update ) ) { |
172 |
$themes_update = get_site_transient( 'update_themes' ); |
|
173 |
} |
|
0 | 174 |
|
5 | 175 |
if ( ! ( $theme instanceof WP_Theme ) ) { |
176 |
return false; |
|
177 |
} |
|
0 | 178 |
|
179 |
$stylesheet = $theme->get_stylesheet(); |
|
180 |
||
5 | 181 |
$html = ''; |
182 |
||
9 | 183 |
if ( isset( $themes_update->response[ $stylesheet ] ) ) { |
184 |
$update = $themes_update->response[ $stylesheet ]; |
|
185 |
$theme_name = $theme->display( 'Name' ); |
|
186 |
$details_url = add_query_arg( |
|
187 |
array( |
|
188 |
'TB_iframe' => 'true', |
|
189 |
'width' => 1024, |
|
190 |
'height' => 800, |
|
191 |
), |
|
192 |
$update['url'] |
|
193 |
); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list. |
|
194 |
$update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet ); |
|
0 | 195 |
|
9 | 196 |
if ( ! is_multisite() ) { |
197 |
if ( ! current_user_can( 'update_themes' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */ |
9 | 199 |
$html = sprintf( |
200 |
'<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
|
201 |
$theme_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
esc_url( $details_url ), |
9 | 203 |
sprintf( |
204 |
'class="thickbox open-plugin-details-modal" aria-label="%s"', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
/* translators: 1: theme name, 2: version number */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
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
|
207 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
$update['new_version'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
); |
5 | 210 |
} elseif ( empty( $update['package'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number */ |
9 | 212 |
$html = sprintf( |
213 |
'<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
|
214 |
$theme_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
esc_url( $details_url ), |
9 | 216 |
sprintf( |
217 |
'class="thickbox open-plugin-details-modal" aria-label="%s"', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
/* translators: 1: theme name, 2: version number */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
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
|
220 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
$update['new_version'] |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
); |
5 | 223 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
/* translators: 1: theme name, 2: theme details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */ |
9 | 225 |
$html = sprintf( |
226 |
'<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
|
227 |
$theme_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
esc_url( $details_url ), |
9 | 229 |
sprintf( |
230 |
'class="thickbox open-plugin-details-modal" aria-label="%s"', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
/* translators: 1: theme name, 2: version number */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
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
|
233 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
$update['new_version'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
$update_url, |
9 | 236 |
sprintf( |
237 |
'aria-label="%s" id="update-theme" data-slug="%s"', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
/* translators: %s: theme name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
esc_attr( sprintf( __( 'Update %s now' ), $theme_name ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
$stylesheet |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
); |
5 | 243 |
} |
0 | 244 |
} |
245 |
} |
|
5 | 246 |
|
247 |
return $html; |
|
0 | 248 |
} |
249 |
||
250 |
/** |
|
9 | 251 |
* Retrieve list of WordPress theme features (aka theme tags). |
0 | 252 |
* |
253 |
* @since 3.1.0 |
|
254 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
* @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true. |
0 | 256 |
* @return array Array of features keyed by category with translations keyed by slug. |
257 |
*/ |
|
258 |
function get_theme_feature_list( $api = true ) { |
|
259 |
// Hard-coded list is used if api not accessible. |
|
260 |
$features = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
__( 'Subject' ) => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
'blog' => __( 'Blog' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
'e-commerce' => __( 'E-Commerce' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
'education' => __( 'Education' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
'entertainment' => __( 'Entertainment' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
'food-and-drink' => __( 'Food & Drink' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
'holiday' => __( 'Holiday' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
'news' => __( 'News' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
'photography' => __( 'Photography' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
'portfolio' => __( 'Portfolio' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
__( 'Features' ) => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
'accessibility-ready' => __( 'Accessibility Ready' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
'custom-background' => __( 'Custom Background' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
'custom-colors' => __( 'Custom Colors' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
'custom-header' => __( 'Custom Header' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
'custom-logo' => __( 'Custom Logo' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
'editor-style' => __( 'Editor Style' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
'featured-image-header' => __( 'Featured Image Header' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
'featured-images' => __( 'Featured Images' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
'footer-widgets' => __( 'Footer Widgets' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
'full-width-template' => __( 'Full Width Template' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
'post-formats' => __( 'Post Formats' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
286 |
'sticky-post' => __( 'Sticky Post' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
'theme-options' => __( 'Theme Options' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
), |
0 | 289 |
|
9 | 290 |
__( 'Layout' ) => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
291 |
'grid-layout' => __( 'Grid Layout' ), |
0 | 292 |
'one-column' => __( 'One Column' ), |
293 |
'two-columns' => __( 'Two Columns' ), |
|
294 |
'three-columns' => __( 'Three Columns' ), |
|
295 |
'four-columns' => __( 'Four Columns' ), |
|
296 |
'left-sidebar' => __( 'Left Sidebar' ), |
|
297 |
'right-sidebar' => __( 'Right Sidebar' ), |
|
9 | 298 |
), |
0 | 299 |
|
300 |
); |
|
301 |
||
9 | 302 |
if ( ! $api || ! current_user_can( 'install_themes' ) ) { |
0 | 303 |
return $features; |
9 | 304 |
} |
0 | 305 |
|
9 | 306 |
if ( ! $feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) { |
5 | 307 |
set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS ); |
0 | 308 |
} |
309 |
||
9 | 310 |
if ( ! $feature_list ) { |
311 |
$feature_list = themes_api( 'feature_list', array() ); |
|
312 |
if ( is_wp_error( $feature_list ) ) { |
|
313 |
return $features; |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
if ( ! $feature_list ) { |
|
0 | 318 |
return $features; |
9 | 319 |
} |
0 | 320 |
|
5 | 321 |
set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS ); |
0 | 322 |
|
5 | 323 |
$category_translations = array( |
324 |
'Layout' => __( 'Layout' ), |
|
325 |
'Features' => __( 'Features' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
'Subject' => __( 'Subject' ), |
5 | 327 |
); |
0 | 328 |
|
329 |
// Loop over the wporg canonical list and apply translations |
|
330 |
$wporg_features = array(); |
|
331 |
foreach ( (array) $feature_list as $feature_category => $feature_items ) { |
|
9 | 332 |
if ( isset( $category_translations[ $feature_category ] ) ) { |
333 |
$feature_category = $category_translations[ $feature_category ]; |
|
334 |
} |
|
335 |
$wporg_features[ $feature_category ] = array(); |
|
0 | 336 |
|
337 |
foreach ( $feature_items as $feature ) { |
|
9 | 338 |
if ( isset( $features[ $feature_category ][ $feature ] ) ) { |
339 |
$wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ]; |
|
340 |
} else { |
|
341 |
$wporg_features[ $feature_category ][ $feature ] = $feature; |
|
342 |
} |
|
0 | 343 |
} |
344 |
} |
|
345 |
||
346 |
return $wporg_features; |
|
347 |
} |
|
348 |
||
349 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
* Retrieves theme installer pages from the WordPress.org Themes API. |
0 | 351 |
* |
352 |
* It is possible for a theme to override the Themes API result with three |
|
353 |
* filters. Assume this is for themes, which can extend on the Theme Info to |
|
354 |
* offer more choices. This is very powerful and must be used with care, when |
|
5 | 355 |
* overriding the filters. |
0 | 356 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
* 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
|
358 |
* 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
|
359 |
* an object is returned. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
* 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
|
362 |
* 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
|
363 |
* 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
|
364 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
* 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
|
366 |
* response object or array, depending on the `$action` type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* Supported arguments per action: |
0 | 369 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
370 |
* | 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
|
371 |
* | -------------------| :------------: | :-----------------: | :--------: | :--------------: | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
372 |
* | `$slug` | No | Yes | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* | `$per_page` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* | `$page` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* | `$number` | No | No | Yes | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
* | `$search` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
* | `$tag` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* | `$author` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
379 |
* | `$user` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
* | `$browse` | Yes | No | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
* | `$locale` | Yes | Yes | No | No | |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
* | `$fields` | Yes | Yes | No | No | |
0 | 383 |
* |
384 |
* @since 2.8.0 |
|
385 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* @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
|
387 |
* 'hot_tags' or 'feature_list'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* @param array|object $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* 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
|
390 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
* @type string $slug The theme slug. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* @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
|
393 |
* @type int $page Number of current page. Default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
* @type int $number Number of tags to be queried. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
395 |
* @type string $search A search term. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
396 |
* @type string $tag Tag to filter themes. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
397 |
* @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
|
398 |
* @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
|
399 |
* @type string $browse Browse view: 'featured', 'popular', 'updated', 'favorites'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
400 |
* @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
|
401 |
* @type array $fields { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
402 |
* 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
|
403 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
404 |
* @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
|
405 |
* @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
|
406 |
* FAQ, screenshots, other notes, and changelog. Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
* @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
|
408 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* @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
|
410 |
* @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
|
411 |
* @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
|
412 |
* @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
|
413 |
* @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
|
414 |
* @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
|
415 |
* @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
|
416 |
* @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
|
417 |
* @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
|
418 |
* @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
|
419 |
* @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
|
420 |
* @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
|
421 |
* @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
|
422 |
* @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
|
423 |
* @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
|
424 |
* } |
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 |
* @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
|
427 |
* {@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
|
428 |
* for more information on the make-up of possible return objects depending on the value of `$action`. |
0 | 429 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
function themes_api( $action, $args = array() ) { |
9 | 431 |
// include an unmodified $wp_version |
432 |
include( ABSPATH . WPINC . '/version.php' ); |
|
5 | 433 |
|
434 |
if ( is_array( $args ) ) { |
|
435 |
$args = (object) $args; |
|
436 |
} |
|
0 | 437 |
|
9 | 438 |
if ( 'query_themes' == $action ) { |
439 |
if ( ! isset( $args->per_page ) ) { |
|
440 |
$args->per_page = 24; |
|
441 |
} |
|
5 | 442 |
} |
443 |
||
444 |
if ( ! isset( $args->locale ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
$args->locale = get_user_locale(); |
5 | 446 |
} |
0 | 447 |
|
9 | 448 |
if ( ! isset( $args->wp_version ) ) { |
449 |
$args->wp_version = substr( $wp_version, 0, 3 ); // X.y |
|
450 |
} |
|
451 |
||
5 | 452 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* Filters arguments used to query for installer pages from the WordPress.org Themes API. |
5 | 454 |
* |
455 |
* Important: An object MUST be returned to this filter. |
|
456 |
* |
|
457 |
* @since 2.8.0 |
|
458 |
* |
|
459 |
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. |
|
460 |
* @param string $action Requested action. Likely values are 'theme_information', |
|
461 |
* 'feature_list', or 'query_themes'. |
|
462 |
*/ |
|
463 |
$args = apply_filters( 'themes_api_args', $args, $action ); |
|
0 | 464 |
|
5 | 465 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
466 |
* Filters whether to override the WordPress.org Themes API. |
5 | 467 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
* 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
|
469 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
470 |
* 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
|
471 |
* be passed. If `$action` is 'hot_tags', an array should be passed. |
5 | 472 |
* |
473 |
* @since 2.8.0 |
|
474 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* @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
|
476 |
* @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
|
477 |
* 'feature_list', or 'query_themes'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
* @param object $args Arguments used to query for installer pages from the Themes API. |
5 | 479 |
*/ |
480 |
$res = apply_filters( 'themes_api', false, $action, $args ); |
|
0 | 481 |
|
482 |
if ( ! $res ) { |
|
9 | 483 |
$url = 'http://api.wordpress.org/themes/info/1.2/'; |
484 |
$url = add_query_arg( |
|
485 |
array( |
|
486 |
'action' => $action, |
|
487 |
'request' => $args, |
|
488 |
), |
|
489 |
$url |
|
490 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
|
9 | 492 |
$http_url = $url; |
493 |
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { |
|
0 | 494 |
$url = set_url_scheme( $url, 'https' ); |
9 | 495 |
} |
0 | 496 |
|
5 | 497 |
$http_args = array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
0 | 499 |
); |
9 | 500 |
$request = wp_remote_get( $url, $http_args ); |
0 | 501 |
|
502 |
if ( $ssl && is_wp_error( $request ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
if ( ! wp_doing_ajax() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
trigger_error( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
505 |
sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
506 |
/* translators: %s: support forums URL */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
__( '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>.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
508 |
__( 'https://wordpress.org/support/' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
509 |
) . ' ' . __( '(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
|
510 |
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
|
511 |
); |
5 | 512 |
} |
9 | 513 |
$request = wp_remote_get( $http_url, $http_args ); |
0 | 514 |
} |
515 |
||
9 | 516 |
if ( is_wp_error( $request ) ) { |
517 |
$res = new WP_Error( |
|
518 |
'themes_api_failed', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
/* translators: %s: support forums URL */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
__( '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>.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
522 |
__( 'https://wordpress.org/support/' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
523 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
524 |
$request->get_error_message() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
); |
0 | 526 |
} else { |
9 | 527 |
$res = json_decode( wp_remote_retrieve_body( $request ), true ); |
528 |
if ( is_array( $res ) ) { |
|
529 |
// Object casting is required in order to match the info/1.0 format. |
|
530 |
$res = (object) $res; |
|
531 |
} elseif ( null === $res ) { |
|
532 |
$res = new WP_Error( |
|
533 |
'themes_api_failed', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
535 |
/* translators: %s: support forums URL */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
__( '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>.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
537 |
__( 'https://wordpress.org/support/' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
wp_remote_retrieve_body( $request ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
540 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
541 |
} |
9 | 542 |
|
543 |
if ( isset( $res->error ) ) { |
|
544 |
$res = new WP_Error( 'themes_api_failed', $res->error ); |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
// Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects. |
|
549 |
if ( 'query_themes' == $action ) { |
|
550 |
foreach ( $res->themes as $i => $theme ) { |
|
551 |
$res->themes[ $i ] = (object) $theme; |
|
552 |
} |
|
553 |
} |
|
554 |
// Back-compat for info/1.2 API, downgrade the feature_list result back to an array. |
|
555 |
if ( 'feature_list' == $action ) { |
|
556 |
$res = (array) $res; |
|
5 | 557 |
} |
558 |
} |
|
559 |
||
560 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
* Filters the returned WordPress.org Themes API response. |
5 | 562 |
* |
563 |
* @since 2.8.0 |
|
564 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
* @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
|
566 |
* @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
|
567 |
* 'feature_list', or 'query_themes'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
568 |
* @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. |
5 | 569 |
*/ |
570 |
return apply_filters( 'themes_api_result', $res, $action, $args ); |
|
571 |
} |
|
572 |
||
573 |
/** |
|
574 |
* Prepare themes for JavaScript. |
|
575 |
* |
|
576 |
* @since 3.8.0 |
|
577 |
* |
|
9 | 578 |
* @param WP_Theme[] $themes Optional. Array of theme objects to prepare. |
579 |
* Defaults to all allowed themes. |
|
5 | 580 |
* |
581 |
* @return array An associative array of theme data, sorted by name. |
|
582 |
*/ |
|
583 |
function wp_prepare_themes_for_js( $themes = null ) { |
|
584 |
$current_theme = get_stylesheet(); |
|
585 |
||
586 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
* Filters theme data before it is prepared for JavaScript. |
5 | 588 |
* |
589 |
* Passing a non-empty array will result in wp_prepare_themes_for_js() returning |
|
590 |
* early with that value instead. |
|
591 |
* |
|
592 |
* @since 4.2.0 |
|
593 |
* |
|
9 | 594 |
* @param array $prepared_themes An associative array of theme data. Default empty array. |
595 |
* @param WP_Theme[]|null $themes An array of theme objects to prepare, if any. |
|
596 |
* @param string $current_theme The current theme slug. |
|
5 | 597 |
*/ |
598 |
$prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme ); |
|
599 |
||
600 |
if ( ! empty( $prepared_themes ) ) { |
|
601 |
return $prepared_themes; |
|
602 |
} |
|
603 |
||
604 |
// Make sure the current theme is listed first. |
|
605 |
$prepared_themes[ $current_theme ] = array(); |
|
606 |
||
607 |
if ( null === $themes ) { |
|
608 |
$themes = wp_get_themes( array( 'allowed' => true ) ); |
|
609 |
if ( ! isset( $themes[ $current_theme ] ) ) { |
|
610 |
$themes[ $current_theme ] = wp_get_theme(); |
|
611 |
} |
|
612 |
} |
|
613 |
||
614 |
$updates = array(); |
|
615 |
if ( current_user_can( 'update_themes' ) ) { |
|
616 |
$updates_transient = get_site_transient( 'update_themes' ); |
|
617 |
if ( isset( $updates_transient->response ) ) { |
|
618 |
$updates = $updates_transient->response; |
|
0 | 619 |
} |
620 |
} |
|
621 |
||
5 | 622 |
WP_Theme::sort_by_name( $themes ); |
623 |
||
624 |
$parents = array(); |
|
625 |
||
626 |
foreach ( $themes as $theme ) { |
|
9 | 627 |
$slug = $theme->get_stylesheet(); |
5 | 628 |
$encoded_slug = urlencode( $slug ); |
629 |
||
630 |
$parent = false; |
|
631 |
if ( $theme->parent() ) { |
|
9 | 632 |
$parent = $theme->parent(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
$parents[ $slug ] = $parent->get_stylesheet(); |
9 | 634 |
$parent = $parent->display( 'Name' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
$customize_action = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { |
9 | 639 |
$customize_action = esc_url( |
640 |
add_query_arg( |
|
641 |
array( |
|
642 |
'return' => urlencode( esc_url_raw( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), |
|
643 |
), |
|
644 |
wp_customize_url( $slug ) |
|
645 |
) |
|
646 |
); |
|
5 | 647 |
} |
648 |
||
649 |
$prepared_themes[ $slug ] = array( |
|
650 |
'id' => $slug, |
|
651 |
'name' => $theme->display( 'Name' ), |
|
652 |
'screenshot' => array( $theme->get_screenshot() ), // @todo multiple |
|
653 |
'description' => $theme->display( 'Description' ), |
|
654 |
'author' => $theme->display( 'Author', false, true ), |
|
655 |
'authorAndUri' => $theme->display( 'Author' ), |
|
656 |
'version' => $theme->display( 'Version' ), |
|
657 |
'tags' => $theme->display( 'Tags' ), |
|
658 |
'parent' => $parent, |
|
659 |
'active' => $slug === $current_theme, |
|
660 |
'hasUpdate' => isset( $updates[ $slug ] ), |
|
9 | 661 |
'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ), |
5 | 662 |
'update' => get_theme_update_available( $theme ), |
663 |
'actions' => array( |
|
9 | 664 |
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
665 |
'customize' => $customize_action, |
9 | 666 |
'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, |
5 | 667 |
), |
668 |
); |
|
669 |
} |
|
670 |
||
671 |
// Remove 'delete' action if theme has an active child |
|
672 |
if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) { |
|
673 |
unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] ); |
|
674 |
} |
|
675 |
||
676 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
* Filters the themes prepared for JavaScript, for themes.php. |
5 | 678 |
* |
679 |
* Could be useful for changing the order, which is by name by default. |
|
680 |
* |
|
681 |
* @since 3.8.0 |
|
682 |
* |
|
683 |
* @param array $prepared_themes Array of themes. |
|
684 |
*/ |
|
685 |
$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes ); |
|
686 |
$prepared_themes = array_values( $prepared_themes ); |
|
687 |
return array_filter( $prepared_themes ); |
|
0 | 688 |
} |
5 | 689 |
|
690 |
/** |
|
691 |
* Print JS templates for the theme-browsing UI in the Customizer. |
|
692 |
* |
|
693 |
* @since 4.2.0 |
|
694 |
*/ |
|
695 |
function customize_themes_print_templates() { |
|
696 |
?> |
|
697 |
<script type="text/html" id="tmpl-customize-themes-details-view"> |
|
698 |
<div class="theme-backdrop"></div> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
<div class="theme-wrap wp-clearfix" role="document"> |
5 | 700 |
<div class="theme-header"> |
701 |
<button type="button" class="left dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show previous theme' ); ?></span></button> |
|
702 |
<button type="button" class="right dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show next theme' ); ?></span></button> |
|
703 |
<button type="button" class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close details dialog' ); ?></span></button> |
|
704 |
</div> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
<div class="theme-about wp-clearfix"> |
5 | 706 |
<div class="theme-screenshots"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
<# if ( data.screenshot && data.screenshot[0] ) { #> |
5 | 708 |
<div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div> |
709 |
<# } else { #> |
|
710 |
<div class="screenshot blank"></div> |
|
711 |
<# } #> |
|
712 |
</div> |
|
713 |
||
714 |
<div class="theme-info"> |
|
715 |
<# if ( data.active ) { #> |
|
716 |
<span class="current-label"><?php _e( 'Current Theme' ); ?></span> |
|
717 |
<# } #> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
<h2 class="theme-name">{{{ data.name }}}<span class="theme-version"><?php printf( __( 'Version: %s' ), '{{ data.version }}' ); ?></span></h2> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
<h3 class="theme-author"><?php printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' ); ?></h3> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
<# if ( data.stars && 0 != data.num_ratings ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
<div class="theme-rating"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
{{{ data.stars }}} |
9 | 724 |
<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
|
725 |
<?php |
9 | 726 |
printf( |
727 |
'%1$s <span class="screen-reader-text">%2$s</span>', |
|
728 |
/* translators: %s: number of ratings */ |
|
729 |
sprintf( __( '(%s ratings)' ), '{{ data.num_ratings }}' ), |
|
730 |
/* translators: accessibility text */ |
|
731 |
__( '(opens in a new tab)' ) |
|
732 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
?> |
9 | 734 |
</a> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
736 |
<# } #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
<# if ( data.hasUpdate ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
739 |
<div class="notice notice-warning notice-alt notice-large" data-slug="{{ data.id }}"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
<h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
{{{ data.update }}} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
</div> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
<# } #> |
5 | 744 |
|
745 |
<# if ( data.parent ) { #> |
|
746 |
<p class="parent-theme"><?php printf( __( 'This is a child theme of %s.' ), '<strong>{{{ data.parent }}}</strong>' ); ?></p> |
|
747 |
<# } #> |
|
748 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
<p class="theme-description">{{{ data.description }}}</p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
750 |
|
5 | 751 |
<# if ( data.tags ) { #> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
752 |
<p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{{ data.tags }}}</p> |
5 | 753 |
<# } #> |
754 |
</div> |
|
755 |
</div> |
|
756 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
<div class="theme-actions"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
<# if ( data.active ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
<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
|
760 |
<# } else if ( 'installed' === data.type ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
<?php if ( current_user_can( 'delete_themes' ) ) { ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
<# if ( data.actions && data.actions['delete'] ) { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
<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
|
764 |
<# } #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
765 |
<?php } ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
766 |
<button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
<# } else { #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
<button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
<button type="button" class="button button-primary theme-install preview" data-slug="{{ data.id }}"><?php _e( 'Install & Preview' ); ?></button> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
<# } #> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
</div> |
5 | 772 |
</div> |
773 |
</script> |
|
774 |
<?php |
|
775 |
} |
|
9 | 776 |
|
777 |
/** |
|
778 |
* Determines whether a theme is technically active but was paused while |
|
779 |
* loading. |
|
780 |
* |
|
781 |
* For more information on this and similar theme functions, check out |
|
782 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
783 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
784 |
* |
|
785 |
* @since 5.2.0 |
|
786 |
* |
|
787 |
* @param string $theme Path to the theme directory relative to the themes directory. |
|
788 |
* @return bool True, if in the list of paused themes. False, not in the list. |
|
789 |
*/ |
|
790 |
function is_theme_paused( $theme ) { |
|
791 |
if ( ! isset( $GLOBALS['_paused_themes'] ) ) { |
|
792 |
return false; |
|
793 |
} |
|
794 |
||
795 |
if ( get_stylesheet() !== $theme && get_template() !== $theme ) { |
|
796 |
return false; |
|
797 |
} |
|
798 |
||
799 |
return array_key_exists( $theme, $GLOBALS['_paused_themes'] ); |
|
800 |
} |
|
801 |
||
802 |
/** |
|
803 |
* Gets the error that was recorded for a paused theme. |
|
804 |
* |
|
805 |
* @since 5.2.0 |
|
806 |
* |
|
807 |
* @param string $theme Path to the theme directory relative to the themes |
|
808 |
* directory. |
|
809 |
* @return array|false Array of error information as it was returned by |
|
810 |
* `error_get_last()`, or false if none was recorded. |
|
811 |
*/ |
|
812 |
function wp_get_theme_error( $theme ) { |
|
813 |
if ( ! isset( $GLOBALS['_paused_themes'] ) ) { |
|
814 |
return false; |
|
815 |
} |
|
816 |
||
817 |
if ( ! array_key_exists( $theme, $GLOBALS['_paused_themes'] ) ) { |
|
818 |
return false; |
|
819 |
} |
|
820 |
||
821 |
return $GLOBALS['_paused_themes'][ $theme ]; |
|
822 |
} |
|
823 |
||
824 |
/** |
|
825 |
* Tries to resume a single theme. |
|
826 |
* |
|
827 |
* If a redirect was provided and a functions.php file was found, we first ensure that |
|
828 |
* functions.php file does not throw fatal errors anymore. |
|
829 |
* |
|
830 |
* The way it works is by setting the redirection to the error before trying to |
|
831 |
* include the file. If the theme fails, then the redirection will not be overwritten |
|
832 |
* with the success message and the theme will not be resumed. |
|
833 |
* |
|
834 |
* @since 5.2.0 |
|
835 |
* |
|
836 |
* @param string $theme Single theme to resume. |
|
837 |
* @param string $redirect Optional. URL to redirect to. Default empty string. |
|
838 |
* @return bool|WP_Error True on success, false if `$theme` was not paused, |
|
839 |
* `WP_Error` on failure. |
|
840 |
*/ |
|
841 |
function resume_theme( $theme, $redirect = '' ) { |
|
842 |
list( $extension ) = explode( '/', $theme ); |
|
843 |
||
844 |
/* |
|
845 |
* We'll override this later if the theme could be resumed without |
|
846 |
* creating a fatal error. |
|
847 |
*/ |
|
848 |
if ( ! empty( $redirect ) ) { |
|
849 |
$functions_path = ''; |
|
850 |
if ( strpos( STYLESHEETPATH, $extension ) ) { |
|
851 |
$functions_path = STYLESHEETPATH . '/functions.php'; |
|
852 |
} elseif ( strpos( TEMPLATEPATH, $extension ) ) { |
|
853 |
$functions_path = TEMPLATEPATH . '/functions.php'; |
|
854 |
} |
|
855 |
||
856 |
if ( ! empty( $functions_path ) ) { |
|
857 |
wp_redirect( |
|
858 |
add_query_arg( |
|
859 |
'_error_nonce', |
|
860 |
wp_create_nonce( 'theme-resume-error_' . $theme ), |
|
861 |
$redirect |
|
862 |
) |
|
863 |
); |
|
864 |
||
865 |
// Load the theme's functions.php to test whether it throws a fatal error. |
|
866 |
ob_start(); |
|
867 |
if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) { |
|
868 |
define( 'WP_SANDBOX_SCRAPING', true ); |
|
869 |
} |
|
870 |
include $functions_path; |
|
871 |
ob_clean(); |
|
872 |
} |
|
873 |
} |
|
874 |
||
875 |
$result = wp_paused_themes()->delete( $extension ); |
|
876 |
||
877 |
if ( ! $result ) { |
|
878 |
return new WP_Error( |
|
879 |
'could_not_resume_theme', |
|
880 |
__( 'Could not resume the theme.' ) |
|
881 |
); |
|
882 |
} |
|
883 |
||
884 |
return true; |
|
885 |
} |
|
886 |
||
887 |
/** |
|
888 |
* Renders an admin notice in case some themes have been paused due to errors. |
|
889 |
* |
|
890 |
* @since 5.2.0 |
|
891 |
*/ |
|
892 |
function paused_themes_notice() { |
|
893 |
if ( 'themes.php' === $GLOBALS['pagenow'] ) { |
|
894 |
return; |
|
895 |
} |
|
896 |
||
897 |
if ( ! current_user_can( 'resume_themes' ) ) { |
|
898 |
return; |
|
899 |
} |
|
900 |
||
901 |
if ( ! isset( $GLOBALS['_paused_themes'] ) || empty( $GLOBALS['_paused_themes'] ) ) { |
|
902 |
return; |
|
903 |
} |
|
904 |
||
905 |
printf( |
|
906 |
'<div class="notice notice-error"><p><strong>%s</strong><br>%s</p><p><a href="%s">%s</a></p></div>', |
|
907 |
__( 'One or more themes failed to load properly.' ), |
|
908 |
__( 'You can find more details and make changes on the Themes screen.' ), |
|
909 |
esc_url( admin_url( 'themes.php' ) ), |
|
910 |
__( 'Go to the Themes screen' ) |
|
911 |
); |
|
912 |
} |