wp/wp-includes/functions.wp-styles.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     7  * @package WordPress
     7  * @package WordPress
     8  * @subpackage Dependencies
     8  * @subpackage Dependencies
     9  */
     9  */
    10 
    10 
    11 /**
    11 /**
    12  * Initialize $wp_styles if it has not been set.
    12  * Initializes $wp_styles if it has not been set.
       
    13  *
       
    14  * @since 4.2.0
    13  *
    15  *
    14  * @global WP_Styles $wp_styles
    16  * @global WP_Styles $wp_styles
    15  *
       
    16  * @since 4.2.0
       
    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;
    26 
    26 
    27 	return $wp_styles;
    27 	return $wp_styles;
    28 }
    28 }
    29 
    29 
    30 /**
    30 /**
    31  * Display styles that are in the $handles queue.
    31  * Displays styles that are in the $handles queue.
    32  *
    32  *
    33  * Passing an empty array to $handles prints the queue,
    33  * Passing an empty array to $handles prints the queue,
    34  * passing an array with one string prints that style,
    34  * passing an array with one string prints that style,
    35  * and passing an array of strings prints those styles.
    35  * and passing an array of strings prints those styles.
    36  *
    36  *
       
    37  * @since 2.6.0
       
    38  *
    37  * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
    39  * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
    38  *
       
    39  * @since 2.6.0
       
    40  *
    40  *
    41  * @param string|bool|array $handles Styles to be printed. Default 'false'.
    41  * @param string|bool|array $handles Styles to be printed. Default 'false'.
    42  * @return string[] On success, an array of handles of processed 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.
    43  */
    43  */
    44 function wp_print_styles( $handles = false ) {
    44 function wp_print_styles( $handles = false ) {
    67 
    67 
    68 	return wp_styles()->do_items( $handles );
    68 	return wp_styles()->do_items( $handles );
    69 }
    69 }
    70 
    70 
    71 /**
    71 /**
    72  * Add extra CSS styles to a registered stylesheet.
    72  * Adds extra CSS styles to a registered stylesheet.
    73  *
    73  *
    74  * Styles will only be added if the stylesheet is already in the queue.
    74  * Styles will only be added if the stylesheet is already in the queue.
    75  * Accepts a string $data containing the CSS. If two or more CSS code blocks
    75  * Accepts a string $data containing the CSS. If two or more CSS code blocks
    76  * are added to the same stylesheet $handle, they will be printed in the order
    76  * are added to the same stylesheet $handle, they will be printed in the order
    77  * they were added, i.e. the latter added styles can redeclare the previous.
    77  * they were added, i.e. the latter added styles can redeclare the previous.
   103 
   103 
   104 	return wp_styles()->add_inline_style( $handle, $data );
   104 	return wp_styles()->add_inline_style( $handle, $data );
   105 }
   105 }
   106 
   106 
   107 /**
   107 /**
   108  * Register a CSS stylesheet.
   108  * Registers a CSS stylesheet.
   109  *
   109  *
   110  * @see WP_Dependencies::add()
   110  * @see WP_Dependencies::add()
   111  * @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
   111  * @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
   112  *
   112  *
   113  * @since 2.6.0
   113  * @since 2.6.0
   114  * @since 4.3.0 A return value was added.
   114  * @since 4.3.0 A return value was added.
   115  *
   115  *
   116  * @param string           $handle Name of the stylesheet. Should be unique.
   116  * @param string           $handle Name of the stylesheet. Should be unique.
   117  * @param string|bool      $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   117  * @param string|false     $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   118  *                                 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.
   119  * @param string[]         $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.
   120  * @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
   121  *                                 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
   122  *                                 number is automatically added equal to current installed WordPress version.
   122  *                                 number is automatically added equal to current installed WordPress version.
   131 
   131 
   132 	return wp_styles()->add( $handle, $src, $deps, $ver, $media );
   132 	return wp_styles()->add( $handle, $src, $deps, $ver, $media );
   133 }
   133 }
   134 
   134 
   135 /**
   135 /**
   136  * Remove a registered stylesheet.
   136  * Removes a registered stylesheet.
   137  *
   137  *
   138  * @see WP_Dependencies::remove()
   138  * @see WP_Dependencies::remove()
   139  *
   139  *
   140  * @since 2.1.0
   140  * @since 2.1.0
   141  *
   141  *
   146 
   146 
   147 	wp_styles()->remove( $handle );
   147 	wp_styles()->remove( $handle );
   148 }
   148 }
   149 
   149 
   150 /**
   150 /**
   151  * Enqueue a CSS stylesheet.
   151  * Enqueues a CSS stylesheet.
   152  *
   152  *
   153  * Registers the style if source provided (does NOT overwrite) and enqueues.
   153  * Registers the style if source provided (does NOT overwrite) and enqueues.
   154  *
   154  *
   155  * @see WP_Dependencies::add()
   155  * @see WP_Dependencies::add()
   156  * @see WP_Dependencies::enqueue()
   156  * @see WP_Dependencies::enqueue()
   182 
   182 
   183 	$wp_styles->enqueue( $handle );
   183 	$wp_styles->enqueue( $handle );
   184 }
   184 }
   185 
   185 
   186 /**
   186 /**
   187  * Remove a previously enqueued CSS stylesheet.
   187  * Removes a previously enqueued CSS stylesheet.
   188  *
   188  *
   189  * @see WP_Dependencies::dequeue()
   189  * @see WP_Dependencies::dequeue()
   190  *
   190  *
   191  * @since 3.1.0
   191  * @since 3.1.0
   192  *
   192  *
   197 
   197 
   198 	wp_styles()->dequeue( $handle );
   198 	wp_styles()->dequeue( $handle );
   199 }
   199 }
   200 
   200 
   201 /**
   201 /**
   202  * Check whether a CSS stylesheet has been added to the queue.
   202  * Checks whether a CSS stylesheet has been added to the queue.
   203  *
   203  *
   204  * @since 2.8.0
   204  * @since 2.8.0
   205  *
   205  *
   206  * @param string $handle Name of the stylesheet.
   206  * @param string $handle Name of the stylesheet.
   207  * @param string $list   Optional. Status of the stylesheet to check. Default 'enqueued'.
   207  * @param string $status Optional. Status of the stylesheet to check. Default 'enqueued'.
   208  *                       Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
   208  *                       Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
   209  * @return bool Whether style is queued.
   209  * @return bool Whether style is queued.
   210  */
   210  */
   211 function wp_style_is( $handle, $list = 'enqueued' ) {
   211 function wp_style_is( $handle, $status = 'enqueued' ) {
   212 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   212 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
   213 
   213 
   214 	return (bool) wp_styles()->query( $handle, $list );
   214 	return (bool) wp_styles()->query( $handle, $status );
   215 }
   215 }
   216 
   216 
   217 /**
   217 /**
   218  * Add metadata to a CSS stylesheet.
   218  * Adds metadata to a CSS stylesheet.
   219  *
   219  *
   220  * Works only if the stylesheet has already been registered.
   220  * Works only if the stylesheet has already been registered.
   221  *
   221  *
   222  * Possible values for $key and $value:
   222  * Possible values for $key and $value:
   223  * 'conditional' string      Comments for IE 6, lte IE 7 etc.
   223  * 'conditional' string      Comments for IE 6, lte IE 7 etc.
   224  * 'rtl'         bool|string To declare an RTL stylesheet.
   224  * 'rtl'         bool|string To declare an RTL stylesheet.
   225  * 'suffix'      string      Optional suffix, used in combination with RTL.
   225  * 'suffix'      string      Optional suffix, used in combination with RTL.
   226  * 'alt'         bool        For rel="alternate stylesheet".
   226  * 'alt'         bool        For rel="alternate stylesheet".
   227  * 'title'       string      For preferred/alternate stylesheets.
   227  * 'title'       string      For preferred/alternate stylesheets.
   228  * 'path'        string      The absolute path to a stylesheet. Stylesheet will
   228  * 'path'        string      The absolute path to a stylesheet. Stylesheet will
   229  *                           load inline when 'path'' is set.
   229  *                           load inline when 'path' is set.
   230  *
   230  *
   231  * @see WP_Dependencies::add_data()
   231  * @see WP_Dependencies::add_data()
   232  *
   232  *
   233  * @since 3.6.0
   233  * @since 3.6.0
   234  * @since 5.8.0 Added 'path' as an official value for $key.
   234  * @since 5.8.0 Added 'path' as an official value for $key.