author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WP_Theme Class |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Theme |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 3.4.0 |
0 | 8 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9 |
#[AllowDynamicProperties] |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
final class WP_Theme implements ArrayAccess { |
0 | 11 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* Whether the theme has been marked as updateable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* @var bool |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* @see WP_MS_Themes_List_Table |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
public $update = false; |
0 | 21 |
|
22 |
/** |
|
23 |
* Headers for style.css files. |
|
24 |
* |
|
16 | 25 |
* @since 3.4.0 |
26 |
* @since 5.4.0 Added `Requires at least` and `Requires PHP` headers. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
* @since 6.1.0 Added `Update URI` header. |
19 | 28 |
* @var string[] |
0 | 29 |
*/ |
30 |
private static $file_headers = array( |
|
31 |
'Name' => 'Theme Name', |
|
32 |
'ThemeURI' => 'Theme URI', |
|
33 |
'Description' => 'Description', |
|
34 |
'Author' => 'Author', |
|
35 |
'AuthorURI' => 'Author URI', |
|
36 |
'Version' => 'Version', |
|
37 |
'Template' => 'Template', |
|
38 |
'Status' => 'Status', |
|
39 |
'Tags' => 'Tags', |
|
40 |
'TextDomain' => 'Text Domain', |
|
41 |
'DomainPath' => 'Domain Path', |
|
16 | 42 |
'RequiresWP' => 'Requires at least', |
43 |
'RequiresPHP' => 'Requires PHP', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
44 |
'UpdateURI' => 'Update URI', |
0 | 45 |
); |
46 |
||
47 |
/** |
|
48 |
* Default themes. |
|
49 |
* |
|
19 | 50 |
* @since 3.4.0 |
51 |
* @since 3.5.0 Added the Twenty Twelve theme. |
|
52 |
* @since 3.6.0 Added the Twenty Thirteen theme. |
|
53 |
* @since 3.8.0 Added the Twenty Fourteen theme. |
|
54 |
* @since 4.1.0 Added the Twenty Fifteen theme. |
|
55 |
* @since 4.4.0 Added the Twenty Sixteen theme. |
|
56 |
* @since 4.7.0 Added the Twenty Seventeen theme. |
|
57 |
* @since 5.0.0 Added the Twenty Nineteen theme. |
|
58 |
* @since 5.3.0 Added the Twenty Twenty theme. |
|
59 |
* @since 5.6.0 Added the Twenty Twenty-One theme. |
|
60 |
* @since 5.9.0 Added the Twenty Twenty-Two theme. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
* @since 6.1.0 Added the Twenty Twenty-Three theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
* @since 6.4.0 Added the Twenty Twenty-Four theme. |
19 | 63 |
* @var string[] |
0 | 64 |
*/ |
65 |
private static $default_themes = array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
'classic' => 'WordPress Classic', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
'default' => 'WordPress Default', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
68 |
'twentyten' => 'Twenty Ten', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
69 |
'twentyeleven' => 'Twenty Eleven', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
70 |
'twentytwelve' => 'Twenty Twelve', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
71 |
'twentythirteen' => 'Twenty Thirteen', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
72 |
'twentyfourteen' => 'Twenty Fourteen', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
73 |
'twentyfifteen' => 'Twenty Fifteen', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
74 |
'twentysixteen' => 'Twenty Sixteen', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
75 |
'twentyseventeen' => 'Twenty Seventeen', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
'twentynineteen' => 'Twenty Nineteen', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
77 |
'twentytwenty' => 'Twenty Twenty', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
78 |
'twentytwentyone' => 'Twenty Twenty-One', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
79 |
'twentytwentytwo' => 'Twenty Twenty-Two', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
80 |
'twentytwentythree' => 'Twenty Twenty-Three', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
81 |
'twentytwentyfour' => 'Twenty Twenty-Four', |
5 | 82 |
); |
83 |
||
84 |
/** |
|
85 |
* Renamed theme tags. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* |
19 | 87 |
* @since 3.8.0 |
88 |
* @var string[] |
|
5 | 89 |
*/ |
90 |
private static $tag_map = array( |
|
91 |
'fixed-width' => 'fixed-layout', |
|
92 |
'flexible-width' => 'fluid-layout', |
|
0 | 93 |
); |
94 |
||
95 |
/** |
|
96 |
* Absolute path to the theme root, usually wp-content/themes |
|
97 |
* |
|
19 | 98 |
* @since 3.4.0 |
0 | 99 |
* @var string |
100 |
*/ |
|
101 |
private $theme_root; |
|
102 |
||
103 |
/** |
|
104 |
* Header data from the theme's style.css file. |
|
105 |
* |
|
19 | 106 |
* @since 3.4.0 |
0 | 107 |
* @var array |
108 |
*/ |
|
109 |
private $headers = array(); |
|
110 |
||
111 |
/** |
|
112 |
* Header data from the theme's style.css file after being sanitized. |
|
113 |
* |
|
19 | 114 |
* @since 3.4.0 |
0 | 115 |
* @var array |
116 |
*/ |
|
117 |
private $headers_sanitized; |
|
118 |
||
119 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
120 |
* Is this theme a block theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
121 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
* @var bool |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
private $block_theme; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
/** |
0 | 128 |
* Header name from the theme's style.css after being translated. |
129 |
* |
|
130 |
* Cached due to sorting functions running over the translated name. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* |
19 | 132 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
* @var string |
0 | 134 |
*/ |
135 |
private $name_translated; |
|
136 |
||
137 |
/** |
|
138 |
* Errors encountered when initializing the theme. |
|
139 |
* |
|
19 | 140 |
* @since 3.4.0 |
0 | 141 |
* @var WP_Error |
142 |
*/ |
|
143 |
private $errors; |
|
144 |
||
145 |
/** |
|
146 |
* The directory name of the theme's files, inside the theme root. |
|
147 |
* |
|
148 |
* In the case of a child theme, this is directory name of the child theme. |
|
149 |
* Otherwise, 'stylesheet' is the same as 'template'. |
|
150 |
* |
|
19 | 151 |
* @since 3.4.0 |
0 | 152 |
* @var string |
153 |
*/ |
|
154 |
private $stylesheet; |
|
155 |
||
156 |
/** |
|
157 |
* The directory name of the theme's files, inside the theme root. |
|
158 |
* |
|
159 |
* In the case of a child theme, this is the directory name of the parent theme. |
|
160 |
* Otherwise, 'template' is the same as 'stylesheet'. |
|
161 |
* |
|
19 | 162 |
* @since 3.4.0 |
0 | 163 |
* @var string |
164 |
*/ |
|
165 |
private $template; |
|
166 |
||
167 |
/** |
|
168 |
* A reference to the parent theme, in the case of a child theme. |
|
169 |
* |
|
19 | 170 |
* @since 3.4.0 |
0 | 171 |
* @var WP_Theme |
172 |
*/ |
|
173 |
private $parent; |
|
174 |
||
175 |
/** |
|
176 |
* URL to the theme root, usually an absolute URL to wp-content/themes |
|
177 |
* |
|
19 | 178 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* @var string |
0 | 180 |
*/ |
181 |
private $theme_root_uri; |
|
182 |
||
183 |
/** |
|
184 |
* Flag for whether the theme's textdomain is loaded. |
|
185 |
* |
|
19 | 186 |
* @since 3.4.0 |
0 | 187 |
* @var bool |
188 |
*/ |
|
189 |
private $textdomain_loaded; |
|
190 |
||
191 |
/** |
|
192 |
* Stores an md5 hash of the theme root, to function as the cache key. |
|
193 |
* |
|
19 | 194 |
* @since 3.4.0 |
0 | 195 |
* @var string |
196 |
*/ |
|
197 |
private $cache_hash; |
|
198 |
||
199 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
* Block template folders. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
201 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
* @var string[] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
204 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
private $block_template_folders; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
206 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
* Default values for template folders. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
209 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
210 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
211 |
* @var string[] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
212 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
213 |
private $default_template_folders = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
214 |
'wp_template' => 'templates', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
215 |
'wp_template_part' => 'parts', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
216 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
217 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
218 |
/** |
0 | 219 |
* Flag for whether the themes cache bucket should be persistently cached. |
220 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
* Default is false. Can be set with the {@see 'wp_cache_themes_persistently'} filter. |
0 | 222 |
* |
19 | 223 |
* @since 3.4.0 |
0 | 224 |
* @var bool |
225 |
*/ |
|
226 |
private static $persistently_cache; |
|
227 |
||
228 |
/** |
|
229 |
* Expiration time for the themes cache bucket. |
|
230 |
* |
|
231 |
* By default the bucket is not cached, so this value is useless. |
|
232 |
* |
|
19 | 233 |
* @since 3.4.0 |
0 | 234 |
* @var bool |
235 |
*/ |
|
236 |
private static $cache_expiration = 1800; |
|
237 |
||
238 |
/** |
|
239 |
* Constructor for WP_Theme. |
|
240 |
* |
|
16 | 241 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* |
16 | 245 |
* @param string $theme_dir Directory of the theme within the theme_root. |
246 |
* @param string $theme_root Theme root. |
|
247 |
* @param WP_Theme|null $_child If this theme is a parent theme, the child may be passed for validation purposes. |
|
0 | 248 |
*/ |
249 |
public function __construct( $theme_dir, $theme_root, $_child = null ) { |
|
250 |
global $wp_theme_directories; |
|
251 |
||
252 |
// Initialize caching on first run. |
|
253 |
if ( ! isset( self::$persistently_cache ) ) { |
|
5 | 254 |
/** This action is documented in wp-includes/theme.php */ |
0 | 255 |
self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' ); |
256 |
if ( self::$persistently_cache ) { |
|
257 |
wp_cache_add_global_groups( 'themes' ); |
|
9 | 258 |
if ( is_int( self::$persistently_cache ) ) { |
0 | 259 |
self::$cache_expiration = self::$persistently_cache; |
9 | 260 |
} |
0 | 261 |
} else { |
262 |
wp_cache_add_non_persistent_groups( 'themes' ); |
|
263 |
} |
|
264 |
} |
|
265 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
// Handle a numeric theme directory as a string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
267 |
$theme_dir = (string) $theme_dir; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
|
0 | 269 |
$this->theme_root = $theme_root; |
270 |
$this->stylesheet = $theme_dir; |
|
271 |
||
272 |
// Correct a situation where the theme is 'some-directory/some-theme' but 'some-directory' was passed in as part of the theme root instead. |
|
16 | 273 |
if ( ! in_array( $theme_root, (array) $wp_theme_directories, true ) |
274 |
&& in_array( dirname( $theme_root ), (array) $wp_theme_directories, true ) |
|
275 |
) { |
|
0 | 276 |
$this->stylesheet = basename( $this->theme_root ) . '/' . $this->stylesheet; |
277 |
$this->theme_root = dirname( $theme_root ); |
|
278 |
} |
|
279 |
||
280 |
$this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet ); |
|
9 | 281 |
$theme_file = $this->stylesheet . '/style.css'; |
0 | 282 |
|
283 |
$cache = $this->cache_get( 'theme' ); |
|
284 |
||
285 |
if ( is_array( $cache ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
286 |
foreach ( array( 'block_template_folders', 'block_theme', 'errors', 'headers', 'template' ) as $key ) { |
9 | 287 |
if ( isset( $cache[ $key ] ) ) { |
0 | 288 |
$this->$key = $cache[ $key ]; |
9 | 289 |
} |
0 | 290 |
} |
9 | 291 |
if ( $this->errors ) { |
0 | 292 |
return; |
9 | 293 |
} |
294 |
if ( isset( $cache['theme_root_template'] ) ) { |
|
0 | 295 |
$theme_root_template = $cache['theme_root_template']; |
9 | 296 |
} |
0 | 297 |
} elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) { |
298 |
$this->headers['Name'] = $this->stylesheet; |
|
9 | 299 |
if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) { |
16 | 300 |
$this->errors = new WP_Error( |
301 |
'theme_not_found', |
|
302 |
sprintf( |
|
303 |
/* translators: %s: Theme directory name. */ |
|
304 |
__( 'The theme directory "%s" does not exist.' ), |
|
305 |
esc_html( $this->stylesheet ) |
|
306 |
) |
|
307 |
); |
|
9 | 308 |
} else { |
0 | 309 |
$this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) ); |
9 | 310 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
311 |
$this->template = $this->stylesheet; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
312 |
$this->block_theme = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
313 |
$this->block_template_folders = $this->default_template_folders; |
9 | 314 |
$this->cache_add( |
315 |
'theme', |
|
316 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
317 |
'block_template_folders' => $this->block_template_folders, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
318 |
'block_theme' => $this->block_theme, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
319 |
'headers' => $this->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
320 |
'errors' => $this->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
'stylesheet' => $this->stylesheet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
322 |
'template' => $this->template, |
9 | 323 |
) |
324 |
); |
|
325 |
if ( ! file_exists( $this->theme_root ) ) { // Don't cache this one. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
326 |
$this->errors->add( 'theme_root_missing', __( '<strong>Error:</strong> The themes directory is either empty or does not exist. Please check your installation.' ) ); |
9 | 327 |
} |
0 | 328 |
return; |
329 |
} elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
$this->headers['Name'] = $this->stylesheet; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
331 |
$this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
$this->template = $this->stylesheet; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
$this->block_theme = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
334 |
$this->block_template_folders = $this->default_template_folders; |
9 | 335 |
$this->cache_add( |
336 |
'theme', |
|
337 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
'block_template_folders' => $this->block_template_folders, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
'block_theme' => $this->block_theme, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
340 |
'headers' => $this->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
'errors' => $this->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
342 |
'stylesheet' => $this->stylesheet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
343 |
'template' => $this->template, |
9 | 344 |
) |
345 |
); |
|
0 | 346 |
return; |
347 |
} else { |
|
348 |
$this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
349 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
350 |
* Default themes always trump their pretenders. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
* Properly identify default themes that are inside a directory within wp-content/themes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
352 |
*/ |
16 | 353 |
$default_theme_slug = array_search( $this->headers['Name'], self::$default_themes, true ); |
354 |
if ( $default_theme_slug ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
355 |
if ( basename( $this->stylesheet ) !== $default_theme_slug ) { |
0 | 356 |
$this->headers['Name'] .= '/' . $this->stylesheet; |
9 | 357 |
} |
0 | 358 |
} |
359 |
} |
|
360 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
if ( ! $this->template && $this->stylesheet === $this->headers['Template'] ) { |
16 | 362 |
$this->errors = new WP_Error( |
363 |
'theme_child_invalid', |
|
364 |
sprintf( |
|
365 |
/* translators: %s: Template. */ |
|
366 |
__( 'The theme defines itself as its parent theme. Please check the %s header.' ), |
|
367 |
'<code>Template</code>' |
|
368 |
) |
|
369 |
); |
|
9 | 370 |
$this->cache_add( |
371 |
'theme', |
|
372 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
'block_template_folders' => $this->get_block_template_folders(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
'block_theme' => $this->is_block_theme(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
375 |
'headers' => $this->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
376 |
'errors' => $this->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
377 |
'stylesheet' => $this->stylesheet, |
9 | 378 |
) |
379 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
381 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
|
0 | 384 |
// (If template is set from cache [and there are no errors], we know it's good.) |
16 | 385 |
if ( ! $this->template ) { |
386 |
$this->template = $this->headers['Template']; |
|
387 |
} |
|
388 |
||
389 |
if ( ! $this->template ) { |
|
0 | 390 |
$this->template = $this->stylesheet; |
19 | 391 |
$theme_path = $this->theme_root . '/' . $this->stylesheet; |
392 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
if ( ! $this->is_block_theme() && ! file_exists( $theme_path . '/index.php' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
394 |
$error_message = sprintf( |
19 | 395 |
/* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: Template, 5: style.css */ |
396 |
__( 'Template is missing. Standalone themes need to have a %1$s or %2$s template file. <a href="%3$s">Child themes</a> need to have a %4$s header in the %5$s stylesheet.' ), |
|
397 |
'<code>templates/index.html</code>', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
398 |
'<code>index.php</code>', |
9 | 399 |
__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ), |
19 | 400 |
'<code>Template</code>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
401 |
'<code>style.css</code>' |
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 |
$this->errors = new WP_Error( 'theme_no_index', $error_message ); |
9 | 404 |
$this->cache_add( |
405 |
'theme', |
|
406 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
'block_template_folders' => $this->get_block_template_folders(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
408 |
'block_theme' => $this->block_theme, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
'headers' => $this->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
'errors' => $this->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
'stylesheet' => $this->stylesheet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
412 |
'template' => $this->template, |
9 | 413 |
) |
414 |
); |
|
0 | 415 |
return; |
416 |
} |
|
417 |
} |
|
418 |
||
419 |
// If we got our data from cache, we can assume that 'template' is pointing to the right place. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
if ( ! is_array( $cache ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
&& $this->template !== $this->stylesheet |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
&& ! file_exists( $this->theme_root . '/' . $this->template . '/index.php' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
* If we're in a directory of themes inside /themes, look for the parent nearby. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
426 |
* wp-content/themes/directory-of-themes/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
*/ |
16 | 428 |
$parent_dir = dirname( $this->stylesheet ); |
429 |
$directories = search_theme_directories(); |
|
430 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
431 |
if ( '.' !== $parent_dir |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
432 |
&& file_exists( $this->theme_root . '/' . $parent_dir . '/' . $this->template . '/index.php' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
433 |
) { |
0 | 434 |
$this->template = $parent_dir . '/' . $this->template; |
16 | 435 |
} elseif ( $directories && isset( $directories[ $this->template ] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
436 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
437 |
* Look for the template in the search_theme_directories() results, in case it is in another theme root. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
438 |
* We don't look into directories of themes, just the theme root. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
439 |
*/ |
0 | 440 |
$theme_root_template = $directories[ $this->template ]['theme_root']; |
441 |
} else { |
|
442 |
// Parent theme is missing. |
|
16 | 443 |
$this->errors = new WP_Error( |
444 |
'theme_no_parent', |
|
445 |
sprintf( |
|
446 |
/* translators: %s: Theme directory name. */ |
|
447 |
__( 'The parent theme is missing. Please install the "%s" parent theme.' ), |
|
448 |
esc_html( $this->template ) |
|
449 |
) |
|
450 |
); |
|
9 | 451 |
$this->cache_add( |
452 |
'theme', |
|
453 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
454 |
'block_template_folders' => $this->get_block_template_folders(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
455 |
'block_theme' => $this->is_block_theme(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
456 |
'headers' => $this->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
457 |
'errors' => $this->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
458 |
'stylesheet' => $this->stylesheet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
459 |
'template' => $this->template, |
9 | 460 |
) |
461 |
); |
|
0 | 462 |
$this->parent = new WP_Theme( $this->template, $this->theme_root, $this ); |
463 |
return; |
|
464 |
} |
|
465 |
} |
|
466 |
||
467 |
// Set the parent, if we're a child theme. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
if ( $this->template !== $this->stylesheet ) { |
0 | 469 |
// If we are a parent, then there is a problem. Only two generations allowed! Cancel things out. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
470 |
if ( $_child instanceof WP_Theme && $_child->template === $this->stylesheet ) { |
0 | 471 |
$_child->parent = null; |
16 | 472 |
$_child->errors = new WP_Error( |
473 |
'theme_parent_invalid', |
|
474 |
sprintf( |
|
475 |
/* translators: %s: Theme directory name. */ |
|
476 |
__( 'The "%s" theme is not a valid parent theme.' ), |
|
477 |
esc_html( $_child->template ) |
|
478 |
) |
|
479 |
); |
|
9 | 480 |
$_child->cache_add( |
481 |
'theme', |
|
482 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
483 |
'block_template_folders' => $_child->get_block_template_folders(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
484 |
'block_theme' => $_child->is_block_theme(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
485 |
'headers' => $_child->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
486 |
'errors' => $_child->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
'stylesheet' => $_child->stylesheet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
488 |
'template' => $_child->template, |
9 | 489 |
) |
490 |
); |
|
0 | 491 |
// The two themes actually reference each other with the Template header. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
492 |
if ( $_child->stylesheet === $this->template ) { |
16 | 493 |
$this->errors = new WP_Error( |
494 |
'theme_parent_invalid', |
|
495 |
sprintf( |
|
496 |
/* translators: %s: Theme directory name. */ |
|
497 |
__( 'The "%s" theme is not a valid parent theme.' ), |
|
498 |
esc_html( $this->template ) |
|
499 |
) |
|
500 |
); |
|
9 | 501 |
$this->cache_add( |
502 |
'theme', |
|
503 |
array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
504 |
'block_template_folders' => $this->get_block_template_folders(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
505 |
'block_theme' => $this->is_block_theme(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
506 |
'headers' => $this->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
507 |
'errors' => $this->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
508 |
'stylesheet' => $this->stylesheet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
509 |
'template' => $this->template, |
9 | 510 |
) |
511 |
); |
|
0 | 512 |
} |
513 |
return; |
|
514 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
515 |
// Set the parent. Pass the current instance so we can do the checks above and assess errors. |
0 | 516 |
$this->parent = new WP_Theme( $this->template, isset( $theme_root_template ) ? $theme_root_template : $this->theme_root, $this ); |
517 |
} |
|
518 |
||
9 | 519 |
if ( wp_paused_themes()->get( $this->stylesheet ) && ( ! is_wp_error( $this->errors ) || ! isset( $this->errors->errors['theme_paused'] ) ) ) { |
520 |
$this->errors = new WP_Error( 'theme_paused', __( 'This theme failed to load properly and was paused within the admin backend.' ) ); |
|
521 |
} |
|
522 |
||
0 | 523 |
// We're good. If we didn't retrieve from cache, set it. |
524 |
if ( ! is_array( $cache ) ) { |
|
9 | 525 |
$cache = array( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
526 |
'block_theme' => $this->is_block_theme(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
527 |
'block_template_folders' => $this->get_block_template_folders(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
528 |
'headers' => $this->headers, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
529 |
'errors' => $this->errors, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
530 |
'stylesheet' => $this->stylesheet, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
531 |
'template' => $this->template, |
9 | 532 |
); |
0 | 533 |
// If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above. |
9 | 534 |
if ( isset( $theme_root_template ) ) { |
0 | 535 |
$cache['theme_root_template'] = $theme_root_template; |
9 | 536 |
} |
0 | 537 |
$this->cache_add( 'theme', $cache ); |
538 |
} |
|
539 |
} |
|
540 |
||
541 |
/** |
|
542 |
* When converting the object to a string, the theme name is returned. |
|
543 |
* |
|
16 | 544 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
* |
0 | 546 |
* @return string Theme name, ready for display (translated) |
547 |
*/ |
|
548 |
public function __toString() { |
|
9 | 549 |
return (string) $this->display( 'Name' ); |
0 | 550 |
} |
551 |
||
552 |
/** |
|
553 |
* __isset() magic method for properties formerly returned by current_theme_info() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
554 |
* |
16 | 555 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
557 |
* @param string $offset Property to check if set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
558 |
* @return bool Whether the given property is set. |
0 | 559 |
*/ |
560 |
public function __isset( $offset ) { |
|
561 |
static $properties = array( |
|
9 | 562 |
'name', |
563 |
'title', |
|
564 |
'version', |
|
565 |
'parent_theme', |
|
566 |
'template_dir', |
|
567 |
'stylesheet_dir', |
|
568 |
'template', |
|
569 |
'stylesheet', |
|
570 |
'screenshot', |
|
571 |
'description', |
|
572 |
'author', |
|
573 |
'tags', |
|
574 |
'theme_root', |
|
575 |
'theme_root_uri', |
|
0 | 576 |
); |
577 |
||
16 | 578 |
return in_array( $offset, $properties, true ); |
0 | 579 |
} |
580 |
||
581 |
/** |
|
582 |
* __get() magic method for properties formerly returned by current_theme_info() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
583 |
* |
16 | 584 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
585 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
* @param string $offset Property to get. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
* @return mixed Property value. |
0 | 588 |
*/ |
589 |
public function __get( $offset ) { |
|
590 |
switch ( $offset ) { |
|
9 | 591 |
case 'name': |
592 |
case 'title': |
|
593 |
return $this->get( 'Name' ); |
|
594 |
case 'version': |
|
595 |
return $this->get( 'Version' ); |
|
596 |
case 'parent_theme': |
|
597 |
return $this->parent() ? $this->parent()->get( 'Name' ) : ''; |
|
598 |
case 'template_dir': |
|
0 | 599 |
return $this->get_template_directory(); |
9 | 600 |
case 'stylesheet_dir': |
0 | 601 |
return $this->get_stylesheet_directory(); |
9 | 602 |
case 'template': |
0 | 603 |
return $this->get_template(); |
9 | 604 |
case 'stylesheet': |
0 | 605 |
return $this->get_stylesheet(); |
9 | 606 |
case 'screenshot': |
0 | 607 |
return $this->get_screenshot( 'relative' ); |
608 |
// 'author' and 'description' did not previously return translated data. |
|
9 | 609 |
case 'description': |
610 |
return $this->display( 'Description' ); |
|
611 |
case 'author': |
|
612 |
return $this->display( 'Author' ); |
|
613 |
case 'tags': |
|
0 | 614 |
return $this->get( 'Tags' ); |
9 | 615 |
case 'theme_root': |
0 | 616 |
return $this->get_theme_root(); |
9 | 617 |
case 'theme_root_uri': |
0 | 618 |
return $this->get_theme_root_uri(); |
619 |
// For cases where the array was converted to an object. |
|
9 | 620 |
default: |
0 | 621 |
return $this->offsetGet( $offset ); |
622 |
} |
|
623 |
} |
|
624 |
||
625 |
/** |
|
626 |
* Method to implement ArrayAccess for keys formerly returned by get_themes() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* |
16 | 628 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* @param mixed $offset |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* @param mixed $value |
0 | 632 |
*/ |
19 | 633 |
#[ReturnTypeWillChange] |
0 | 634 |
public function offsetSet( $offset, $value ) {} |
635 |
||
636 |
/** |
|
637 |
* Method to implement ArrayAccess for keys formerly returned by get_themes() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* |
16 | 639 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
* @param mixed $offset |
0 | 642 |
*/ |
19 | 643 |
#[ReturnTypeWillChange] |
0 | 644 |
public function offsetUnset( $offset ) {} |
645 |
||
646 |
/** |
|
647 |
* Method to implement ArrayAccess for keys formerly returned by get_themes() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
* |
16 | 649 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
* @param mixed $offset |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
* @return bool |
0 | 653 |
*/ |
19 | 654 |
#[ReturnTypeWillChange] |
0 | 655 |
public function offsetExists( $offset ) { |
656 |
static $keys = array( |
|
9 | 657 |
'Name', |
658 |
'Version', |
|
659 |
'Status', |
|
660 |
'Title', |
|
661 |
'Author', |
|
662 |
'Author Name', |
|
663 |
'Author URI', |
|
664 |
'Description', |
|
665 |
'Template', |
|
666 |
'Stylesheet', |
|
667 |
'Template Files', |
|
668 |
'Stylesheet Files', |
|
669 |
'Template Dir', |
|
670 |
'Stylesheet Dir', |
|
671 |
'Screenshot', |
|
672 |
'Tags', |
|
673 |
'Theme Root', |
|
674 |
'Theme Root URI', |
|
675 |
'Parent Theme', |
|
0 | 676 |
); |
677 |
||
16 | 678 |
return in_array( $offset, $keys, true ); |
0 | 679 |
} |
680 |
||
681 |
/** |
|
682 |
* Method to implement ArrayAccess for keys formerly returned by get_themes(). |
|
683 |
* |
|
684 |
* Author, Author Name, Author URI, and Description did not previously return |
|
685 |
* translated data. We are doing so now as it is safe to do. However, as |
|
686 |
* Name and Title could have been used as the key for get_themes(), both remain |
|
687 |
* untranslated for back compatibility. This means that ['Name'] is not ideal, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
* and care should be taken to use `$theme::display( 'Name' )` to get a properly |
0 | 689 |
* translated header. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* |
16 | 691 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
* @param mixed $offset |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
* @return mixed |
0 | 695 |
*/ |
19 | 696 |
#[ReturnTypeWillChange] |
0 | 697 |
public function offsetGet( $offset ) { |
698 |
switch ( $offset ) { |
|
9 | 699 |
case 'Name': |
700 |
case 'Title': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
* See note above about using translated data. get() is not ideal. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
* It is only for backward compatibility. Use display(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
*/ |
9 | 705 |
return $this->get( 'Name' ); |
706 |
case 'Author': |
|
707 |
return $this->display( 'Author' ); |
|
708 |
case 'Author Name': |
|
709 |
return $this->display( 'Author', false ); |
|
710 |
case 'Author URI': |
|
711 |
return $this->display( 'AuthorURI' ); |
|
712 |
case 'Description': |
|
713 |
return $this->display( 'Description' ); |
|
714 |
case 'Version': |
|
715 |
case 'Status': |
|
0 | 716 |
return $this->get( $offset ); |
9 | 717 |
case 'Template': |
0 | 718 |
return $this->get_template(); |
9 | 719 |
case 'Stylesheet': |
0 | 720 |
return $this->get_stylesheet(); |
9 | 721 |
case 'Template Files': |
0 | 722 |
return $this->get_files( 'php', 1, true ); |
9 | 723 |
case 'Stylesheet Files': |
0 | 724 |
return $this->get_files( 'css', 0, false ); |
9 | 725 |
case 'Template Dir': |
0 | 726 |
return $this->get_template_directory(); |
9 | 727 |
case 'Stylesheet Dir': |
0 | 728 |
return $this->get_stylesheet_directory(); |
9 | 729 |
case 'Screenshot': |
0 | 730 |
return $this->get_screenshot( 'relative' ); |
9 | 731 |
case 'Tags': |
732 |
return $this->get( 'Tags' ); |
|
733 |
case 'Theme Root': |
|
0 | 734 |
return $this->get_theme_root(); |
9 | 735 |
case 'Theme Root URI': |
0 | 736 |
return $this->get_theme_root_uri(); |
9 | 737 |
case 'Parent Theme': |
738 |
return $this->parent() ? $this->parent()->get( 'Name' ) : ''; |
|
739 |
default: |
|
0 | 740 |
return null; |
741 |
} |
|
742 |
} |
|
743 |
||
744 |
/** |
|
745 |
* Returns errors property. |
|
746 |
* |
|
747 |
* @since 3.4.0 |
|
748 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
* @return WP_Error|false WP_Error if there are errors, or false. |
0 | 750 |
*/ |
751 |
public function errors() { |
|
752 |
return is_wp_error( $this->errors ) ? $this->errors : false; |
|
753 |
} |
|
754 |
||
755 |
/** |
|
19 | 756 |
* Determines whether the theme exists. |
0 | 757 |
* |
758 |
* A theme with errors exists. A theme with the error of 'theme_not_found', |
|
759 |
* meaning that the theme's directory was not found, does not exist. |
|
760 |
* |
|
761 |
* @since 3.4.0 |
|
762 |
* |
|
763 |
* @return bool Whether the theme exists. |
|
764 |
*/ |
|
765 |
public function exists() { |
|
16 | 766 |
return ! ( $this->errors() && in_array( 'theme_not_found', $this->errors()->get_error_codes(), true ) ); |
0 | 767 |
} |
768 |
||
769 |
/** |
|
770 |
* Returns reference to the parent theme. |
|
771 |
* |
|
772 |
* @since 3.4.0 |
|
773 |
* |
|
19 | 774 |
* @return WP_Theme|false Parent theme, or false if the active theme is not a child theme. |
0 | 775 |
*/ |
776 |
public function parent() { |
|
777 |
return isset( $this->parent ) ? $this->parent : false; |
|
778 |
} |
|
779 |
||
780 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
781 |
* Perform reinitialization tasks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
782 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
783 |
* Prevents a callback from being injected during unserialization of an object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
784 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
785 |
public function __wakeup() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
786 |
if ( $this->parent && ! $this->parent instanceof self ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
787 |
throw new UnexpectedValueException(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
788 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
789 |
if ( $this->headers && ! is_array( $this->headers ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
790 |
throw new UnexpectedValueException(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
791 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
792 |
foreach ( $this->headers as $value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
793 |
if ( ! is_string( $value ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
794 |
throw new UnexpectedValueException(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
795 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
796 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
797 |
$this->headers_sanitized = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
798 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
799 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
800 |
/** |
0 | 801 |
* Adds theme data to cache. |
802 |
* |
|
803 |
* Cache entries keyed by the theme and the type of data. |
|
804 |
* |
|
805 |
* @since 3.4.0 |
|
806 |
* |
|
16 | 807 |
* @param string $key Type of data to store (theme, screenshot, headers, post_templates) |
808 |
* @param array|string $data Data to store |
|
0 | 809 |
* @return bool Return value from wp_cache_add() |
810 |
*/ |
|
811 |
private function cache_add( $key, $data ) { |
|
812 |
return wp_cache_add( $key . '-' . $this->cache_hash, $data, 'themes', self::$cache_expiration ); |
|
813 |
} |
|
814 |
||
815 |
/** |
|
816 |
* Gets theme data from cache. |
|
817 |
* |
|
818 |
* Cache entries are keyed by the theme and the type of data. |
|
819 |
* |
|
820 |
* @since 3.4.0 |
|
821 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
* @param string $key Type of data to retrieve (theme, screenshot, headers, post_templates) |
0 | 823 |
* @return mixed Retrieved data |
824 |
*/ |
|
825 |
private function cache_get( $key ) { |
|
826 |
return wp_cache_get( $key . '-' . $this->cache_hash, 'themes' ); |
|
827 |
} |
|
828 |
||
829 |
/** |
|
830 |
* Clears the cache for the theme. |
|
831 |
* |
|
832 |
* @since 3.4.0 |
|
833 |
*/ |
|
834 |
public function cache_delete() { |
|
9 | 835 |
foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key ) { |
0 | 836 |
wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' ); |
9 | 837 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
838 |
$this->template = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
839 |
$this->textdomain_loaded = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
840 |
$this->theme_root_uri = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
841 |
$this->parent = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
842 |
$this->errors = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
843 |
$this->headers_sanitized = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
844 |
$this->name_translated = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
845 |
$this->block_theme = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
846 |
$this->block_template_folders = null; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
847 |
$this->headers = array(); |
0 | 848 |
$this->__construct( $this->stylesheet, $this->theme_root ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
849 |
$this->delete_pattern_cache(); |
0 | 850 |
} |
851 |
||
852 |
/** |
|
19 | 853 |
* Gets a raw, unformatted theme header. |
0 | 854 |
* |
855 |
* The header is sanitized, but is not translated, and is not marked up for display. |
|
856 |
* To get a theme header for display, use the display() method. |
|
857 |
* |
|
858 |
* Use the get_template() method, not the 'Template' header, for finding the template. |
|
859 |
* The 'Template' header is only good for what was written in the style.css, while |
|
860 |
* get_template() takes into account where WordPress actually located the theme and |
|
861 |
* whether it is actually valid. |
|
862 |
* |
|
863 |
* @since 3.4.0 |
|
864 |
* |
|
865 |
* @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
|
16 | 866 |
* @return string|array|false String or array (for Tags header) on success, false on failure. |
0 | 867 |
*/ |
868 |
public function get( $header ) { |
|
9 | 869 |
if ( ! isset( $this->headers[ $header ] ) ) { |
0 | 870 |
return false; |
9 | 871 |
} |
0 | 872 |
|
873 |
if ( ! isset( $this->headers_sanitized ) ) { |
|
874 |
$this->headers_sanitized = $this->cache_get( 'headers' ); |
|
9 | 875 |
if ( ! is_array( $this->headers_sanitized ) ) { |
0 | 876 |
$this->headers_sanitized = array(); |
9 | 877 |
} |
0 | 878 |
} |
879 |
||
9 | 880 |
if ( isset( $this->headers_sanitized[ $header ] ) ) { |
0 | 881 |
return $this->headers_sanitized[ $header ]; |
9 | 882 |
} |
0 | 883 |
|
884 |
// If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets. |
|
885 |
if ( self::$persistently_cache ) { |
|
9 | 886 |
foreach ( array_keys( $this->headers ) as $_header ) { |
0 | 887 |
$this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] ); |
9 | 888 |
} |
0 | 889 |
$this->cache_add( 'headers', $this->headers_sanitized ); |
890 |
} else { |
|
891 |
$this->headers_sanitized[ $header ] = $this->sanitize_header( $header, $this->headers[ $header ] ); |
|
892 |
} |
|
893 |
||
894 |
return $this->headers_sanitized[ $header ]; |
|
895 |
} |
|
896 |
||
897 |
/** |
|
898 |
* Gets a theme header, formatted and translated for display. |
|
899 |
* |
|
900 |
* @since 3.4.0 |
|
901 |
* |
|
16 | 902 |
* @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
903 |
* @param bool $markup Optional. Whether to mark up the header. Defaults to true. |
|
904 |
* @param bool $translate Optional. Whether to translate the header. Defaults to true. |
|
905 |
* @return string|array|false Processed header. An array for Tags if `$markup` is false, string otherwise. |
|
906 |
* False on failure. |
|
0 | 907 |
*/ |
908 |
public function display( $header, $markup = true, $translate = true ) { |
|
909 |
$value = $this->get( $header ); |
|
5 | 910 |
if ( false === $value ) { |
911 |
return false; |
|
912 |
} |
|
0 | 913 |
|
9 | 914 |
if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) { |
0 | 915 |
$translate = false; |
9 | 916 |
} |
0 | 917 |
|
9 | 918 |
if ( $translate ) { |
0 | 919 |
$value = $this->translate_header( $header, $value ); |
9 | 920 |
} |
0 | 921 |
|
9 | 922 |
if ( $markup ) { |
0 | 923 |
$value = $this->markup_header( $header, $value, $translate ); |
9 | 924 |
} |
0 | 925 |
|
926 |
return $value; |
|
927 |
} |
|
928 |
||
929 |
/** |
|
19 | 930 |
* Sanitizes a theme header. |
0 | 931 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
* @since 3.4.0 |
16 | 933 |
* @since 5.4.0 Added support for `Requires at least` and `Requires PHP` headers. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
934 |
* @since 6.1.0 Added support for `Update URI` header. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
* |
16 | 936 |
* @param string $header Theme header. Accepts 'Name', 'Description', 'Author', 'Version', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
937 |
* 'ThemeURI', 'AuthorURI', 'Status', 'Tags', 'RequiresWP', 'RequiresPHP', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
938 |
* 'UpdateURI'. |
16 | 939 |
* @param string $value Value to sanitize. |
940 |
* @return string|array An array for Tags header, string otherwise. |
|
0 | 941 |
*/ |
942 |
private function sanitize_header( $header, $value ) { |
|
943 |
switch ( $header ) { |
|
9 | 944 |
case 'Status': |
0 | 945 |
if ( ! $value ) { |
946 |
$value = 'publish'; |
|
947 |
break; |
|
948 |
} |
|
949 |
// Fall through otherwise. |
|
9 | 950 |
case 'Name': |
0 | 951 |
static $header_tags = array( |
952 |
'abbr' => array( 'title' => true ), |
|
953 |
'acronym' => array( 'title' => true ), |
|
954 |
'code' => true, |
|
955 |
'em' => true, |
|
956 |
'strong' => true, |
|
957 |
); |
|
16 | 958 |
|
959 |
$value = wp_kses( $value, $header_tags ); |
|
0 | 960 |
break; |
9 | 961 |
case 'Author': |
0 | 962 |
// There shouldn't be anchor tags in Author, but some themes like to be challenging. |
9 | 963 |
case 'Description': |
0 | 964 |
static $header_tags_with_a = array( |
9 | 965 |
'a' => array( |
966 |
'href' => true, |
|
967 |
'title' => true, |
|
968 |
), |
|
0 | 969 |
'abbr' => array( 'title' => true ), |
970 |
'acronym' => array( 'title' => true ), |
|
971 |
'code' => true, |
|
972 |
'em' => true, |
|
973 |
'strong' => true, |
|
974 |
); |
|
16 | 975 |
|
976 |
$value = wp_kses( $value, $header_tags_with_a ); |
|
0 | 977 |
break; |
9 | 978 |
case 'ThemeURI': |
979 |
case 'AuthorURI': |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
980 |
$value = sanitize_url( $value ); |
0 | 981 |
break; |
9 | 982 |
case 'Tags': |
0 | 983 |
$value = array_filter( array_map( 'trim', explode( ',', strip_tags( $value ) ) ) ); |
984 |
break; |
|
9 | 985 |
case 'Version': |
16 | 986 |
case 'RequiresWP': |
987 |
case 'RequiresPHP': |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
988 |
case 'UpdateURI': |
5 | 989 |
$value = strip_tags( $value ); |
990 |
break; |
|
0 | 991 |
} |
992 |
||
993 |
return $value; |
|
994 |
} |
|
995 |
||
996 |
/** |
|
19 | 997 |
* Marks up a theme header. |
0 | 998 |
* |
9 | 999 |
* @since 3.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
* |
16 | 1001 |
* @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
1002 |
* @param string|array $value Value to mark up. An array for Tags header, string otherwise. |
|
1003 |
* @param string $translate Whether the header has been translated. |
|
0 | 1004 |
* @return string Value, marked up. |
1005 |
*/ |
|
1006 |
private function markup_header( $header, $value, $translate ) { |
|
1007 |
switch ( $header ) { |
|
9 | 1008 |
case 'Name': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
if ( empty( $value ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
$value = esc_html( $this->get_stylesheet() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
} |
0 | 1012 |
break; |
9 | 1013 |
case 'Description': |
0 | 1014 |
$value = wptexturize( $value ); |
1015 |
break; |
|
9 | 1016 |
case 'Author': |
1017 |
if ( $this->get( 'AuthorURI' ) ) { |
|
5 | 1018 |
$value = sprintf( '<a href="%1$s">%2$s</a>', $this->display( 'AuthorURI', true, $translate ), $value ); |
0 | 1019 |
} elseif ( ! $value ) { |
1020 |
$value = __( 'Anonymous' ); |
|
1021 |
} |
|
1022 |
break; |
|
9 | 1023 |
case 'Tags': |
0 | 1024 |
static $comma = null; |
1025 |
if ( ! isset( $comma ) ) { |
|
19 | 1026 |
$comma = wp_get_list_item_separator(); |
0 | 1027 |
} |
1028 |
$value = implode( $comma, $value ); |
|
1029 |
break; |
|
9 | 1030 |
case 'ThemeURI': |
1031 |
case 'AuthorURI': |
|
0 | 1032 |
$value = esc_url( $value ); |
1033 |
break; |
|
1034 |
} |
|
1035 |
||
1036 |
return $value; |
|
1037 |
} |
|
1038 |
||
1039 |
/** |
|
19 | 1040 |
* Translates a theme header. |
0 | 1041 |
* |
1042 |
* @since 3.4.0 |
|
1043 |
* |
|
16 | 1044 |
* @param string $header Theme header. Name, Description, Author, Version, ThemeURI, AuthorURI, Status, Tags. |
1045 |
* @param string|array $value Value to translate. An array for Tags header, string otherwise. |
|
1046 |
* @return string|array Translated value. An array for Tags header, string otherwise. |
|
0 | 1047 |
*/ |
1048 |
private function translate_header( $header, $value ) { |
|
1049 |
switch ( $header ) { |
|
9 | 1050 |
case 'Name': |
0 | 1051 |
// Cached for sorting reasons. |
9 | 1052 |
if ( isset( $this->name_translated ) ) { |
0 | 1053 |
return $this->name_translated; |
9 | 1054 |
} |
16 | 1055 |
|
9 | 1056 |
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain |
1057 |
$this->name_translated = translate( $value, $this->get( 'TextDomain' ) ); |
|
16 | 1058 |
|
0 | 1059 |
return $this->name_translated; |
9 | 1060 |
case 'Tags': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) { |
0 | 1062 |
return $value; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
} |
0 | 1064 |
|
1065 |
static $tags_list; |
|
1066 |
if ( ! isset( $tags_list ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
$tags_list = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
// As of 4.6, deprecated tags which are only used to provide translation for older themes. |
9 | 1069 |
'black' => __( 'Black' ), |
1070 |
'blue' => __( 'Blue' ), |
|
1071 |
'brown' => __( 'Brown' ), |
|
1072 |
'gray' => __( 'Gray' ), |
|
1073 |
'green' => __( 'Green' ), |
|
1074 |
'orange' => __( 'Orange' ), |
|
1075 |
'pink' => __( 'Pink' ), |
|
1076 |
'purple' => __( 'Purple' ), |
|
1077 |
'red' => __( 'Red' ), |
|
1078 |
'silver' => __( 'Silver' ), |
|
1079 |
'tan' => __( 'Tan' ), |
|
1080 |
'white' => __( 'White' ), |
|
1081 |
'yellow' => __( 'Yellow' ), |
|
19 | 1082 |
'dark' => _x( 'Dark', 'color scheme' ), |
1083 |
'light' => _x( 'Light', 'color scheme' ), |
|
9 | 1084 |
'fixed-layout' => __( 'Fixed Layout' ), |
1085 |
'fluid-layout' => __( 'Fluid Layout' ), |
|
1086 |
'responsive-layout' => __( 'Responsive Layout' ), |
|
1087 |
'blavatar' => __( 'Blavatar' ), |
|
1088 |
'photoblogging' => __( 'Photoblogging' ), |
|
1089 |
'seasonal' => __( 'Seasonal' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
|
16 | 1092 |
$feature_list = get_theme_feature_list( false ); // No API. |
1093 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
foreach ( $feature_list as $tags ) { |
0 | 1095 |
$tags_list += $tags; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
} |
0 | 1097 |
} |
1098 |
||
1099 |
foreach ( $value as &$tag ) { |
|
5 | 1100 |
if ( isset( $tags_list[ $tag ] ) ) { |
0 | 1101 |
$tag = $tags_list[ $tag ]; |
5 | 1102 |
} elseif ( isset( self::$tag_map[ $tag ] ) ) { |
1103 |
$tag = $tags_list[ self::$tag_map[ $tag ] ]; |
|
1104 |
} |
|
0 | 1105 |
} |
1106 |
||
1107 |
return $value; |
|
5 | 1108 |
|
9 | 1109 |
default: |
1110 |
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain |
|
1111 |
$value = translate( $value, $this->get( 'TextDomain' ) ); |
|
0 | 1112 |
} |
1113 |
return $value; |
|
1114 |
} |
|
1115 |
||
1116 |
/** |
|
19 | 1117 |
* Returns the directory name of the theme's "stylesheet" files, inside the theme root. |
0 | 1118 |
* |
1119 |
* In the case of a child theme, this is directory name of the child theme. |
|
1120 |
* Otherwise, get_stylesheet() is the same as get_template(). |
|
1121 |
* |
|
1122 |
* @since 3.4.0 |
|
1123 |
* |
|
1124 |
* @return string Stylesheet |
|
1125 |
*/ |
|
1126 |
public function get_stylesheet() { |
|
1127 |
return $this->stylesheet; |
|
1128 |
} |
|
1129 |
||
1130 |
/** |
|
19 | 1131 |
* Returns the directory name of the theme's "template" files, inside the theme root. |
0 | 1132 |
* |
1133 |
* In the case of a child theme, this is the directory name of the parent theme. |
|
1134 |
* Otherwise, the get_template() is the same as get_stylesheet(). |
|
1135 |
* |
|
1136 |
* @since 3.4.0 |
|
1137 |
* |
|
1138 |
* @return string Template |
|
1139 |
*/ |
|
1140 |
public function get_template() { |
|
1141 |
return $this->template; |
|
1142 |
} |
|
1143 |
||
1144 |
/** |
|
1145 |
* Returns the absolute path to the directory of a theme's "stylesheet" files. |
|
1146 |
* |
|
1147 |
* In the case of a child theme, this is the absolute path to the directory |
|
1148 |
* of the child theme's files. |
|
1149 |
* |
|
1150 |
* @since 3.4.0 |
|
1151 |
* |
|
1152 |
* @return string Absolute path of the stylesheet directory. |
|
1153 |
*/ |
|
1154 |
public function get_stylesheet_directory() { |
|
16 | 1155 |
if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes(), true ) ) { |
0 | 1156 |
return ''; |
9 | 1157 |
} |
0 | 1158 |
|
1159 |
return $this->theme_root . '/' . $this->stylesheet; |
|
1160 |
} |
|
1161 |
||
1162 |
/** |
|
1163 |
* Returns the absolute path to the directory of a theme's "template" files. |
|
1164 |
* |
|
1165 |
* In the case of a child theme, this is the absolute path to the directory |
|
1166 |
* of the parent theme's files. |
|
1167 |
* |
|
1168 |
* @since 3.4.0 |
|
1169 |
* |
|
1170 |
* @return string Absolute path of the template directory. |
|
1171 |
*/ |
|
1172 |
public function get_template_directory() { |
|
9 | 1173 |
if ( $this->parent() ) { |
0 | 1174 |
$theme_root = $this->parent()->theme_root; |
9 | 1175 |
} else { |
0 | 1176 |
$theme_root = $this->theme_root; |
9 | 1177 |
} |
0 | 1178 |
|
1179 |
return $theme_root . '/' . $this->template; |
|
1180 |
} |
|
1181 |
||
1182 |
/** |
|
1183 |
* Returns the URL to the directory of a theme's "stylesheet" files. |
|
1184 |
* |
|
1185 |
* In the case of a child theme, this is the URL to the directory of the |
|
1186 |
* child theme's files. |
|
1187 |
* |
|
1188 |
* @since 3.4.0 |
|
1189 |
* |
|
1190 |
* @return string URL to the stylesheet directory. |
|
1191 |
*/ |
|
1192 |
public function get_stylesheet_directory_uri() { |
|
1193 |
return $this->get_theme_root_uri() . '/' . str_replace( '%2F', '/', rawurlencode( $this->stylesheet ) ); |
|
1194 |
} |
|
1195 |
||
1196 |
/** |
|
1197 |
* Returns the URL to the directory of a theme's "template" files. |
|
1198 |
* |
|
1199 |
* In the case of a child theme, this is the URL to the directory of the |
|
1200 |
* parent theme's files. |
|
1201 |
* |
|
1202 |
* @since 3.4.0 |
|
1203 |
* |
|
1204 |
* @return string URL to the template directory. |
|
1205 |
*/ |
|
1206 |
public function get_template_directory_uri() { |
|
9 | 1207 |
if ( $this->parent() ) { |
0 | 1208 |
$theme_root_uri = $this->parent()->get_theme_root_uri(); |
9 | 1209 |
} else { |
0 | 1210 |
$theme_root_uri = $this->get_theme_root_uri(); |
9 | 1211 |
} |
0 | 1212 |
|
1213 |
return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) ); |
|
1214 |
} |
|
1215 |
||
1216 |
/** |
|
19 | 1217 |
* Returns the absolute path to the directory of the theme root. |
0 | 1218 |
* |
1219 |
* This is typically the absolute path to wp-content/themes. |
|
1220 |
* |
|
1221 |
* @since 3.4.0 |
|
1222 |
* |
|
1223 |
* @return string Theme root. |
|
1224 |
*/ |
|
1225 |
public function get_theme_root() { |
|
1226 |
return $this->theme_root; |
|
1227 |
} |
|
1228 |
||
1229 |
/** |
|
1230 |
* Returns the URL to the directory of the theme root. |
|
1231 |
* |
|
1232 |
* This is typically the absolute URL to wp-content/themes. This forms the basis |
|
1233 |
* for all other URLs returned by WP_Theme, so we pass it to the public function |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
* get_theme_root_uri() and allow it to run the {@see 'theme_root_uri'} filter. |
0 | 1235 |
* |
1236 |
* @since 3.4.0 |
|
1237 |
* |
|
1238 |
* @return string Theme root URI. |
|
1239 |
*/ |
|
1240 |
public function get_theme_root_uri() { |
|
9 | 1241 |
if ( ! isset( $this->theme_root_uri ) ) { |
0 | 1242 |
$this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root ); |
9 | 1243 |
} |
0 | 1244 |
return $this->theme_root_uri; |
1245 |
} |
|
1246 |
||
1247 |
/** |
|
1248 |
* Returns the main screenshot file for the theme. |
|
1249 |
* |
|
1250 |
* The main screenshot is called screenshot.png. gif and jpg extensions are also allowed. |
|
1251 |
* |
|
1252 |
* Screenshots for a theme must be in the stylesheet directory. (In the case of child |
|
1253 |
* themes, parent theme screenshots are not inherited.) |
|
1254 |
* |
|
1255 |
* @since 3.4.0 |
|
1256 |
* |
|
1257 |
* @param string $uri Type of URL to return, either 'relative' or an absolute URI. Defaults to absolute URI. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1258 |
* @return string|false Screenshot file. False if the theme does not have a screenshot. |
0 | 1259 |
*/ |
1260 |
public function get_screenshot( $uri = 'uri' ) { |
|
1261 |
$screenshot = $this->cache_get( 'screenshot' ); |
|
1262 |
if ( $screenshot ) { |
|
16 | 1263 |
if ( 'relative' === $uri ) { |
0 | 1264 |
return $screenshot; |
9 | 1265 |
} |
0 | 1266 |
return $this->get_stylesheet_directory_uri() . '/' . $screenshot; |
1267 |
} elseif ( 0 === $screenshot ) { |
|
1268 |
return false; |
|
1269 |
} |
|
1270 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1271 |
foreach ( array( 'png', 'gif', 'jpg', 'jpeg', 'webp', 'avif' ) as $ext ) { |
0 | 1272 |
if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) { |
1273 |
$this->cache_add( 'screenshot', 'screenshot.' . $ext ); |
|
16 | 1274 |
if ( 'relative' === $uri ) { |
0 | 1275 |
return 'screenshot.' . $ext; |
9 | 1276 |
} |
0 | 1277 |
return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext; |
1278 |
} |
|
1279 |
} |
|
1280 |
||
1281 |
$this->cache_add( 'screenshot', 0 ); |
|
1282 |
return false; |
|
1283 |
} |
|
1284 |
||
1285 |
/** |
|
19 | 1286 |
* Returns files in the theme's directory. |
0 | 1287 |
* |
1288 |
* @since 3.4.0 |
|
1289 |
* |
|
16 | 1290 |
* @param string[]|string $type Optional. Array of extensions to find, string of a single extension, |
1291 |
* or null for all extensions. Default null. |
|
1292 |
* @param int $depth Optional. How deep to search for files. Defaults to a flat scan (0 depth). |
|
1293 |
* -1 depth is infinite. |
|
1294 |
* @param bool $search_parent Optional. Whether to return parent files. Default false. |
|
1295 |
* @return string[] Array of files, keyed by the path to the file relative to the theme's directory, with the values |
|
1296 |
* being absolute paths. |
|
0 | 1297 |
*/ |
1298 |
public function get_files( $type = null, $depth = 0, $search_parent = false ) { |
|
1299 |
$files = (array) self::scandir( $this->get_stylesheet_directory(), $type, $depth ); |
|
1300 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
if ( $search_parent && $this->parent() ) { |
0 | 1302 |
$files += (array) self::scandir( $this->get_template_directory(), $type, $depth ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
} |
0 | 1304 |
|
19 | 1305 |
return array_filter( $files ); |
0 | 1306 |
} |
1307 |
||
1308 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
* Returns the theme's post templates. |
0 | 1310 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
* @since 4.7.0 |
18 | 1312 |
* @since 5.8.0 Include block templates. |
0 | 1313 |
* |
19 | 1314 |
* @return array[] Array of page template arrays, keyed by post type and filename, |
1315 |
* with the value of the translated header name. |
|
0 | 1316 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
public function get_post_templates() { |
19 | 1318 |
// If you screw up your active theme and we invalidate your parent, most things still work. Let it slide. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
if ( $this->errors() && $this->errors()->get_error_codes() !== array( 'theme_parent_invalid' ) ) { |
0 | 1320 |
return array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
} |
0 | 1322 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
$post_templates = $this->cache_get( 'post_templates' ); |
0 | 1324 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
if ( ! is_array( $post_templates ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
$post_templates = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
|
9 | 1328 |
$files = (array) $this->get_files( 'php', 1, true ); |
0 | 1329 |
|
1330 |
foreach ( $files as $file => $full_path ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
if ( ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header ) ) { |
0 | 1332 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
$types = array( 'page' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
$types = explode( ',', _cleanup_header_comment( $type[1] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1338 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
foreach ( $types as $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
$type = sanitize_key( $type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
if ( ! isset( $post_templates[ $type ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
$post_templates[ $type ] = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
$post_templates[ $type ][ $file ] = _cleanup_header_comment( $header[1] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
} |
0 | 1348 |
} |
1349 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1350 |
$this->cache_add( 'post_templates', $post_templates ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1351 |
} |
19 | 1352 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1353 |
if ( current_theme_supports( 'block-templates' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1354 |
$block_templates = get_block_templates( array(), 'wp_template' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1355 |
foreach ( get_post_types( array( 'public' => true ) ) as $type ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1356 |
foreach ( $block_templates as $block_template ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1357 |
if ( ! $block_template->is_custom ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1358 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1359 |
} |
19 | 1360 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1361 |
if ( isset( $block_template->post_types ) && ! in_array( $type, $block_template->post_types, true ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1362 |
continue; |
18 | 1363 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1364 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1365 |
$post_templates[ $type ][ $block_template->slug ] = $block_template->title; |
18 | 1366 |
} |
1367 |
} |
|
0 | 1368 |
} |
1369 |
||
1370 |
if ( $this->load_textdomain() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
foreach ( $post_templates as &$post_type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
foreach ( $post_type as &$post_template ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
$post_template = $this->translate_header( 'Template Name', $post_template ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
} |
0 | 1375 |
} |
1376 |
} |
|
1377 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
return $post_templates; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
* Returns the theme's post templates for a given post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
* @since 3.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
* @since 4.7.0 Added the `$post_type` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
* @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
|
1388 |
* @param string $post_type Optional. Post type to get the templates for. Default 'page'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
* If a post is provided, its post type is used. |
16 | 1390 |
* @return string[] Array of template header names keyed by the template file name. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
public function get_page_templates( $post = null, $post_type = 'page' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1393 |
if ( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
$post_type = get_post_type( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
$post_templates = $this->get_post_templates(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
$post_templates = isset( $post_templates[ $post_type ] ) ? $post_templates[ $post_type ] : array(); |
0 | 1399 |
|
5 | 1400 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
* Filters list of page templates for a theme. |
5 | 1402 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1403 |
* @since 4.9.6 |
5 | 1404 |
* |
16 | 1405 |
* @param string[] $post_templates Array of template header names keyed by the template file name. |
18 | 1406 |
* @param WP_Theme $theme The theme object. |
5 | 1407 |
* @param WP_Post|null $post The post being edited, provided for context, or null. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
* @param string $post_type Post type to get the templates for. |
5 | 1409 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
$post_templates = (array) apply_filters( 'theme_templates', $post_templates, $this, $post, $post_type ); |
5 | 1411 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
* Filters list of page templates for a theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
* The dynamic portion of the hook name, `$post_type`, refers to the post type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
* |
18 | 1417 |
* Possible hook names include: |
1418 |
* |
|
1419 |
* - `theme_post_templates` |
|
1420 |
* - `theme_page_templates` |
|
1421 |
* - `theme_attachment_templates` |
|
1422 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
* @since 3.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
* @since 4.4.0 Converted to allow complete control over the `$page_templates` array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
* @since 4.7.0 Added the `$post_type` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
* |
16 | 1427 |
* @param string[] $post_templates Array of template header names keyed by the template file name. |
18 | 1428 |
* @param WP_Theme $theme The theme object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
* @param WP_Post|null $post The post being edited, provided for context, or null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
* @param string $post_type Post type to get the templates for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
$post_templates = (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
return $post_templates; |
0 | 1435 |
} |
1436 |
||
1437 |
/** |
|
1438 |
* Scans a directory for files of a certain extension. |
|
1439 |
* |
|
1440 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
* @param string $path Absolute path to search. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
* @param array|string|null $extensions Optional. Array of extensions to find, string of a single extension, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
* or null for all extensions. Default null. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
* @param int $depth Optional. How many levels deep to search for files. Accepts 0, 1+, or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
* -1 (infinite depth). Default 0. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
* @param string $relative_path Optional. The basename of the absolute path. Used to control the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1448 |
* returned path for the found files, particularly when this function |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
* recurses to lower depths. Default empty. |
16 | 1450 |
* @return string[]|false Array of files, keyed by the path to the file relative to the `$path` directory prepended |
1451 |
* with `$relative_path`, with the values being absolute paths. False otherwise. |
|
0 | 1452 |
*/ |
1453 |
private static function scandir( $path, $extensions = null, $depth = 0, $relative_path = '' ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
if ( ! is_dir( $path ) ) { |
0 | 1455 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
} |
0 | 1457 |
|
1458 |
if ( $extensions ) { |
|
9 | 1459 |
$extensions = (array) $extensions; |
0 | 1460 |
$_extensions = implode( '|', $extensions ); |
1461 |
} |
|
1462 |
||
1463 |
$relative_path = trailingslashit( $relative_path ); |
|
16 | 1464 |
if ( '/' === $relative_path ) { |
0 | 1465 |
$relative_path = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1466 |
} |
0 | 1467 |
|
1468 |
$results = scandir( $path ); |
|
9 | 1469 |
$files = array(); |
0 | 1470 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
* Filters the array of excluded directories and files while scanning theme folder. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
* @since 4.7.4 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1475 |
* |
9 | 1476 |
* @param string[] $exclusions Array of excluded directories and files. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
$exclusions = (array) apply_filters( 'theme_scandir_exclusions', array( 'CVS', 'node_modules', 'vendor', 'bower_components' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
|
0 | 1480 |
foreach ( $results as $result ) { |
16 | 1481 |
if ( '.' === $result[0] || in_array( $result, $exclusions, true ) ) { |
0 | 1482 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
} |
0 | 1484 |
if ( is_dir( $path . '/' . $result ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
if ( ! $depth ) { |
0 | 1486 |
continue; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
} |
9 | 1488 |
$found = self::scandir( $path . '/' . $result, $extensions, $depth - 1, $relative_path . $result ); |
0 | 1489 |
$files = array_merge_recursive( $files, $found ); |
1490 |
} elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) { |
|
1491 |
$files[ $relative_path . $result ] = $path . '/' . $result; |
|
1492 |
} |
|
1493 |
} |
|
1494 |
||
1495 |
return $files; |
|
1496 |
} |
|
1497 |
||
1498 |
/** |
|
1499 |
* Loads the theme's textdomain. |
|
1500 |
* |
|
16 | 1501 |
* Translation files are not inherited from the parent theme. TODO: If this fails for the |
0 | 1502 |
* child theme, it should probably try to load the parent theme's translations. |
1503 |
* |
|
1504 |
* @since 3.4.0 |
|
1505 |
* |
|
5 | 1506 |
* @return bool True if the textdomain was successfully loaded or has already been loaded. |
9 | 1507 |
* False if no textdomain was specified in the file headers, or if the domain could not be loaded. |
0 | 1508 |
*/ |
1509 |
public function load_textdomain() { |
|
9 | 1510 |
if ( isset( $this->textdomain_loaded ) ) { |
0 | 1511 |
return $this->textdomain_loaded; |
9 | 1512 |
} |
0 | 1513 |
|
9 | 1514 |
$textdomain = $this->get( 'TextDomain' ); |
0 | 1515 |
if ( ! $textdomain ) { |
1516 |
$this->textdomain_loaded = false; |
|
1517 |
return false; |
|
1518 |
} |
|
1519 |
||
1520 |
if ( is_textdomain_loaded( $textdomain ) ) { |
|
1521 |
$this->textdomain_loaded = true; |
|
1522 |
return true; |
|
1523 |
} |
|
1524 |
||
16 | 1525 |
$path = $this->get_stylesheet_directory(); |
1526 |
$domainpath = $this->get( 'DomainPath' ); |
|
1527 |
if ( $domainpath ) { |
|
0 | 1528 |
$path .= $domainpath; |
9 | 1529 |
} else { |
0 | 1530 |
$path .= '/languages'; |
9 | 1531 |
} |
0 | 1532 |
|
1533 |
$this->textdomain_loaded = load_theme_textdomain( $textdomain, $path ); |
|
1534 |
return $this->textdomain_loaded; |
|
1535 |
} |
|
1536 |
||
1537 |
/** |
|
19 | 1538 |
* Determines whether the theme is allowed (multisite only). |
0 | 1539 |
* |
1540 |
* @since 3.4.0 |
|
1541 |
* |
|
16 | 1542 |
* @param string $check Optional. Whether to check only the 'network'-wide settings, the 'site' |
1543 |
* settings, or 'both'. Defaults to 'both'. |
|
1544 |
* @param int $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site. |
|
0 | 1545 |
* @return bool Whether the theme is allowed for the network. Returns true in single-site. |
1546 |
*/ |
|
1547 |
public function is_allowed( $check = 'both', $blog_id = null ) { |
|
9 | 1548 |
if ( ! is_multisite() ) { |
0 | 1549 |
return true; |
9 | 1550 |
} |
0 | 1551 |
|
16 | 1552 |
if ( 'both' === $check || 'network' === $check ) { |
0 | 1553 |
$allowed = self::get_allowed_on_network(); |
9 | 1554 |
if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) { |
0 | 1555 |
return true; |
9 | 1556 |
} |
0 | 1557 |
} |
1558 |
||
16 | 1559 |
if ( 'both' === $check || 'site' === $check ) { |
0 | 1560 |
$allowed = self::get_allowed_on_site( $blog_id ); |
9 | 1561 |
if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) { |
0 | 1562 |
return true; |
9 | 1563 |
} |
0 | 1564 |
} |
1565 |
||
1566 |
return false; |
|
1567 |
} |
|
1568 |
||
1569 |
/** |
|
19 | 1570 |
* Returns whether this theme is a block-based theme or not. |
1571 |
* |
|
1572 |
* @since 5.9.0 |
|
1573 |
* |
|
1574 |
* @return bool |
|
1575 |
*/ |
|
1576 |
public function is_block_theme() { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1577 |
if ( isset( $this->block_theme ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1578 |
return $this->block_theme; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1579 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1580 |
|
19 | 1581 |
$paths_to_index_block_template = array( |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1582 |
$this->get_file_path( '/templates/index.html' ), |
19 | 1583 |
$this->get_file_path( '/block-templates/index.html' ), |
1584 |
); |
|
1585 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1586 |
$this->block_theme = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1587 |
|
19 | 1588 |
foreach ( $paths_to_index_block_template as $path_to_index_block_template ) { |
1589 |
if ( is_file( $path_to_index_block_template ) && is_readable( $path_to_index_block_template ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1590 |
$this->block_theme = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1591 |
break; |
19 | 1592 |
} |
1593 |
} |
|
1594 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1595 |
return $this->block_theme; |
19 | 1596 |
} |
1597 |
||
1598 |
/** |
|
1599 |
* Retrieves the path of a file in the theme. |
|
1600 |
* |
|
1601 |
* Searches in the stylesheet directory before the template directory so themes |
|
1602 |
* which inherit from a parent theme can just override one file. |
|
1603 |
* |
|
1604 |
* @since 5.9.0 |
|
1605 |
* |
|
1606 |
* @param string $file Optional. File to search for in the stylesheet directory. |
|
1607 |
* @return string The path of the file. |
|
1608 |
*/ |
|
1609 |
public function get_file_path( $file = '' ) { |
|
1610 |
$file = ltrim( $file, '/' ); |
|
1611 |
||
1612 |
$stylesheet_directory = $this->get_stylesheet_directory(); |
|
1613 |
$template_directory = $this->get_template_directory(); |
|
1614 |
||
1615 |
if ( empty( $file ) ) { |
|
1616 |
$path = $stylesheet_directory; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1617 |
} elseif ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/' . $file ) ) { |
19 | 1618 |
$path = $stylesheet_directory . '/' . $file; |
1619 |
} else { |
|
1620 |
$path = $template_directory . '/' . $file; |
|
1621 |
} |
|
1622 |
||
1623 |
/** This filter is documented in wp-includes/link-template.php */ |
|
1624 |
return apply_filters( 'theme_file_path', $path, $file ); |
|
1625 |
} |
|
1626 |
||
1627 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
* Determines the latest WordPress default theme that is installed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1630 |
* This hits the filesystem. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
* |
16 | 1632 |
* @since 4.4.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1633 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
* @return WP_Theme|false Object, or false if no theme is installed, which would be bad. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1635 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
public static function get_core_default_theme() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
foreach ( array_reverse( self::$default_themes ) as $slug => $name ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
$theme = wp_get_theme( $slug ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
if ( $theme->exists() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
return $theme; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1641 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1643 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
/** |
0 | 1647 |
* Returns array of stylesheet names of themes allowed on the site or network. |
1648 |
* |
|
1649 |
* @since 3.4.0 |
|
1650 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
* @param int $blog_id Optional. ID of the site. Defaults to the current site. |
9 | 1652 |
* @return string[] Array of stylesheet names. |
0 | 1653 |
*/ |
1654 |
public static function get_allowed( $blog_id = null ) { |
|
5 | 1655 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1656 |
* Filters the array of themes allowed on the network. |
5 | 1657 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1658 |
* Site is provided as context so that a list of network allowed themes can |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
* be filtered further. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1660 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
* @since 4.5.0 |
5 | 1662 |
* |
9 | 1663 |
* @param string[] $allowed_themes An array of theme stylesheet names. |
1664 |
* @param int $blog_id ID of the site. |
|
5 | 1665 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1666 |
$network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id ); |
0 | 1667 |
return $network + self::get_allowed_on_site( $blog_id ); |
1668 |
} |
|
1669 |
||
1670 |
/** |
|
1671 |
* Returns array of stylesheet names of themes allowed on the network. |
|
1672 |
* |
|
1673 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1674 |
* |
9 | 1675 |
* @return string[] Array of stylesheet names. |
0 | 1676 |
*/ |
1677 |
public static function get_allowed_on_network() { |
|
1678 |
static $allowed_themes; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1679 |
if ( ! isset( $allowed_themes ) ) { |
0 | 1680 |
$allowed_themes = (array) get_site_option( 'allowedthemes' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1681 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1682 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1683 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1684 |
* Filters the array of themes allowed on the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1685 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1686 |
* @since MU (3.0.0) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1687 |
* |
9 | 1688 |
* @param string[] $allowed_themes An array of theme stylesheet names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1689 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1690 |
$allowed_themes = apply_filters( 'allowed_themes', $allowed_themes ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1691 |
|
0 | 1692 |
return $allowed_themes; |
1693 |
} |
|
1694 |
||
1695 |
/** |
|
1696 |
* Returns array of stylesheet names of themes allowed on the site. |
|
1697 |
* |
|
1698 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1700 |
* @param int $blog_id Optional. ID of the site. Defaults to the current site. |
9 | 1701 |
* @return string[] Array of stylesheet names. |
0 | 1702 |
*/ |
1703 |
public static function get_allowed_on_site( $blog_id = null ) { |
|
1704 |
static $allowed_themes = array(); |
|
1705 |
||
9 | 1706 |
if ( ! $blog_id || ! is_multisite() ) { |
0 | 1707 |
$blog_id = get_current_blog_id(); |
9 | 1708 |
} |
0 | 1709 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
if ( isset( $allowed_themes[ $blog_id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1711 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1712 |
* Filters the array of themes allowed on the site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1713 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
* |
9 | 1716 |
* @param string[] $allowed_themes An array of theme stylesheet names. |
1717 |
* @param int $blog_id ID of the site. Defaults to current site. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1719 |
return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
} |
0 | 1721 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1722 |
$current = get_current_blog_id() === $blog_id; |
0 | 1723 |
|
1724 |
if ( $current ) { |
|
1725 |
$allowed_themes[ $blog_id ] = get_option( 'allowedthemes' ); |
|
1726 |
} else { |
|
1727 |
switch_to_blog( $blog_id ); |
|
1728 |
$allowed_themes[ $blog_id ] = get_option( 'allowedthemes' ); |
|
1729 |
restore_current_blog(); |
|
1730 |
} |
|
1731 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1732 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1733 |
* This is all super old MU back compat joy. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1734 |
* 'allowedthemes' keys things by stylesheet. 'allowed_themes' keyed things by name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1735 |
*/ |
0 | 1736 |
if ( false === $allowed_themes[ $blog_id ] ) { |
1737 |
if ( $current ) { |
|
1738 |
$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' ); |
|
1739 |
} else { |
|
1740 |
switch_to_blog( $blog_id ); |
|
1741 |
$allowed_themes[ $blog_id ] = get_option( 'allowed_themes' ); |
|
1742 |
restore_current_blog(); |
|
1743 |
} |
|
1744 |
||
1745 |
if ( ! is_array( $allowed_themes[ $blog_id ] ) || empty( $allowed_themes[ $blog_id ] ) ) { |
|
1746 |
$allowed_themes[ $blog_id ] = array(); |
|
1747 |
} else { |
|
1748 |
$converted = array(); |
|
9 | 1749 |
$themes = wp_get_themes(); |
0 | 1750 |
foreach ( $themes as $stylesheet => $theme_data ) { |
9 | 1751 |
if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get( 'Name' ) ] ) ) { |
0 | 1752 |
$converted[ $stylesheet ] = true; |
9 | 1753 |
} |
0 | 1754 |
} |
1755 |
$allowed_themes[ $blog_id ] = $converted; |
|
1756 |
} |
|
1757 |
// Set the option so we never have to go through this pain again. |
|
1758 |
if ( is_admin() && $allowed_themes[ $blog_id ] ) { |
|
1759 |
if ( $current ) { |
|
1760 |
update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); |
|
1761 |
delete_option( 'allowed_themes' ); |
|
1762 |
} else { |
|
1763 |
switch_to_blog( $blog_id ); |
|
1764 |
update_option( 'allowedthemes', $allowed_themes[ $blog_id ] ); |
|
1765 |
delete_option( 'allowed_themes' ); |
|
1766 |
restore_current_blog(); |
|
1767 |
} |
|
1768 |
} |
|
1769 |
} |
|
1770 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
/** This filter is documented in wp-includes/class-wp-theme.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1776 |
* Returns the folder names of the block template directories. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1777 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1778 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1779 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1780 |
* @return string[] { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1781 |
* Folder names used by block themes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1782 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1783 |
* @type string $wp_template Theme-relative directory name for block templates. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1784 |
* @type string $wp_template_part Theme-relative directory name for block template parts. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1785 |
* } |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1786 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1787 |
public function get_block_template_folders() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1788 |
// Return set/cached value if available. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1789 |
if ( isset( $this->block_template_folders ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1790 |
return $this->block_template_folders; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1791 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1792 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1793 |
$this->block_template_folders = $this->default_template_folders; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1794 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1795 |
$stylesheet_directory = $this->get_stylesheet_directory(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1796 |
// If the theme uses deprecated block template folders. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1797 |
if ( file_exists( $stylesheet_directory . '/block-templates' ) || file_exists( $stylesheet_directory . '/block-template-parts' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1798 |
$this->block_template_folders = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1799 |
'wp_template' => 'block-templates', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1800 |
'wp_template_part' => 'block-template-parts', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1801 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1802 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1803 |
return $this->block_template_folders; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1804 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1805 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1806 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1807 |
* Gets block pattern data for a specified theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1808 |
* Each pattern is defined as a PHP file and defines |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1809 |
* its metadata using plugin-style headers. The minimum required definition is: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1810 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1811 |
* /** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1812 |
* * Title: My Pattern |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1813 |
* * Slug: my-theme/my-pattern |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1814 |
* * |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1815 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1816 |
* The output of the PHP source corresponds to the content of the pattern, e.g.: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1817 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1818 |
* <main><p><?php echo "Hello"; ?></p></main> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1819 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1820 |
* If applicable, this will collect from both parent and child theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1821 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1822 |
* Other settable fields include: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1823 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1824 |
* - Description |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1825 |
* - Viewport Width |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1826 |
* - Inserter (yes/no) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1827 |
* - Categories (comma-separated values) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1828 |
* - Keywords (comma-separated values) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1829 |
* - Block Types (comma-separated values) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1830 |
* - Post Types (comma-separated values) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1831 |
* - Template Types (comma-separated values) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1832 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1833 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1834 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1835 |
* @return array Block pattern data. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1836 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1837 |
public function get_block_patterns() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1838 |
$can_use_cached = ! wp_is_development_mode( 'theme' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1839 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1840 |
$pattern_data = $this->get_pattern_cache(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1841 |
if ( is_array( $pattern_data ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1842 |
if ( $can_use_cached ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1843 |
return $pattern_data; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1844 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1845 |
// If in development mode, clear pattern cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1846 |
$this->delete_pattern_cache(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1847 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1848 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1849 |
$dirpath = $this->get_stylesheet_directory() . '/patterns/'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1850 |
$pattern_data = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1851 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1852 |
if ( ! file_exists( $dirpath ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1853 |
if ( $can_use_cached ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1854 |
$this->set_pattern_cache( $pattern_data ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1855 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1856 |
return $pattern_data; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1857 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1858 |
$files = glob( $dirpath . '*.php' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1859 |
if ( ! $files ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1860 |
if ( $can_use_cached ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1861 |
$this->set_pattern_cache( $pattern_data ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1862 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1863 |
return $pattern_data; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1864 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1865 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1866 |
$default_headers = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1867 |
'title' => 'Title', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1868 |
'slug' => 'Slug', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1869 |
'description' => 'Description', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1870 |
'viewportWidth' => 'Viewport Width', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1871 |
'inserter' => 'Inserter', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1872 |
'categories' => 'Categories', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1873 |
'keywords' => 'Keywords', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1874 |
'blockTypes' => 'Block Types', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1875 |
'postTypes' => 'Post Types', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1876 |
'templateTypes' => 'Template Types', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1877 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1878 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1879 |
$properties_to_parse = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1880 |
'categories', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1881 |
'keywords', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1882 |
'blockTypes', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1883 |
'postTypes', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1884 |
'templateTypes', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1885 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1886 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1887 |
foreach ( $files as $file ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1888 |
$pattern = get_file_data( $file, $default_headers ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1889 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1890 |
if ( empty( $pattern['slug'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1891 |
_doing_it_wrong( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1892 |
__FUNCTION__, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1893 |
sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1894 |
/* translators: 1: file name. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1895 |
__( 'Could not register file "%s" as a block pattern ("Slug" field missing)' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1896 |
$file |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1897 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1898 |
'6.0.0' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1899 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1900 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1901 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1902 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1903 |
if ( ! preg_match( '/^[A-z0-9\/_-]+$/', $pattern['slug'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1904 |
_doing_it_wrong( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1905 |
__FUNCTION__, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1906 |
sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1907 |
/* translators: 1: file name; 2: slug value found. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1908 |
__( 'Could not register file "%1$s" as a block pattern (invalid slug "%2$s")' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1909 |
$file, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1910 |
$pattern['slug'] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1911 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1912 |
'6.0.0' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1913 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1914 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1915 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1916 |
// Title is a required property. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1917 |
if ( ! $pattern['title'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1918 |
_doing_it_wrong( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1919 |
__FUNCTION__, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1920 |
sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1921 |
/* translators: 1: file name. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1922 |
__( 'Could not register file "%s" as a block pattern ("Title" field missing)' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1923 |
$file |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1924 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1925 |
'6.0.0' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1926 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1927 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1928 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1929 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1930 |
// For properties of type array, parse data as comma-separated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1931 |
foreach ( $properties_to_parse as $property ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1932 |
if ( ! empty( $pattern[ $property ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1933 |
$pattern[ $property ] = array_filter( wp_parse_list( (string) $pattern[ $property ] ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1934 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1935 |
unset( $pattern[ $property ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1936 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1937 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1938 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1939 |
// Parse properties of type int. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1940 |
$property = 'viewportWidth'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1941 |
if ( ! empty( $pattern[ $property ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1942 |
$pattern[ $property ] = (int) $pattern[ $property ]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1943 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1944 |
unset( $pattern[ $property ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1945 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1946 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1947 |
// Parse properties of type bool. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1948 |
$property = 'inserter'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1949 |
if ( ! empty( $pattern[ $property ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1950 |
$pattern[ $property ] = in_array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1951 |
strtolower( $pattern[ $property ] ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1952 |
array( 'yes', 'true' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1953 |
true |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1954 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1955 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1956 |
unset( $pattern[ $property ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1957 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1958 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1959 |
$key = str_replace( $dirpath, '', $file ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1960 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1961 |
$pattern_data[ $key ] = $pattern; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1962 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1963 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1964 |
if ( $can_use_cached ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1965 |
$this->set_pattern_cache( $pattern_data ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1966 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1967 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1968 |
return $pattern_data; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1969 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1970 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1971 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1972 |
* Gets block pattern cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1973 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1974 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1975 |
* @since 6.6.0 Uses transients to cache regardless of site environment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1976 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1977 |
* @return array|false Returns an array of patterns if cache is found, otherwise false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1978 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1979 |
private function get_pattern_cache() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1980 |
if ( ! $this->exists() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1981 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1982 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1983 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1984 |
$pattern_data = get_site_transient( 'wp_theme_files_patterns-' . $this->cache_hash ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1985 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1986 |
if ( is_array( $pattern_data ) && $pattern_data['version'] === $this->get( 'Version' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1987 |
return $pattern_data['patterns']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1988 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1989 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1990 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1991 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1992 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1993 |
* Sets block pattern cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1994 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1995 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1996 |
* @since 6.6.0 Uses transients to cache regardless of site environment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1997 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1998 |
* @param array $patterns Block patterns data to set in cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1999 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2000 |
private function set_pattern_cache( array $patterns ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2001 |
$pattern_data = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2002 |
'version' => $this->get( 'Version' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2003 |
'patterns' => $patterns, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2004 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2005 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2006 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2007 |
* Filters the cache expiration time for theme files. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2008 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2009 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2010 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2011 |
* @param int $cache_expiration Cache expiration time in seconds. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2012 |
* @param string $cache_type Type of cache being set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2013 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2014 |
$cache_expiration = (int) apply_filters( 'wp_theme_files_cache_ttl', self::$cache_expiration, 'theme_block_patterns' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2015 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2016 |
// We don't want to cache patterns infinitely. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2017 |
if ( $cache_expiration <= 0 ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2018 |
_doing_it_wrong( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2019 |
__METHOD__, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2020 |
sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2021 |
/* translators: %1$s: The filter name.*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2022 |
__( 'The %1$s filter must return an integer value greater than 0.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2023 |
'<code>wp_theme_files_cache_ttl</code>' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2024 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2025 |
'6.6.0' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2026 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2027 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2028 |
$cache_expiration = self::$cache_expiration; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2029 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2030 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2031 |
set_site_transient( 'wp_theme_files_patterns-' . $this->cache_hash, $pattern_data, $cache_expiration ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2032 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2033 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2034 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2035 |
* Clears block pattern cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2036 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2037 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2038 |
* @since 6.6.0 Uses transients to cache regardless of site environment. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2039 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2040 |
public function delete_pattern_cache() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2041 |
delete_site_transient( 'wp_theme_files_patterns-' . $this->cache_hash ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2042 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2043 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2044 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2045 |
* Enables a theme for all sites on the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2047 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
* |
9 | 2049 |
* @param string|string[] $stylesheets Stylesheet name or array of stylesheet names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
public static function network_enable_theme( $stylesheets ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
if ( ! is_array( $stylesheets ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
$stylesheets = array( $stylesheets ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2060 |
$allowed_themes = get_site_option( 'allowedthemes' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
foreach ( $stylesheets as $stylesheet ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2062 |
$allowed_themes[ $stylesheet ] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2063 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2064 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
update_site_option( 'allowedthemes', $allowed_themes ); |
0 | 2066 |
} |
2067 |
||
2068 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
* Disables a theme for all sites on the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
* |
9 | 2073 |
* @param string|string[] $stylesheets Stylesheet name or array of stylesheet names. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
public static function network_disable_theme( $stylesheets ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2078 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2080 |
if ( ! is_array( $stylesheets ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
$stylesheets = array( $stylesheets ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
$allowed_themes = get_site_option( 'allowedthemes' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
foreach ( $stylesheets as $stylesheet ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
if ( isset( $allowed_themes[ $stylesheet ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
unset( $allowed_themes[ $stylesheet ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2088 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2089 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
update_site_option( 'allowedthemes', $allowed_themes ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
* Sorts themes by name. |
0 | 2096 |
* |
2097 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
* |
9 | 2099 |
* @param WP_Theme[] $themes Array of theme objects to sort (passed by reference). |
0 | 2100 |
*/ |
2101 |
public static function sort_by_name( &$themes ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2102 |
if ( str_starts_with( get_user_locale(), 'en_' ) ) { |
0 | 2103 |
uasort( $themes, array( 'WP_Theme', '_name_sort' ) ); |
2104 |
} else { |
|
9 | 2105 |
foreach ( $themes as $key => $theme ) { |
2106 |
$theme->translate_header( 'Name', $theme->headers['Name'] ); |
|
2107 |
} |
|
0 | 2108 |
uasort( $themes, array( 'WP_Theme', '_name_sort_i18n' ) ); |
2109 |
} |
|
2110 |
} |
|
2111 |
||
2112 |
/** |
|
2113 |
* Callback function for usort() to naturally sort themes by name. |
|
2114 |
* |
|
2115 |
* Accesses the Name header directly from the class for maximum speed. |
|
2116 |
* Would choke on HTML but we don't care enough to slow it down with strip_tags(). |
|
2117 |
* |
|
2118 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2119 |
* |
16 | 2120 |
* @param WP_Theme $a First theme. |
2121 |
* @param WP_Theme $b Second theme. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2122 |
* @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2123 |
* Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
0 | 2124 |
*/ |
2125 |
private static function _name_sort( $a, $b ) { |
|
2126 |
return strnatcasecmp( $a->headers['Name'], $b->headers['Name'] ); |
|
2127 |
} |
|
2128 |
||
2129 |
/** |
|
9 | 2130 |
* Callback function for usort() to naturally sort themes by translated name. |
0 | 2131 |
* |
2132 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2133 |
* |
16 | 2134 |
* @param WP_Theme $a First theme. |
2135 |
* @param WP_Theme $b Second theme. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2136 |
* @return int Negative if `$a` falls lower in the natural order than `$b`. Zero if they fall equally. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2137 |
* Greater than 0 if `$a` falls higher in the natural order than `$b`. Used with usort(). |
0 | 2138 |
*/ |
2139 |
private static function _name_sort_i18n( $a, $b ) { |
|
9 | 2140 |
return strnatcasecmp( $a->name_translated, $b->name_translated ); |
0 | 2141 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2142 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2143 |
private static function _check_headers_property_has_correct_type( $headers ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2144 |
if ( ! is_array( $headers ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2145 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2146 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2147 |
foreach ( $headers as $key => $value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2148 |
if ( ! is_string( $key ) || ! is_string( $value ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2149 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2150 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2151 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2152 |
return true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2153 |
} |
0 | 2154 |
} |