]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/functions.wp-styles.php
Wordpress 3.3
[autoinstalls/wordpress.git] / wp-includes / functions.wp-styles.php
1 <?php
2 /**
3  * BackPress styles procedural API.
4  *
5  * @package BackPress
6  * @since r79
7  */
8
9 /**
10  * Display styles that are in the queue or part of $handles.
11  *
12  * @since r79
13  * @uses do_action() Calls 'wp_print_styles' hook.
14  * @global object $wp_styles The WP_Styles object for printing styles.
15  *
16  * @param array|bool $handles Styles to be printed. An empty array prints the queue,
17  *  an array with one string prints that style, and an array of strings prints those styles.
18  * @return bool True on success, false on failure.
19  */
20 function wp_print_styles( $handles = false ) {
21         do_action( 'wp_print_styles' );
22         if ( '' === $handles ) // for wp_head
23                 $handles = false;
24
25         global $wp_styles;
26         if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
27                 if ( ! did_action( 'init' ) )
28                         _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
29                                 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
30
31                 if ( !$handles )
32                         return array(); // No need to instantiate if nothing is there.
33                 else
34                         $wp_styles = new WP_Styles();
35         }
36
37         return $wp_styles->do_items( $handles );
38 }
39
40 /**
41  * Adds extra CSS.
42  *
43  * Works only if the stylesheet has already been added.
44  * Accepts a string $data containing the CSS. If two or more CSS code blocks are
45  * added to the same stylesheet $handle, they will be printed in the order
46  * they were added, i.e. the latter added styles can redeclare the previous.
47  *
48  * @since 3.3
49  * @see WP_Scripts::add_inline_style()
50  */
51 function wp_add_inline_style( $handle, $data ) {
52         global $wp_styles;
53         if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
54                 if ( ! did_action( 'init' ) )
55                         _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
56                                 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
57                 $wp_styles = new WP_Styles();
58         }
59
60         return $wp_styles->add_inline_style( $handle, $data );
61 }
62
63 /**
64  * Register CSS style file.
65  *
66  * @since r79
67  * @see WP_Styles::add() For additional information.
68  * @global object $wp_styles The WP_Styles object for printing styles.
69  * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
70  *
71  * @param string $handle Name of the stylesheet.
72  * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
73  * @param array $deps Array of handles of any stylesheet that this stylesheet depends on.
74  *  (Stylesheets that must be loaded before this stylesheet.) Pass an empty array if there are no dependencies.
75  * @param string|bool $ver String specifying the stylesheet version number. Set to NULL to disable.
76  *  Used to ensure that the correct version is sent to the client regardless of caching.
77  * @param string $media The media for which this stylesheet has been defined.
78  */
79 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
80         global $wp_styles;
81         if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
82                 if ( ! did_action( 'init' ) )
83                         _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
84                                 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
85                 $wp_styles = new WP_Styles();
86         }
87
88         $wp_styles->add( $handle, $src, $deps, $ver, $media );
89 }
90
91 /**
92  * Remove a registered CSS file.
93  *
94  * @since r79
95  * @see WP_Styles::remove() For additional information.
96  * @global object $wp_styles The WP_Styles object for printing styles.
97  *
98  * @param string $handle Name of the stylesheet.
99  */
100 function wp_deregister_style( $handle ) {
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>init</code>' ), '3.3' );
106                 $wp_styles = new WP_Styles();
107         }
108
109         $wp_styles->remove( $handle );
110 }
111
112 /**
113  * Enqueue a CSS style file.
114  *
115  * Registers the style if src provided (does NOT overwrite) and enqueues.
116  *
117  * @since r79
118  * @see WP_Styles::add(), WP_Styles::enqueue()
119  * @global object $wp_styles The WP_Styles object for printing styles.
120  * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
121  *
122  * @param string $handle Name of the stylesheet.
123  * @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
124  * @param array $deps Array of handles (names) of any stylesheet that this stylesheet depends on.
125  *  (Stylesheets that must be loaded before this stylesheet.) Pass an empty array if there are no dependencies.
126  * @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter
127  *  is used to ensure that the correct version is sent to the client regardless of caching, and so should be included
128  *  if a version number is available and makes sense for the stylesheet.
129  * @param string $media The media for which this stylesheet has been defined.
130  */
131 function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
132         global $wp_styles;
133         if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
134                 if ( ! did_action( 'init' ) )
135                         _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
136                                 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
137                 $wp_styles = new WP_Styles();
138         }
139
140         if ( $src ) {
141                 $_handle = explode('?', $handle);
142                 $wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
143         }
144         $wp_styles->enqueue( $handle );
145 }
146
147 /**
148  * Remove an enqueued style.
149  *
150  * @since WP 3.1
151  * @see WP_Styles::dequeue() For parameter information.
152  */
153 function wp_dequeue_style( $handle ) {
154         global $wp_styles;
155         if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
156                 if ( ! did_action( 'init' ) )
157                         _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
158                                 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
159                 $wp_styles = new WP_Styles();
160         }
161
162         $wp_styles->dequeue( $handle );
163 }
164
165 /**
166  * Check whether style has been added to WordPress Styles.
167  *
168  * The values for list defaults to 'queue', which is the same as wp_enqueue_style().
169  *
170  * @since WP unknown; BP unknown
171  * @global object $wp_styles The WP_Styles object for printing styles.
172  *
173  * @param string $handle Name of the stylesheet.
174  * @param string $list Values are 'registered', 'done', 'queue' and 'to_do'.
175  * @return bool True on success, false on failure.
176  */
177 function wp_style_is( $handle, $list = 'queue' ) {
178         global $wp_styles;
179         if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
180                 if ( ! did_action( 'init' ) )
181                         _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
182                                 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' );
183                 $wp_styles = new WP_Styles();
184         }
185
186         $query = $wp_styles->query( $handle, $list );
187
188         if ( is_object( $query ) )
189                 return true;
190
191         return $query;
192 }