wp/wp-includes/functions.wp-styles.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * BackPress Styles Procedural API
     3  * Dependencies API: Styles functions
     4  *
     4  *
     5  * @since 2.6.0
     5  * @since 2.6.0
     6  *
     6  *
     7  * @package WordPress
     7  * @package WordPress
     8  * @subpackage BackPress
     8  * @subpackage Dependencies
     9  */
     9  */
    10 
    10 
    11 /**
    11 /**
    12  * Initialize $wp_styles if it has not been set.
    12  * Initialize $wp_styles if it has not been set.
    13  *
    13  *
    74  *
    74  *
    75  * @see WP_Styles::add_inline_style()
    75  * @see WP_Styles::add_inline_style()
    76  *
    76  *
    77  * @since 3.3.0
    77  * @since 3.3.0
    78  *
    78  *
    79  * @param string $handle Name of the stylesheet to add the extra styles to. Must be lowercase.
    79  * @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.
    80  * @param string $data   String containing the CSS styles to be added.
    81  * @return bool True on success, false on failure.
    81  * @return bool True on success, false on failure.
    82  */
    82  */
    83 function wp_add_inline_style( $handle, $data ) {
    83 function wp_add_inline_style( $handle, $data ) {
    84 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
    84 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
    85 
    85 
    86 	if ( false !== stripos( $data, '</style>' ) ) {
    86 	if ( false !== stripos( $data, '</style>' ) ) {
    87 		_doing_it_wrong( __FUNCTION__, __( 'Do not pass style tags to wp_add_inline_style().' ), '3.7' );
    87 		_doing_it_wrong( __FUNCTION__, sprintf(
       
    88 			/* translators: 1: <style>, 2: wp_add_inline_style() */
       
    89 			__( 'Do not pass %1$s tags to %2$s.' ),
       
    90 			'<code>&lt;style&gt;</code>',
       
    91 			'<code>wp_add_inline_style()</code>'
       
    92 		), '3.7.0' );
    88 		$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
    93 		$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
    89 	}
    94 	}
    90 
    95 
    91 	return wp_styles()->add_inline_style( $handle, $data );
    96 	return wp_styles()->add_inline_style( $handle, $data );
    92 }
    97 }
    93 
    98 
    94 /**
    99 /**
    95  * Register a CSS stylesheet.
   100  * Register a CSS stylesheet.
    96  *
   101  *
    97  * @see WP_Dependencies::add()
   102  * @see WP_Dependencies::add()
    98  * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
   103  * @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
    99  *
   104  *
   100  * @since 2.6.0
   105  * @since 2.6.0
   101  *
   106  * @since 4.3.0 A return value was added.
   102  * @param string      $handle Name of the stylesheet.
   107  *
   103  * @param string|bool $src    Path to the stylesheet from the WordPress root directory. Example: '/css/mystyle.css'.
   108  * @param string           $handle Name of the stylesheet. Should be unique.
   104  * @param array       $deps   An array of registered style handles this stylesheet depends on. Default empty array.
   109  * @param string           $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   105  * @param string|bool $ver    String specifying the stylesheet version number. Used to ensure that the correct version
   110  * @param array            $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   106  *                            is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'.
   111  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   107  * @param string      $media  Optional. The media for which this stylesheet has been defined.
   112  *                                 as a query string for cache busting purposes. If version is set to false, a version
   108  *                            Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
   113  *                                 number is automatically added equal to current installed WordPress version.
   109  *                            'screen', 'tty', or 'tv'.
   114  *                                 If set to null, no version is added.
       
   115  * @param string           $media  Optional. The media for which this stylesheet has been defined.
       
   116  *                                 Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
       
   117  *                                 '(orientation: portrait)' and '(max-width: 640px)'.
       
   118  * @return bool Whether the style has been registered. True on success, false on failure.
   110  */
   119  */
   111 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
   120 function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
   112 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   121 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   113 
   122 
   114 	wp_styles()->add( $handle, $src, $deps, $ver, $media );
   123 	return wp_styles()->add( $handle, $src, $deps, $ver, $media );
   115 }
   124 }
   116 
   125 
   117 /**
   126 /**
   118  * Remove a registered stylesheet.
   127  * Remove a registered stylesheet.
   119  *
   128  *
   132 /**
   141 /**
   133  * Enqueue a CSS stylesheet.
   142  * Enqueue a CSS stylesheet.
   134  *
   143  *
   135  * Registers the style if source provided (does NOT overwrite) and enqueues.
   144  * Registers the style if source provided (does NOT overwrite) and enqueues.
   136  *
   145  *
   137  * @see WP_Dependencies::add(), WP_Dependencies::enqueue()
   146  * @see WP_Dependencies::add()
   138  * @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
   147  * @see WP_Dependencies::enqueue()
   139  *
   148  * @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
   140  * @since 2.6.0
   149  *
   141  *
   150  * @since 2.6.0
   142  * @param string      $handle Name of the stylesheet.
   151  *
   143  * @param string|bool $src    Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
   152  * @param string           $handle Name of the stylesheet. Should be unique.
   144  * @param array       $deps   An array of registered style handles this stylesheet depends on. Default empty array.
   153  * @param string           $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   145  * @param string|bool $ver    String specifying the stylesheet version number, if it has one. This parameter is used
   154  *                                 Default empty.
   146  *                            to ensure that the correct version is sent to the client regardless of caching, and so
   155  * @param array            $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   147  *                            should be included if a version number is available and makes sense for the stylesheet.
   156  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   148  * @param string      $media  Optional. The media for which this stylesheet has been defined.
   157  *                                 as a query string for cache busting purposes. If version is set to false, a version
   149  *                            Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
   158  *                                 number is automatically added equal to current installed WordPress version.
   150  *                            'screen', 'tty', or 'tv'.
   159  *                                 If set to null, no version is added.
   151  */
   160  * @param string           $media  Optional. The media for which this stylesheet has been defined.
   152 function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
   161  *                                 Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
   153 	global $wp_styles;
   162  *                                 '(orientation: portrait)' and '(max-width: 640px)'.
       
   163  */
       
   164 function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) {
   154 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   165 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   155 
   166 
   156 	$wp_styles = wp_styles();
   167 	$wp_styles = wp_styles();
   157 
   168 
   158 	if ( $src ) {
   169 	if ( $src ) {
   177 	wp_styles()->dequeue( $handle );
   188 	wp_styles()->dequeue( $handle );
   178 }
   189 }
   179 
   190 
   180 /**
   191 /**
   181  * Check whether a CSS stylesheet has been added to the queue.
   192  * Check whether a CSS stylesheet has been added to the queue.
   182  *
       
   183  * @global WP_Styles $wp_styles The WP_Styles object for printing styles.
       
   184  *
   193  *
   185  * @since 2.8.0
   194  * @since 2.8.0
   186  *
   195  *
   187  * @param string $handle Name of the stylesheet.
   196  * @param string $handle Name of the stylesheet.
   188  * @param string $list   Optional. Status of the stylesheet to check. Default 'enqueued'.
   197  * @param string $list   Optional. Status of the stylesheet to check. Default 'enqueued'.