wp/wp-includes/functions.wp-styles.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    65 }
    65 }
    66 
    66 
    67 /**
    67 /**
    68  * Add extra CSS styles to a registered stylesheet.
    68  * Add extra CSS styles to a registered stylesheet.
    69  *
    69  *
    70  * Styles will only be added if the stylesheet in already in the queue.
    70  * Styles will only be added if the stylesheet is already in the queue.
    71  * Accepts a string $data containing the CSS. If two or more CSS code blocks
    71  * Accepts a string $data containing the CSS. If two or more CSS code blocks
    72  * are added to the same stylesheet $handle, they will be printed in the order
    72  * are added to the same stylesheet $handle, they will be printed in the order
    73  * they were added, i.e. the latter added styles can redeclare the previous.
    73  * they were added, i.e. the latter added styles can redeclare the previous.
    74  *
    74  *
    75  * @see WP_Styles::add_inline_style()
    75  * @see WP_Styles::add_inline_style()
    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__, sprintf(
    87 		_doing_it_wrong(
    88 			/* translators: 1: <style>, 2: wp_add_inline_style() */
    88 			__FUNCTION__,
    89 			__( 'Do not pass %1$s tags to %2$s.' ),
    89 			sprintf(
    90 			'<code>&lt;style&gt;</code>',
    90 				/* translators: 1: <style>, 2: wp_add_inline_style() */
    91 			'<code>wp_add_inline_style()</code>'
    91 				__( 'Do not pass %1$s tags to %2$s.' ),
    92 		), '3.7.0' );
    92 				'<code>&lt;style&gt;</code>',
       
    93 				'<code>wp_add_inline_style()</code>'
       
    94 			),
       
    95 			'3.7.0'
       
    96 		);
    93 		$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
    97 		$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
    94 	}
    98 	}
    95 
    99 
    96 	return wp_styles()->add_inline_style( $handle, $data );
   100 	return wp_styles()->add_inline_style( $handle, $data );
    97 }
   101 }
   104  *
   108  *
   105  * @since 2.6.0
   109  * @since 2.6.0
   106  * @since 4.3.0 A return value was added.
   110  * @since 4.3.0 A return value was added.
   107  *
   111  *
   108  * @param string           $handle Name of the stylesheet. Should be unique.
   112  * @param string           $handle Name of the stylesheet. Should be unique.
   109  * @param string           $src    Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
   113  * @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.
   110  * @param array            $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   115  * @param array            $deps   Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
   111  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   116  * @param string|bool|null $ver    Optional. String specifying stylesheet version number, if it has one, which is added to the URL
   112  *                                 as a query string for cache busting purposes. If version is set to false, a version
   117  *                                 as a query string for cache busting purposes. If version is set to false, a version
   113  *                                 number is automatically added equal to current installed WordPress version.
   118  *                                 number is automatically added equal to current installed WordPress version.
   114  *                                 If set to null, no version is added.
   119  *                                 If set to null, no version is added.
   165 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   170 	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
   166 
   171 
   167 	$wp_styles = wp_styles();
   172 	$wp_styles = wp_styles();
   168 
   173 
   169 	if ( $src ) {
   174 	if ( $src ) {
   170 		$_handle = explode('?', $handle);
   175 		$_handle = explode( '?', $handle );
   171 		$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
   176 		$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
   172 	}
   177 	}
   173 	$wp_styles->enqueue( $handle );
   178 	$wp_styles->enqueue( $handle );
   174 }
   179 }
   175 
   180