0
|
1 |
<?php |
|
2 |
/** |
|
3 |
* BackPress Styles Procedural API |
|
4 |
* |
|
5 |
* @since 2.6.0 |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage BackPress |
|
9 |
*/ |
|
10 |
|
|
11 |
/** |
|
12 |
* Display styles that are in the $handles queue. |
|
13 |
* |
|
14 |
* Passing an empty array to $handles prints the queue, |
|
15 |
* passing an array with one string prints that style, |
|
16 |
* and passing an array of strings prints those styles. |
|
17 |
* |
|
18 |
* @see do_action() Calls 'wp_print_styles' hook. |
|
19 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
20 |
* |
|
21 |
* @since 2.6.0 |
|
22 |
* |
|
23 |
* @param array|bool $handles Styles to be printed. Default 'false'. |
|
24 |
* @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array. |
|
25 |
*/ |
|
26 |
function wp_print_styles( $handles = false ) { |
|
27 |
if ( '' === $handles ) // for wp_head |
|
28 |
$handles = false; |
|
29 |
|
|
30 |
if ( ! $handles ) |
|
31 |
do_action( 'wp_print_styles' ); |
|
32 |
|
|
33 |
global $wp_styles; |
|
34 |
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|
35 |
if ( ! did_action( 'init' ) ) |
|
36 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
37 |
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); |
|
38 |
|
|
39 |
if ( !$handles ) |
|
40 |
return array(); // No need to instantiate if nothing is there. |
|
41 |
else |
|
42 |
$wp_styles = new WP_Styles(); |
|
43 |
} |
|
44 |
|
|
45 |
return $wp_styles->do_items( $handles ); |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* Add extra CSS styles to a registered stylesheet. |
|
50 |
* |
|
51 |
* Styles will only be added if the stylesheet in already in the queue. |
|
52 |
* Accepts a string $data containing the CSS. If two or more CSS code blocks |
|
53 |
* are added to the same stylesheet $handle, they will be printed in the order |
|
54 |
* they were added, i.e. the latter added styles can redeclare the previous. |
|
55 |
* |
|
56 |
* @see WP_Styles::add_inline_style() |
|
57 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
58 |
* |
|
59 |
* @since 3.3.0 |
|
60 |
* |
|
61 |
* @param string $handle Name of the stylesheet to add the extra styles to. Must be lowercase. |
|
62 |
* @param string $data String containing the CSS styles to be added. |
|
63 |
* @return bool True on success, false on failure. |
|
64 |
*/ |
|
65 |
function wp_add_inline_style( $handle, $data ) { |
|
66 |
global $wp_styles; |
|
67 |
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|
68 |
if ( ! did_action( 'init' ) ) |
|
69 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
70 |
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); |
|
71 |
$wp_styles = new WP_Styles(); |
|
72 |
} |
|
73 |
|
|
74 |
if ( false !== stripos( $data, '</style>' ) ) { |
|
75 |
_doing_it_wrong( __FUNCTION__, 'Do not pass style tags to wp_add_inline_style().', '3.7' ); |
|
76 |
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) ); |
|
77 |
} |
|
78 |
|
|
79 |
return $wp_styles->add_inline_style( $handle, $data ); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Register a CSS stylesheet. |
|
84 |
* |
|
85 |
* @see WP_Dependencies::add() |
|
86 |
* @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types. |
|
87 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
88 |
* |
|
89 |
* @since 2.6.0 |
|
90 |
* |
|
91 |
* @param string $handle Name of the stylesheet. |
|
92 |
* @param string|bool $src Path to the stylesheet from the WordPress root directory. Example: '/css/mystyle.css'. |
|
93 |
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array. |
|
94 |
* @param string|bool $ver String specifying the stylesheet version number. Used to ensure that the correct version |
|
95 |
* is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'. |
|
96 |
* @param string $media Optional. The media for which this stylesheet has been defined. |
|
97 |
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print', |
|
98 |
* 'screen', 'tty', or 'tv'. |
|
99 |
*/ |
|
100 |
function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { |
|
101 |
global $wp_styles; |
|
102 |
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|
103 |
if ( ! did_action( 'init' ) ) |
|
104 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
105 |
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); |
|
106 |
$wp_styles = new WP_Styles(); |
|
107 |
} |
|
108 |
|
|
109 |
$wp_styles->add( $handle, $src, $deps, $ver, $media ); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Remove a registered stylesheet. |
|
114 |
* |
|
115 |
* @see WP_Dependencies::remove() |
|
116 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
117 |
* |
|
118 |
* @since 2.1.0 |
|
119 |
* |
|
120 |
* @param string $handle Name of the stylesheet to be removed. |
|
121 |
*/ |
|
122 |
function wp_deregister_style( $handle ) { |
|
123 |
global $wp_styles; |
|
124 |
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|
125 |
if ( ! did_action( 'init' ) ) |
|
126 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
127 |
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); |
|
128 |
$wp_styles = new WP_Styles(); |
|
129 |
} |
|
130 |
|
|
131 |
$wp_styles->remove( $handle ); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Enqueue a CSS stylesheet. |
|
136 |
* |
|
137 |
* Registers the style if source provided (does NOT overwrite) and enqueues. |
|
138 |
* |
|
139 |
* @see WP_Dependencies::add(), WP_Dependencies::enqueue() |
|
140 |
* @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types. |
|
141 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
142 |
* |
|
143 |
* @since 2.6.0 |
|
144 |
* |
|
145 |
* @param string $handle Name of the stylesheet. |
|
146 |
* @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'. |
|
147 |
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array. |
|
148 |
* @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used |
|
149 |
* to ensure that the correct version is sent to the client regardless of caching, and so |
|
150 |
* should be included if a version number is available and makes sense for the stylesheet. |
|
151 |
* @param string $media Optional. The media for which this stylesheet has been defined. |
|
152 |
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print', |
|
153 |
* 'screen', 'tty', or 'tv'. |
|
154 |
*/ |
|
155 |
function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) { |
|
156 |
global $wp_styles; |
|
157 |
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|
158 |
if ( ! did_action( 'init' ) ) |
|
159 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
160 |
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); |
|
161 |
$wp_styles = new WP_Styles(); |
|
162 |
} |
|
163 |
|
|
164 |
if ( $src ) { |
|
165 |
$_handle = explode('?', $handle); |
|
166 |
$wp_styles->add( $_handle[0], $src, $deps, $ver, $media ); |
|
167 |
} |
|
168 |
$wp_styles->enqueue( $handle ); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Remove a previously enqueued CSS stylesheet. |
|
173 |
* |
|
174 |
* @see WP_Dependencies::dequeue() |
|
175 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
176 |
* |
|
177 |
* @since 3.1.0 |
|
178 |
* |
|
179 |
* @param string $handle Name of the stylesheet to be removed. |
|
180 |
*/ |
|
181 |
function wp_dequeue_style( $handle ) { |
|
182 |
global $wp_styles; |
|
183 |
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|
184 |
if ( ! did_action( 'init' ) ) |
|
185 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
186 |
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); |
|
187 |
$wp_styles = new WP_Styles(); |
|
188 |
} |
|
189 |
|
|
190 |
$wp_styles->dequeue( $handle ); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Check whether a CSS stylesheet has been added to the queue. |
|
195 |
* |
|
196 |
* @global WP_Styles $wp_styles The WP_Styles object for printing styles. |
|
197 |
* |
|
198 |
* @since 2.8.0 |
|
199 |
* |
|
200 |
* @param string $handle Name of the stylesheet. |
|
201 |
* @param string $list Optional. Status of the stylesheet to check. Default 'enqueued'. |
|
202 |
* Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'. |
|
203 |
* @return bool Whether style is queued. |
|
204 |
*/ |
|
205 |
function wp_style_is( $handle, $list = 'enqueued' ) { |
|
206 |
global $wp_styles; |
|
207 |
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|
208 |
if ( ! did_action( 'init' ) ) |
|
209 |
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|
210 |
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); |
|
211 |
$wp_styles = new WP_Styles(); |
|
212 |
} |
|
213 |
|
|
214 |
return (bool) $wp_styles->query( $handle, $list ); |
|
215 |
} |
|
216 |
|
|
217 |
/** |
|
218 |
* Add metadata to a CSS stylesheet. |
|
219 |
* |
|
220 |
* Works only if the stylesheet has already been added. |
|
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. |
|
228 |
* |
|
229 |
* @see WP_Dependency::add_data() |
|
230 |
* |
|
231 |
* @since 3.6.0 |
|
232 |
* |
|
233 |
* @param string $handle Name of the stylesheet. |
|
234 |
* @param string $key Name of data point for which we're storing a value. |
|
235 |
* Accepts 'conditional', 'rtl' and 'suffix', 'alt' and 'title'. |
|
236 |
* @param mixed $data String containing the CSS data to be added. |
|
237 |
* @return bool True on success, false on failure. |
|
238 |
*/ |
|
239 |
function wp_style_add_data( $handle, $key, $value ) { |
|
240 |
global $wp_styles; |
|
241 |
return $wp_styles->add_data( $handle, $key, $value ); |
|
242 |
} |