3 * BackPress Styles Procedural API
8 * @subpackage BackPress
12 * Display styles that are in the $handles queue.
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.
18 * @see do_action() Calls 'wp_print_styles' hook.
19 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
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.
26 function wp_print_styles( $handles = false ) {
27 if ( '' === $handles ) // for wp_head
31 do_action( 'wp_print_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' );
40 return array(); // No need to instantiate if nothing is there.
42 $wp_styles = new WP_Styles();
45 return $wp_styles->do_items( $handles );
49 * Add extra CSS styles to a registered stylesheet.
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.
56 * @see WP_Styles::add_inline_style()
57 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
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.
65 function wp_add_inline_style( $handle, $data ) {
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();
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 ) );
79 return $wp_styles->add_inline_style( $handle, $data );
83 * Register a CSS stylesheet.
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.
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'.
100 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
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();
109 $wp_styles->add( $handle, $src, $deps, $ver, $media );
113 * Remove a registered stylesheet.
115 * @see WP_Dependencies::remove()
116 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
120 * @param string $handle Name of the stylesheet to be removed.
122 function wp_deregister_style( $handle ) {
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();
131 $wp_styles->remove( $handle );
135 * Enqueue a CSS stylesheet.
137 * Registers the style if source provided (does NOT overwrite) and enqueues.
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.
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'.
155 function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
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();
165 $_handle = explode('?', $handle);
166 $wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
168 $wp_styles->enqueue( $handle );
172 * Remove a previously enqueued CSS stylesheet.
174 * @see WP_Dependencies::dequeue()
175 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
179 * @param string $handle Name of the stylesheet to be removed.
181 function wp_dequeue_style( $handle ) {
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();
190 $wp_styles->dequeue( $handle );
194 * Check whether a CSS stylesheet has been added to the queue.
196 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
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.
205 function wp_style_is( $handle, $list = 'enqueued' ) {
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();
214 return (bool) $wp_styles->query( $handle, $list );
218 * Add metadata to a CSS stylesheet.
220 * Works only if the stylesheet has already been added.
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.
229 * @see WP_Dependency::add_data()
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.
239 function wp_style_add_data( $handle, $key, $value ) {
241 return $wp_styles->add_data( $handle, $key, $value );