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