2008-05-21 01:56:04 -04:00
|
|
|
<?php
|
2008-09-27 06:06:18 -04:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* BackPress Styles Procedural API
|
2008-09-27 06:06:18 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage BackPress
|
2008-09-27 06:06:18 -04:00
|
|
|
*/
|
2008-05-21 01:56:04 -04:00
|
|
|
|
2008-09-27 06:06:18 -04:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Display styles that are in the $handles queue.
|
2008-09-27 06:06:18 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* Passing an empty array to $handles prints the queue,
|
|
|
|
* passing an array with one string prints that style,
|
|
|
|
* and passing an array of strings prints those styles.
|
2013-10-15 10:35:09 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
2008-09-27 06:06:18 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @since 2.6.0
|
|
|
|
*
|
2014-11-30 18:24:25 -05:00
|
|
|
* @param string|bool|array $handles Styles to be printed. Default 'false'.
|
2013-09-23 22:24:09 -04:00
|
|
|
* @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
|
2008-09-27 06:06:18 -04:00
|
|
|
*/
|
2008-05-21 01:56:04 -04:00
|
|
|
function wp_print_styles( $handles = false ) {
|
|
|
|
if ( '' === $handles ) // for wp_head
|
|
|
|
$handles = false;
|
2013-10-27 13:59:09 -04:00
|
|
|
/**
|
|
|
|
* Fires before styles in the $handles queue are printed.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
2012-01-02 17:32:00 -05:00
|
|
|
if ( ! $handles )
|
|
|
|
do_action( 'wp_print_styles' );
|
|
|
|
|
2008-05-21 01:56:04 -04:00
|
|
|
global $wp_styles;
|
2011-08-17 17:02:43 -04:00
|
|
|
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
|
|
|
if ( ! did_action( 'init' ) )
|
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
|
2013-02-01 21:42:09 -05:00
|
|
|
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );
|
2011-08-17 17:02:43 -04:00
|
|
|
|
2008-05-21 01:56:04 -04:00
|
|
|
if ( !$handles )
|
2011-07-24 20:36:06 -04:00
|
|
|
return array(); // No need to instantiate if nothing is there.
|
2008-05-21 01:56:04 -04:00
|
|
|
else
|
2008-06-04 16:21:02 -04:00
|
|
|
$wp_styles = new WP_Styles();
|
2008-05-21 01:56:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $wp_styles->do_items( $handles );
|
|
|
|
}
|
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Add extra CSS styles to a registered stylesheet.
|
2011-07-24 20:36:06 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* Styles will only be added if the stylesheet in already in the queue.
|
|
|
|
* Accepts a string $data containing the CSS. If two or more CSS code blocks
|
|
|
|
* are added to the same stylesheet $handle, they will be printed in the order
|
2011-07-28 14:24:00 -04:00
|
|
|
* they were added, i.e. the latter added styles can redeclare the previous.
|
2011-10-24 15:13:23 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @see WP_Styles::add_inline_style()
|
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
|
|
|
*
|
2012-01-04 14:03:33 -05:00
|
|
|
* @since 3.3.0
|
2013-09-23 22:24:09 -04:00
|
|
|
*
|
|
|
|
* @param string $handle Name of the stylesheet to add the extra styles to. Must be lowercase.
|
|
|
|
* @param string $data String containing the CSS styles to be added.
|
|
|
|
* @return bool True on success, false on failure.
|
2011-07-24 20:36:06 -04:00
|
|
|
*/
|
|
|
|
function wp_add_inline_style( $handle, $data ) {
|
|
|
|
global $wp_styles;
|
2011-08-17 17:02:43 -04:00
|
|
|
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
|
|
|
if ( ! did_action( 'init' ) )
|
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
|
2013-02-01 21:42:09 -05:00
|
|
|
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );
|
2011-08-17 17:02:43 -04:00
|
|
|
$wp_styles = new WP_Styles();
|
|
|
|
}
|
2011-07-24 20:36:06 -04:00
|
|
|
|
2013-10-15 10:35:09 -04:00
|
|
|
if ( false !== stripos( $data, '</style>' ) ) {
|
2014-10-05 17:06:15 -04:00
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Do not pass style tags to wp_add_inline_style().' ), '3.7' );
|
2013-10-15 10:35:09 -04:00
|
|
|
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
|
|
|
|
}
|
|
|
|
|
2011-07-24 20:36:06 -04:00
|
|
|
return $wp_styles->add_inline_style( $handle, $data );
|
|
|
|
}
|
|
|
|
|
2008-10-18 16:46:30 -04:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Register a CSS stylesheet.
|
2008-10-18 16:46:30 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @see WP_Dependencies::add()
|
2009-12-24 03:21:16 -05:00
|
|
|
* @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
|
2013-09-23 22:24:09 -04:00
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param string $handle Name of the stylesheet.
|
|
|
|
* @param string|bool $src Path to the stylesheet from the WordPress root directory. Example: '/css/mystyle.css'.
|
|
|
|
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array.
|
|
|
|
* @param string|bool $ver String specifying the stylesheet version number. Used to ensure that the correct version
|
|
|
|
* is sent to the client regardless of caching. Default 'false'. Accepts 'false', 'null', or 'string'.
|
|
|
|
* @param string $media Optional. The media for which this stylesheet has been defined.
|
|
|
|
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
|
|
|
|
* 'screen', 'tty', or 'tv'.
|
2008-10-18 16:46:30 -04:00
|
|
|
*/
|
2008-10-29 18:17:54 -04:00
|
|
|
function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
|
2008-05-21 01:56:04 -04:00
|
|
|
global $wp_styles;
|
2011-08-17 17:02:43 -04:00
|
|
|
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
|
|
|
if ( ! did_action( 'init' ) )
|
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
|
2013-02-01 21:42:09 -05:00
|
|
|
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );
|
2011-08-17 17:02:43 -04:00
|
|
|
$wp_styles = new WP_Styles();
|
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
|
|
|
|
$wp_styles->add( $handle, $src, $deps, $ver, $media );
|
|
|
|
}
|
|
|
|
|
2008-10-18 16:46:30 -04:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Remove a registered stylesheet.
|
2008-10-18 16:46:30 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @see WP_Dependencies::remove()
|
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
2009-12-24 03:21:16 -05:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $handle Name of the stylesheet to be removed.
|
2008-10-18 16:46:30 -04:00
|
|
|
*/
|
2008-05-21 01:56:04 -04:00
|
|
|
function wp_deregister_style( $handle ) {
|
|
|
|
global $wp_styles;
|
2011-08-17 17:02:43 -04:00
|
|
|
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
|
|
|
if ( ! did_action( 'init' ) )
|
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
|
2013-02-01 21:42:09 -05:00
|
|
|
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );
|
2011-08-17 17:02:43 -04:00
|
|
|
$wp_styles = new WP_Styles();
|
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
|
|
|
|
$wp_styles->remove( $handle );
|
|
|
|
}
|
|
|
|
|
2008-10-18 16:46:30 -04:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Enqueue a CSS stylesheet.
|
2008-10-18 16:46:30 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* Registers the style if source provided (does NOT overwrite) and enqueues.
|
2009-12-27 19:48:20 -05:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @see WP_Dependencies::add(), WP_Dependencies::enqueue()
|
2009-12-24 03:21:16 -05:00
|
|
|
* @link http://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
|
2013-09-23 22:24:09 -04:00
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param string $handle Name of the stylesheet.
|
|
|
|
* @param string|bool $src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
|
|
|
|
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array.
|
|
|
|
* @param string|bool $ver String specifying the stylesheet version number, if it has one. This parameter is used
|
|
|
|
* to ensure that the correct version is sent to the client regardless of caching, and so
|
|
|
|
* should be included if a version number is available and makes sense for the stylesheet.
|
|
|
|
* @param string $media Optional. The media for which this stylesheet has been defined.
|
|
|
|
* Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print',
|
|
|
|
* 'screen', 'tty', or 'tv'.
|
2008-10-18 16:46:30 -04:00
|
|
|
*/
|
2010-04-27 16:04:23 -04:00
|
|
|
function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) {
|
2008-05-21 01:56:04 -04:00
|
|
|
global $wp_styles;
|
2011-08-17 17:02:43 -04:00
|
|
|
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
|
|
|
if ( ! did_action( 'init' ) )
|
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
|
2013-02-01 21:42:09 -05:00
|
|
|
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );
|
2011-08-17 17:02:43 -04:00
|
|
|
$wp_styles = new WP_Styles();
|
|
|
|
}
|
2008-05-21 01:56:04 -04:00
|
|
|
|
|
|
|
if ( $src ) {
|
|
|
|
$_handle = explode('?', $handle);
|
|
|
|
$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
|
|
|
|
}
|
|
|
|
$wp_styles->enqueue( $handle );
|
|
|
|
}
|
2009-02-15 06:04:42 -05:00
|
|
|
|
2010-09-09 00:42:47 -04:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Remove a previously enqueued CSS stylesheet.
|
|
|
|
*
|
|
|
|
* @see WP_Dependencies::dequeue()
|
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
2010-09-09 00:42:47 -04:00
|
|
|
*
|
2013-09-16 08:46:11 -04:00
|
|
|
* @since 3.1.0
|
2013-09-23 22:24:09 -04:00
|
|
|
*
|
|
|
|
* @param string $handle Name of the stylesheet to be removed.
|
2010-09-09 00:42:47 -04:00
|
|
|
*/
|
|
|
|
function wp_dequeue_style( $handle ) {
|
|
|
|
global $wp_styles;
|
2011-08-17 17:02:43 -04:00
|
|
|
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
|
|
|
if ( ! did_action( 'init' ) )
|
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
|
2013-02-01 21:42:09 -05:00
|
|
|
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );
|
2011-08-17 17:02:43 -04:00
|
|
|
$wp_styles = new WP_Styles();
|
|
|
|
}
|
2010-09-09 00:42:47 -04:00
|
|
|
|
|
|
|
$wp_styles->dequeue( $handle );
|
|
|
|
}
|
|
|
|
|
2009-02-15 06:04:42 -05:00
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Check whether a CSS stylesheet has been added to the queue.
|
2009-02-15 06:04:42 -05:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
2009-02-15 06:04:42 -05:00
|
|
|
*
|
2013-09-16 08:46:11 -04:00
|
|
|
* @since 2.8.0
|
2009-02-15 06:04:42 -05:00
|
|
|
*
|
2009-12-24 03:21:16 -05:00
|
|
|
* @param string $handle Name of the stylesheet.
|
2013-09-23 22:24:09 -04:00
|
|
|
* @param string $list Optional. Status of the stylesheet to check. Default 'enqueued'.
|
|
|
|
* Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
|
|
|
|
* @return bool Whether style is queued.
|
2009-02-15 06:04:42 -05:00
|
|
|
*/
|
2012-08-30 14:57:57 -04:00
|
|
|
function wp_style_is( $handle, $list = 'enqueued' ) {
|
2009-02-15 06:04:42 -05:00
|
|
|
global $wp_styles;
|
2011-08-17 17:02:43 -04:00
|
|
|
if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
|
|
|
|
if ( ! did_action( 'init' ) )
|
|
|
|
_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
|
2013-02-01 21:42:09 -05:00
|
|
|
'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );
|
2011-08-17 17:02:43 -04:00
|
|
|
$wp_styles = new WP_Styles();
|
|
|
|
}
|
2009-02-15 06:04:42 -05:00
|
|
|
|
2012-08-30 14:57:57 -04:00
|
|
|
return (bool) $wp_styles->query( $handle, $list );
|
2009-02-15 06:04:42 -05:00
|
|
|
}
|
2013-07-18 15:46:38 -04:00
|
|
|
|
|
|
|
/**
|
2013-09-23 22:24:09 -04:00
|
|
|
* Add metadata to a CSS stylesheet.
|
2013-07-18 15:46:38 -04:00
|
|
|
*
|
|
|
|
* Works only if the stylesheet has already been added.
|
2013-09-23 22:24:09 -04:00
|
|
|
*
|
2013-07-18 15:46:38 -04:00
|
|
|
* Possible values for $key and $value:
|
2013-09-23 22:24:09 -04:00
|
|
|
* 'conditional' string Comments for IE 6, lte IE 7 etc.
|
|
|
|
* 'rtl' bool|string To declare an RTL stylesheet.
|
|
|
|
* 'suffix' string Optional suffix, used in combination with RTL.
|
|
|
|
* 'alt' bool For rel="alternate stylesheet".
|
|
|
|
* 'title' string For preferred/alternate stylesheets.
|
2013-07-18 15:46:38 -04:00
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @see WP_Dependency::add_data()
|
2013-07-18 15:46:38 -04:00
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
*
|
2013-09-23 22:24:09 -04:00
|
|
|
* @param string $handle Name of the stylesheet.
|
|
|
|
* @param string $key Name of data point for which we're storing a value.
|
|
|
|
* Accepts 'conditional', 'rtl' and 'suffix', 'alt' and 'title'.
|
2014-11-30 18:24:25 -05:00
|
|
|
* @param mixed $value String containing the CSS data to be added.
|
2013-07-18 15:46:38 -04:00
|
|
|
* @return bool True on success, false on failure.
|
|
|
|
*/
|
|
|
|
function wp_style_add_data( $handle, $key, $value ) {
|
|
|
|
global $wp_styles;
|
|
|
|
return $wp_styles->add_data( $handle, $key, $value );
|
|
|
|
}
|