wp/wp-includes/functions.wp-styles.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 19 3d72ae0968f4
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    17  *
    17  *
    18  * @return WP_Styles WP_Styles instance.
    18  * @return WP_Styles WP_Styles instance.
    19  */
    19  */
    20 function wp_styles() {
    20 function wp_styles() {
    21 	global $wp_styles;
    21 	global $wp_styles;
       
    22 
    22 	if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    23 	if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    23 		$wp_styles = new WP_Styles();
    24 		$wp_styles = new WP_Styles();
    24 	}
    25 	}
       
    26 
    25 	return $wp_styles;
    27 	return $wp_styles;
    26 }
    28 }
    27 
    29 
    28 /**
    30 /**
    29  * Display styles that are in the $handles queue.
    31  * Display styles that are in the $handles queue.
    35  * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
    37  * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
    36  *
    38  *
    37  * @since 2.6.0
    39  * @since 2.6.0
    38  *
    40  *
    39  * @param string|bool|array $handles Styles to be printed. Default 'false'.
    41  * @param string|bool|array $handles Styles to be printed. Default 'false'.
    40  * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
    42  * @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
    41  */
    43  */
    42 function wp_print_styles( $handles = false ) {
    44 function wp_print_styles( $handles = false ) {
    43 	if ( '' === $handles ) { // for wp_head
    45 	global $wp_styles;
       
    46 
       
    47 	if ( '' === $handles ) { // For 'wp_head'.
    44 		$handles = false;
    48 		$handles = false;
    45 	}
    49 	}
    46 	/**
    50 
    47 	 * Fires before styles in the $handles queue are printed.
       
    48 	 *
       
    49 	 * @since 2.6.0
       
    50 	 */
       
    51 	if ( ! $handles ) {
    51 	if ( ! $handles ) {
       
    52 		/**
       
    53 		 * Fires before styles in the $handles queue are printed.
       
    54 		 *
       
    55 		 * @since 2.6.0
       
    56 		 */
    52 		do_action( 'wp_print_styles' );
    57 		do_action( 'wp_print_styles' );
    53 	}
    58 	}
    54 
    59 
    55 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
    60 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
    56 
    61 
    57 	global $wp_styles;
       
    58 	if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    62 	if ( ! ( $wp_styles instanceof WP_Styles ) ) {
    59 		if ( ! $handles ) {
    63 		if ( ! $handles ) {
    60 			return array(); // No need to instantiate if nothing is there.
    64 			return array(); // No need to instantiate if nothing is there.
    61 		}
    65 		}
    62 	}
    66 	}
    79  * @param string $handle Name of the stylesheet to add the extra styles to.
    83  * @param string $handle Name of the stylesheet to add the extra styles to.
    80  * @param string $data   String containing the CSS styles to be added.
    84  * @param string $data   String containing the CSS styles to be added.
    81  * @return bool True on success, false on failure.
    85  * @return bool True on success, false on failure.
    82  */
    86  */
    83 function wp_add_inline_style( $handle, $data ) {
    87 function wp_add_inline_style( $handle, $data ) {
    84 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
    88 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
    85 
    89 
    86 	if ( false !== stripos( $data, '</style>' ) ) {
    90 	if ( false !== stripos( $data, '</style>' ) ) {
    87 		_doing_it_wrong(
    91 		_doing_it_wrong(
    88 			__FUNCTION__,
    92 			__FUNCTION__,
    89 			sprintf(
    93 			sprintf(
   110  * @since 4.3.0 A return value was added.
   114  * @since 4.3.0 A return value was added.
   111  *
   115  *
   112  * @param string           $handle Name of the stylesheet. Should be unique.
   116  * @param string           $handle Name of the stylesheet. Should be unique.
   113  * @param string|bool      $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   117  * @param string|bool      $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   114  *                                 If source is set to false, stylesheet is an alias of other stylesheets it depends on.
   118  *                                 If source is set to false, stylesheet is an alias of other stylesheets it depends on.
   115  * @param array            $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   119  * @param string[]         $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   116  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   120  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   117  *                                 as a query string for cache busting purposes. If version is set to false, a version
   121  *                                 as a query string for cache busting purposes. If version is set to false, a version
   118  *                                 number is automatically added equal to current installed WordPress version.
   122  *                                 number is automatically added equal to current installed WordPress version.
   119  *                                 If set to null, no version is added.
   123  *                                 If set to null, no version is added.
   120  * @param string           $media  Optional. The media for which this stylesheet has been defined.
   124  * @param string           $media  Optional. The media for which this stylesheet has been defined.
   121  *                                 Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
   125  *                                 Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
   122  *                                 '(orientation: portrait)' and '(max-width: 640px)'.
   126  *                                 '(orientation: portrait)' and '(max-width: 640px)'.
   123  * @return bool Whether the style has been registered. True on success, false on failure.
   127  * @return bool Whether the style has been registered. True on success, false on failure.
   124  */
   128  */
   125 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
   129 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
   126 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   130 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   127 
   131 
   128 	return wp_styles()->add( $handle, $src, $deps, $ver, $media );
   132 	return wp_styles()->add( $handle, $src, $deps, $ver, $media );
   129 }
   133 }
   130 
   134 
   131 /**
   135 /**
   136  * @since 2.1.0
   140  * @since 2.1.0
   137  *
   141  *
   138  * @param string $handle Name of the stylesheet to be removed.
   142  * @param string $handle Name of the stylesheet to be removed.
   139  */
   143  */
   140 function wp_deregister_style( $handle ) {
   144 function wp_deregister_style( $handle ) {
   141 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   145 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   142 
   146 
   143 	wp_styles()->remove( $handle );
   147 	wp_styles()->remove( $handle );
   144 }
   148 }
   145 
   149 
   146 /**
   150 /**
   155  * @since 2.6.0
   159  * @since 2.6.0
   156  *
   160  *
   157  * @param string           $handle Name of the stylesheet. Should be unique.
   161  * @param string           $handle Name of the stylesheet. Should be unique.
   158  * @param string           $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   162  * @param string           $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   159  *                                 Default empty.
   163  *                                 Default empty.
   160  * @param array            $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   164  * @param string[]         $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   161  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   165  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   162  *                                 as a query string for cache busting purposes. If version is set to false, a version
   166  *                                 as a query string for cache busting purposes. If version is set to false, a version
   163  *                                 number is automatically added equal to current installed WordPress version.
   167  *                                 number is automatically added equal to current installed WordPress version.
   164  *                                 If set to null, no version is added.
   168  *                                 If set to null, no version is added.
   165  * @param string           $media  Optional. The media for which this stylesheet has been defined.
   169  * @param string           $media  Optional. The media for which this stylesheet has been defined.
   166  *                                 Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
   170  *                                 Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
   167  *                                 '(orientation: portrait)' and '(max-width: 640px)'.
   171  *                                 '(orientation: portrait)' and '(max-width: 640px)'.
   168  */
   172  */
   169 function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) {
   173 function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) {
   170 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   174 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   171 
   175 
   172 	$wp_styles = wp_styles();
   176 	$wp_styles = wp_styles();
   173 
   177 
   174 	if ( $src ) {
   178 	if ( $src ) {
   175 		$_handle = explode( '?', $handle );
   179 		$_handle = explode( '?', $handle );
   176 		$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
   180 		$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
   177 	}
   181 	}
       
   182 
   178 	$wp_styles->enqueue( $handle );
   183 	$wp_styles->enqueue( $handle );
   179 }
   184 }
   180 
   185 
   181 /**
   186 /**
   182  * Remove a previously enqueued CSS stylesheet.
   187  * Remove a previously enqueued CSS stylesheet.
   186  * @since 3.1.0
   191  * @since 3.1.0
   187  *
   192  *
   188  * @param string $handle Name of the stylesheet to be removed.
   193  * @param string $handle Name of the stylesheet to be removed.
   189  */
   194  */
   190 function wp_dequeue_style( $handle ) {
   195 function wp_dequeue_style( $handle ) {
   191 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   196 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   192 
   197 
   193 	wp_styles()->dequeue( $handle );
   198 	wp_styles()->dequeue( $handle );
   194 }
   199 }
   195 
   200 
   196 /**
   201 /**
   202  * @param string $list   Optional. Status of the stylesheet to check. Default 'enqueued'.
   207  * @param string $list   Optional. Status of the stylesheet to check. Default 'enqueued'.
   203  *                       Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
   208  *                       Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
   204  * @return bool Whether style is queued.
   209  * @return bool Whether style is queued.
   205  */
   210  */
   206 function wp_style_is( $handle, $list = 'enqueued' ) {
   211 function wp_style_is( $handle, $list = 'enqueued' ) {
   207 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   212 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   208 
   213 
   209 	return (bool) wp_styles()->query( $handle, $list );
   214 	return (bool) wp_styles()->query( $handle, $list );
   210 }
   215 }
   211 
   216 
   212 /**
   217 /**
   219  * 'rtl'         bool|string To declare an RTL stylesheet.
   224  * 'rtl'         bool|string To declare an RTL stylesheet.
   220  * 'suffix'      string      Optional suffix, used in combination with RTL.
   225  * 'suffix'      string      Optional suffix, used in combination with RTL.
   221  * 'alt'         bool        For rel="alternate stylesheet".
   226  * 'alt'         bool        For rel="alternate stylesheet".
   222  * 'title'       string      For preferred/alternate stylesheets.
   227  * 'title'       string      For preferred/alternate stylesheets.
   223  *
   228  *
   224  * @see WP_Dependency::add_data()
   229  * @see WP_Dependencies::add_data()
   225  *
   230  *
   226  * @since 3.6.0
   231  * @since 3.6.0
   227  *
   232  *
   228  * @param string $handle Name of the stylesheet.
   233  * @param string $handle Name of the stylesheet.
   229  * @param string $key    Name of data point for which we're storing a value.
   234  * @param string $key    Name of data point for which we're storing a value.