Changeset 31194
- Timestamp:
- 01/16/2015 02:30:08 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/functions.wp-styles.php
r31188 r31194 8 8 * @subpackage BackPress 9 9 */ 10 11 /** 12 * Initialize $wp_styles if it has not been set. 13 * 14 * @global WP_Styles $wp_styles 15 * 16 * @since 4.2.0 17 * 18 * @return WP_Styles 19 */ 20 function wp_styles() { 21 global $wp_styles; 22 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 23 $wp_styles = new WP_Styles(); 24 } 25 return $wp_styles; 26 } 10 27 11 28 /** … … 24 41 */ 25 42 function wp_print_styles( $handles = false ) { 26 if ( '' === $handles ) // for wp_head43 if ( '' === $handles ) { // for wp_head 27 44 $handles = false; 45 } 28 46 /** 29 47 * Fires before styles in the $handles queue are printed. … … 31 49 * @since 2.6.0 32 50 */ 33 if ( ! $handles ) 51 if ( ! $handles ) { 34 52 do_action( 'wp_print_styles' ); 53 } 54 55 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 35 56 36 57 global $wp_styles; 37 58 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 38 if ( ! did_action( 'init' ) ) 39 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 40 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 41 42 if ( !$handles ) 59 if ( ! $handles ) { 43 60 return array(); // No need to instantiate if nothing is there. 44 else 45 $wp_styles = new WP_Styles(); 46 } 47 48 return $wp_styles->do_items( $handles ); 61 } 62 } 63 64 return wp_styles()->do_items( $handles ); 49 65 } 50 66 … … 58 74 * 59 75 * @see WP_Styles::add_inline_style() 60 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.61 76 * 62 77 * @since 3.3.0 … … 67 82 */ 68 83 function wp_add_inline_style( $handle, $data ) { 69 global $wp_styles; 70 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 71 if ( ! did_action( 'init' ) ) 72 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 73 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 74 $wp_styles = new WP_Styles(); 75 } 84 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 76 85 77 86 if ( false !== stripos( $data, '</style>' ) ) { … … 80 89 } 81 90 82 return $wp_styles->add_inline_style( $handle, $data );91 return wp_styles()->add_inline_style( $handle, $data ); 83 92 } 84 93 … … 88 97 * @see WP_Dependencies::add() 89 98 * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types. 90 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.91 99 * 92 100 * @since 2.6.0 … … 102 110 */ 103 111 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { 104 global $wp_styles; 105 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 106 if ( ! did_action( 'init' ) ) 107 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 108 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 109 $wp_styles = new WP_Styles(); 110 } 111 112 $wp_styles->add( $handle, $src, $deps, $ver, $media ); 112 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 113 114 wp_styles()->add( $handle, $src, $deps, $ver, $media ); 113 115 } 114 116 … … 117 119 * 118 120 * @see WP_Dependencies::remove() 119 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.120 121 * 121 122 * @since 2.1.0 … … 124 125 */ 125 126 function wp_deregister_style( $handle ) { 126 global $wp_styles; 127 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 128 if ( ! did_action( 'init' ) ) 129 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 130 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 131 $wp_styles = new WP_Styles(); 132 } 133 134 $wp_styles->remove( $handle ); 127 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 128 129 wp_styles()->remove( $handle ); 135 130 } 136 131 … … 142 137 * @see WP_Dependencies::add(), WP_Dependencies::enqueue() 143 138 * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types. 144 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.145 139 * 146 140 * @since 2.6.0 … … 158 152 function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) { 159 153 global $wp_styles; 160 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 161 if ( ! did_action( 'init' ) ) 162 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 163 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 164 $wp_styles = new WP_Styles(); 165 } 154 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 155 156 $wp_styles = wp_styles(); 166 157 167 158 if ( $src ) { … … 176 167 * 177 168 * @see WP_Dependencies::dequeue() 178 * @global WP_Styles $wp_styles The WP_Styles object for printing styles.179 169 * 180 170 * @since 3.1.0 … … 183 173 */ 184 174 function wp_dequeue_style( $handle ) { 185 global $wp_styles; 186 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 187 if ( ! did_action( 'init' ) ) 188 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 189 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 190 $wp_styles = new WP_Styles(); 191 } 192 193 $wp_styles->dequeue( $handle ); 175 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 176 177 wp_styles()->dequeue( $handle ); 194 178 } 195 179 … … 207 191 */ 208 192 function wp_style_is( $handle, $list = 'enqueued' ) { 209 global $wp_styles; 210 if ( ! ( $wp_styles instanceof WP_Styles ) ) { 211 if ( ! did_action( 'init' ) ) 212 _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), 213 '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' ); 214 $wp_styles = new WP_Styles(); 215 } 216 217 return (bool) $wp_styles->query( $handle, $list ); 193 wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); 194 195 return (bool) wp_styles()->query( $handle, $list ); 218 196 } 219 197 … … 241 219 */ 242 220 function wp_style_add_data( $handle, $key, $value ) { 243 global $wp_styles; 244 return $wp_styles->add_data( $handle, $key, $value ); 245 } 221 return wp_styles()->add_data( $handle, $key, $value ); 222 }
Note: See TracChangeset
for help on using the changeset viewer.