author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* Dependencies API: Styles functions |
0 | 4 |
* |
5 |
* @since 2.6.0 |
|
6 |
* |
|
7 |
* @package WordPress |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
8 |
* @subpackage Dependencies |
0 | 9 |
*/ |
10 |
||
11 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
* Initializes $wp_styles if it has not been set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
13 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
14 |
* @since 4.2.0 |
5 | 15 |
* |
16 |
* @global WP_Styles $wp_styles |
|
17 |
* |
|
18 |
* @return WP_Styles WP_Styles instance. |
|
19 |
*/ |
|
20 |
function wp_styles() { |
|
21 |
global $wp_styles; |
|
16 | 22 |
|
5 | 23 |
if ( ! ( $wp_styles instanceof WP_Styles ) ) { |
24 |
$wp_styles = new WP_Styles(); |
|
25 |
} |
|
16 | 26 |
|
5 | 27 |
return $wp_styles; |
28 |
} |
|
29 |
||
30 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
* Displays styles that are in the $handles queue. |
0 | 32 |
* |
33 |
* Passing an empty array to $handles prints the queue, |
|
34 |
* passing an array with one string prints that style, |
|
35 |
* and passing an array of strings prints those styles. |
|
36 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
37 |
* @since 2.6.0 |
0 | 38 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
39 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
0 | 40 |
* |
5 | 41 |
* @param string|bool|array $handles Styles to be printed. Default 'false'. |
16 | 42 |
* @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array. |
0 | 43 |
*/ |
44 |
function wp_print_styles( $handles = false ) { |
|
16 | 45 |
global $wp_styles; |
46 |
||
47 |
if ( '' === $handles ) { // For 'wp_head'. |
|
0 | 48 |
$handles = false; |
5 | 49 |
} |
16 | 50 |
|
5 | 51 |
if ( ! $handles ) { |
16 | 52 |
/** |
53 |
* Fires before styles in the $handles queue are printed. |
|
54 |
* |
|
55 |
* @since 2.6.0 |
|
56 |
*/ |
|
5 | 57 |
do_action( 'wp_print_styles' ); |
58 |
} |
|
0 | 59 |
|
5 | 60 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); |
0 | 61 |
|
5 | 62 |
if ( ! ( $wp_styles instanceof WP_Styles ) ) { |
63 |
if ( ! $handles ) { |
|
0 | 64 |
return array(); // No need to instantiate if nothing is there. |
5 | 65 |
} |
0 | 66 |
} |
67 |
||
5 | 68 |
return wp_styles()->do_items( $handles ); |
0 | 69 |
} |
70 |
||
71 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
72 |
* Adds extra CSS styles to a registered stylesheet. |
0 | 73 |
* |
9 | 74 |
* Styles will only be added if the stylesheet is already in the queue. |
0 | 75 |
* Accepts a string $data containing the CSS. If two or more CSS code blocks |
76 |
* are added to the same stylesheet $handle, they will be printed in the order |
|
77 |
* they were added, i.e. the latter added styles can redeclare the previous. |
|
78 |
* |
|
79 |
* @see WP_Styles::add_inline_style() |
|
80 |
* |
|
81 |
* @since 3.3.0 |
|
82 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* @param string $handle Name of the stylesheet to add the extra styles to. |
0 | 84 |
* @param string $data String containing the CSS styles to be added. |
85 |
* @return bool True on success, false on failure. |
|
86 |
*/ |
|
87 |
function wp_add_inline_style( $handle, $data ) { |
|
16 | 88 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); |
0 | 89 |
|
90 |
if ( false !== stripos( $data, '</style>' ) ) { |
|
9 | 91 |
_doing_it_wrong( |
92 |
__FUNCTION__, |
|
93 |
sprintf( |
|
94 |
/* translators: 1: <style>, 2: wp_add_inline_style() */ |
|
95 |
__( 'Do not pass %1$s tags to %2$s.' ), |
|
96 |
'<code><style></code>', |
|
97 |
'<code>wp_add_inline_style()</code>' |
|
98 |
), |
|
99 |
'3.7.0' |
|
100 |
); |
|
0 | 101 |
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) ); |
102 |
} |
|
103 |
||
5 | 104 |
return wp_styles()->add_inline_style( $handle, $data ); |
0 | 105 |
} |
106 |
||
107 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
108 |
* Registers a CSS stylesheet. |
0 | 109 |
* |
110 |
* @see WP_Dependencies::add() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
* @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types. |
0 | 112 |
* |
113 |
* @since 2.6.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
* @since 4.3.0 A return value was added. |
0 | 115 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
* @param string $handle Name of the stylesheet. Should be unique. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
* @param string|false $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. |
9 | 118 |
* If source is set to false, stylesheet is an alias of other stylesheets it depends on. |
16 | 119 |
* @param string[] $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* as a query string for cache busting purposes. If version is set to false, a version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
* number is automatically added equal to current installed WordPress version. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
123 |
* If set to null, no version is added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
* @param string $media Optional. The media for which this stylesheet has been defined. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* '(orientation: portrait)' and '(max-width: 640px)'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* @return bool Whether the style has been registered. True on success, false on failure. |
0 | 128 |
*/ |
129 |
function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { |
|
16 | 130 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); |
0 | 131 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
return wp_styles()->add( $handle, $src, $deps, $ver, $media ); |
0 | 133 |
} |
134 |
||
135 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
136 |
* Removes a registered stylesheet. |
0 | 137 |
* |
138 |
* @see WP_Dependencies::remove() |
|
139 |
* |
|
140 |
* @since 2.1.0 |
|
141 |
* |
|
142 |
* @param string $handle Name of the stylesheet to be removed. |
|
143 |
*/ |
|
144 |
function wp_deregister_style( $handle ) { |
|
16 | 145 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); |
0 | 146 |
|
5 | 147 |
wp_styles()->remove( $handle ); |
0 | 148 |
} |
149 |
||
150 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
151 |
* Enqueues a CSS stylesheet. |
0 | 152 |
* |
153 |
* Registers the style if source provided (does NOT overwrite) and enqueues. |
|
154 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
* @see WP_Dependencies::add() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
* @see WP_Dependencies::enqueue() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
* @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types. |
0 | 158 |
* |
159 |
* @since 2.6.0 |
|
160 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @param string $handle Name of the stylesheet. Should be unique. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* Default empty. |
16 | 164 |
* @param string[] $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
* @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
* as a query string for cache busting purposes. If version is set to false, a version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
* number is automatically added equal to current installed WordPress version. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
* If set to null, no version is added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
* @param string $media Optional. The media for which this stylesheet has been defined. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
* Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
* '(orientation: portrait)' and '(max-width: 640px)'. |
0 | 172 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) { |
16 | 174 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); |
5 | 175 |
|
176 |
$wp_styles = wp_styles(); |
|
0 | 177 |
|
178 |
if ( $src ) { |
|
9 | 179 |
$_handle = explode( '?', $handle ); |
0 | 180 |
$wp_styles->add( $_handle[0], $src, $deps, $ver, $media ); |
181 |
} |
|
16 | 182 |
|
0 | 183 |
$wp_styles->enqueue( $handle ); |
184 |
} |
|
185 |
||
186 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
187 |
* Removes a previously enqueued CSS stylesheet. |
0 | 188 |
* |
189 |
* @see WP_Dependencies::dequeue() |
|
190 |
* |
|
191 |
* @since 3.1.0 |
|
192 |
* |
|
193 |
* @param string $handle Name of the stylesheet to be removed. |
|
194 |
*/ |
|
195 |
function wp_dequeue_style( $handle ) { |
|
16 | 196 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); |
0 | 197 |
|
5 | 198 |
wp_styles()->dequeue( $handle ); |
0 | 199 |
} |
200 |
||
201 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
* Checks whether a CSS stylesheet has been added to the queue. |
0 | 203 |
* |
204 |
* @since 2.8.0 |
|
205 |
* |
|
206 |
* @param string $handle Name of the stylesheet. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
* @param string $status Optional. Status of the stylesheet to check. Default 'enqueued'. |
0 | 208 |
* Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'. |
209 |
* @return bool Whether style is queued. |
|
210 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
211 |
function wp_style_is( $handle, $status = 'enqueued' ) { |
16 | 212 |
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); |
0 | 213 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
214 |
return (bool) wp_styles()->query( $handle, $status ); |
0 | 215 |
} |
216 |
||
217 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
218 |
* Adds metadata to a CSS stylesheet. |
0 | 219 |
* |
19 | 220 |
* Works only if the stylesheet has already been registered. |
0 | 221 |
* |
222 |
* Possible values for $key and $value: |
|
223 |
* 'conditional' string Comments for IE 6, lte IE 7 etc. |
|
224 |
* 'rtl' bool|string To declare an RTL stylesheet. |
|
225 |
* 'suffix' string Optional suffix, used in combination with RTL. |
|
226 |
* 'alt' bool For rel="alternate stylesheet". |
|
227 |
* 'title' string For preferred/alternate stylesheets. |
|
19 | 228 |
* 'path' string The absolute path to a stylesheet. Stylesheet will |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
229 |
* load inline when 'path' is set. |
0 | 230 |
* |
16 | 231 |
* @see WP_Dependencies::add_data() |
0 | 232 |
* |
233 |
* @since 3.6.0 |
|
19 | 234 |
* @since 5.8.0 Added 'path' as an official value for $key. |
235 |
* See {@see wp_maybe_inline_styles()}. |
|
0 | 236 |
* |
237 |
* @param string $handle Name of the stylesheet. |
|
238 |
* @param string $key Name of data point for which we're storing a value. |
|
19 | 239 |
* Accepts 'conditional', 'rtl' and 'suffix', 'alt', 'title' and 'path'. |
5 | 240 |
* @param mixed $value String containing the CSS data to be added. |
0 | 241 |
* @return bool True on success, false on failure. |
242 |
*/ |
|
243 |
function wp_style_add_data( $handle, $key, $value ) { |
|
5 | 244 |
return wp_styles()->add_data( $handle, $key, $value ); |
0 | 245 |
} |