2008-05-21 07:56:04 +02:00
|
|
|
<?php
|
2008-09-27 12:06:18 +02:00
|
|
|
/**
|
2016-02-27 21:34:29 +01:00
|
|
|
* Dependencies API: Styles functions
|
2008-09-27 12:06:18 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @package WordPress
|
2016-02-27 21:34:29 +01:00
|
|
|
* @subpackage Dependencies
|
2008-09-27 12:06:18 +02:00
|
|
|
*/
|
2008-05-21 07:56:04 +02:00
|
|
|
|
2015-01-16 03:31:23 +01:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Initializes $wp_styles if it has not been set.
|
2015-01-16 03:31:23 +01:00
|
|
|
*
|
|
|
|
* @since 4.2.0
|
|
|
|
*
|
Docs: Correct the placement of `@global` tags in various files.
Follow-up to [6589], [8598], [10798], [25490], [25594], [31192], [31194], [35718], [37437], [44169], [44948], [45247], [56763], [56773], [57370], [57503].
Props shailu25.
Fixes #61295.
Built from https://develop.svn.wordpress.org/trunk@58200
git-svn-id: http://core.svn.wordpress.org/trunk@57663 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-05-26 22:51:13 +02:00
|
|
|
* @global WP_Styles $wp_styles
|
|
|
|
*
|
2015-04-05 17:56:26 +02:00
|
|
|
* @return WP_Styles WP_Styles instance.
|
2015-01-16 03:31:23 +01:00
|
|
|
*/
|
|
|
|
function wp_styles() {
|
|
|
|
global $wp_styles;
|
2020-06-17 12:16:08 +02:00
|
|
|
|
2015-01-16 03:31:23 +01:00
|
|
|
if ( ! ( $wp_styles instanceof WP_Styles ) ) {
|
|
|
|
$wp_styles = new WP_Styles();
|
|
|
|
}
|
2020-06-17 12:16:08 +02:00
|
|
|
|
2015-01-16 03:31:23 +01:00
|
|
|
return $wp_styles;
|
|
|
|
}
|
|
|
|
|
2008-09-27 12:06:18 +02:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Displays styles that are in the $handles queue.
|
2008-09-27 12:06:18 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02: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 16:35:09 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* @since 2.6.0
|
|
|
|
*
|
Docs: Correct the placement of `@global` tags in various files.
Follow-up to [6589], [8598], [10798], [25490], [25594], [31192], [31194], [35718], [37437], [44169], [44948], [45247], [56763], [56773], [57370], [57503].
Props shailu25.
Fixes #61295.
Built from https://develop.svn.wordpress.org/trunk@58200
git-svn-id: http://core.svn.wordpress.org/trunk@57663 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-05-26 22:51:13 +02:00
|
|
|
* @global WP_Styles $wp_styles The WP_Styles object for printing styles.
|
|
|
|
*
|
2014-12-01 00:24:25 +01:00
|
|
|
* @param string|bool|array $handles Styles to be printed. Default 'false'.
|
2019-11-05 22:23:02 +01:00
|
|
|
* @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
|
2008-09-27 12:06:18 +02:00
|
|
|
*/
|
2008-05-21 07:56:04 +02:00
|
|
|
function wp_print_styles( $handles = false ) {
|
2020-06-17 12:16:08 +02:00
|
|
|
global $wp_styles;
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
if ( '' === $handles ) { // For 'wp_head'.
|
2008-05-21 07:56:04 +02:00
|
|
|
$handles = false;
|
2015-01-16 03:31:23 +01:00
|
|
|
}
|
2019-11-09 14:43:01 +01:00
|
|
|
|
2015-01-16 03:31:23 +01:00
|
|
|
if ( ! $handles ) {
|
2019-11-09 14:43:01 +01:00
|
|
|
/**
|
|
|
|
* Fires before styles in the $handles queue are printed.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
2012-01-02 23:32:00 +01:00
|
|
|
do_action( 'wp_print_styles' );
|
2015-01-16 03:31:23 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 03:42:22 +01:00
|
|
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
|
2012-01-02 23:32:00 +01:00
|
|
|
|
2015-01-16 02:06:24 +01:00
|
|
|
if ( ! ( $wp_styles instanceof WP_Styles ) ) {
|
2015-01-16 03:31:23 +01:00
|
|
|
if ( ! $handles ) {
|
2011-07-25 02:36:06 +02:00
|
|
|
return array(); // No need to instantiate if nothing is there.
|
2015-01-16 03:31:23 +01:00
|
|
|
}
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|
|
|
|
|
2015-06-12 18:54:24 +02:00
|
|
|
return wp_styles()->do_items( $handles );
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|
|
|
|
|
2011-07-25 02:36:06 +02:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Adds extra CSS styles to a registered stylesheet.
|
2011-07-25 02:36:06 +02:00
|
|
|
*
|
2018-12-20 03:42:48 +01:00
|
|
|
* Styles will only be added if the stylesheet is already in the queue.
|
2013-09-24 04:24:09 +02:00
|
|
|
* 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 20:24:00 +02:00
|
|
|
* they were added, i.e. the latter added styles can redeclare the previous.
|
2011-10-24 21:13:23 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* @see WP_Styles::add_inline_style()
|
|
|
|
*
|
2012-01-04 20:03:33 +01:00
|
|
|
* @since 3.3.0
|
2013-09-24 04:24:09 +02:00
|
|
|
*
|
2016-03-14 23:37:26 +01:00
|
|
|
* @param string $handle Name of the stylesheet to add the extra styles to.
|
2013-09-24 04:24:09 +02:00
|
|
|
* @param string $data String containing the CSS styles to be added.
|
|
|
|
* @return bool True on success, false on failure.
|
2011-07-25 02:36:06 +02:00
|
|
|
*/
|
|
|
|
function wp_add_inline_style( $handle, $data ) {
|
2020-06-17 12:16:08 +02:00
|
|
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
|
2011-07-25 02:36:06 +02:00
|
|
|
|
2013-10-15 16:35:09 +02:00
|
|
|
if ( false !== stripos( $data, '</style>' ) ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
_doing_it_wrong(
|
2018-08-17 03:51:36 +02:00
|
|
|
__FUNCTION__,
|
|
|
|
sprintf(
|
2017-12-01 00:11:00 +01:00
|
|
|
/* translators: 1: <style>, 2: wp_add_inline_style() */
|
|
|
|
__( 'Do not pass %1$s tags to %2$s.' ),
|
|
|
|
'<code><style></code>',
|
|
|
|
'<code>wp_add_inline_style()</code>'
|
2018-08-17 03:51:36 +02:00
|
|
|
),
|
|
|
|
'3.7.0'
|
2017-12-01 00:11:00 +01:00
|
|
|
);
|
2013-10-15 16:35:09 +02:00
|
|
|
$data = trim( preg_replace( '#<style[^>]*>(.*)</style>#is', '$1', $data ) );
|
|
|
|
}
|
|
|
|
|
2015-01-16 03:31:23 +01:00
|
|
|
return wp_styles()->add_inline_style( $handle, $data );
|
2011-07-25 02:36:06 +02:00
|
|
|
}
|
|
|
|
|
2008-10-18 22:46:30 +02:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Registers a CSS stylesheet.
|
2008-10-18 22:46:30 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* @see WP_Dependencies::add()
|
2016-06-10 06:50:33 +02:00
|
|
|
* @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
|
2013-09-24 04:24:09 +02:00
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2015-05-10 21:57:25 +02:00
|
|
|
* @since 4.3.0 A return value was added.
|
2013-09-24 04:24:09 +02:00
|
|
|
*
|
2016-03-14 23:37:26 +01:00
|
|
|
* @param string $handle Name of the stylesheet. Should be unique.
|
2022-10-11 11:02:14 +02:00
|
|
|
* @param string|false $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
2018-09-28 23:51:24 +02:00
|
|
|
* If source is set to false, stylesheet is an alias of other stylesheets it depends on.
|
2019-10-26 23:02:02 +02:00
|
|
|
* @param string[] $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
|
2016-03-14 23:37:26 +01:00
|
|
|
* @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
|
|
|
|
* as a query string for cache busting purposes. If version is set to false, a version
|
|
|
|
* number is automatically added equal to current installed WordPress version.
|
|
|
|
* If set to null, no version is added.
|
|
|
|
* @param string $media Optional. The media for which this stylesheet has been defined.
|
|
|
|
* Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
|
|
|
|
* '(orientation: portrait)' and '(max-width: 640px)'.
|
2015-05-10 21:57:25 +02:00
|
|
|
* @return bool Whether the style has been registered. True on success, false on failure.
|
2008-10-18 22:46:30 +02:00
|
|
|
*/
|
2008-10-29 23:17:54 +01:00
|
|
|
function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
|
2020-06-17 12:16:08 +02:00
|
|
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
|
2008-05-21 07:56:04 +02:00
|
|
|
|
2015-05-10 21:57:25 +02:00
|
|
|
return wp_styles()->add( $handle, $src, $deps, $ver, $media );
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|
|
|
|
|
2008-10-18 22:46:30 +02:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Removes a registered stylesheet.
|
2008-10-18 22:46:30 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* @see WP_Dependencies::remove()
|
2009-12-24 09:21:16 +01:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* @since 2.1.0
|
|
|
|
*
|
|
|
|
* @param string $handle Name of the stylesheet to be removed.
|
2008-10-18 22:46:30 +02:00
|
|
|
*/
|
2008-05-21 07:56:04 +02:00
|
|
|
function wp_deregister_style( $handle ) {
|
2020-06-17 12:16:08 +02:00
|
|
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
|
2008-05-21 07:56:04 +02:00
|
|
|
|
2015-01-16 03:31:23 +01:00
|
|
|
wp_styles()->remove( $handle );
|
2008-05-21 07:56:04 +02:00
|
|
|
}
|
|
|
|
|
2008-10-18 22:46:30 +02:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Enqueues a CSS stylesheet.
|
2008-10-18 22:46:30 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* Registers the style if source provided (does NOT overwrite) and enqueues.
|
2009-12-28 01:48:20 +01:00
|
|
|
*
|
2015-12-23 08:53:26 +01:00
|
|
|
* @see WP_Dependencies::add()
|
|
|
|
* @see WP_Dependencies::enqueue()
|
2016-06-10 06:50:33 +02:00
|
|
|
* @link https://www.w3.org/TR/CSS2/media.html#media-types List of CSS media types.
|
2013-09-24 04:24:09 +02:00
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
2016-03-14 23:37:26 +01:00
|
|
|
* @param string $handle Name of the stylesheet. Should be unique.
|
|
|
|
* @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
2016-09-04 06:09:28 +02:00
|
|
|
* Default empty.
|
2019-10-26 23:02:02 +02:00
|
|
|
* @param string[] $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
|
2016-03-14 23:37:26 +01:00
|
|
|
* @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
|
|
|
|
* as a query string for cache busting purposes. If version is set to false, a version
|
|
|
|
* number is automatically added equal to current installed WordPress version.
|
|
|
|
* If set to null, no version is added.
|
|
|
|
* @param string $media Optional. The media for which this stylesheet has been defined.
|
|
|
|
* Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
|
|
|
|
* '(orientation: portrait)' and '(max-width: 640px)'.
|
2008-10-18 22:46:30 +02:00
|
|
|
*/
|
2016-09-04 06:09:28 +02:00
|
|
|
function wp_enqueue_style( $handle, $src = '', $deps = array(), $ver = false, $media = 'all' ) {
|
2020-06-17 12:16:08 +02:00
|
|
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
|
2015-01-16 03:31:23 +01:00
|
|
|
|
|
|
|
$wp_styles = wp_styles();
|
2008-05-21 07:56:04 +02:00
|
|
|
|
|
|
|
if ( $src ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$_handle = explode( '?', $handle );
|
2008-05-21 07:56:04 +02:00
|
|
|
$wp_styles->add( $_handle[0], $src, $deps, $ver, $media );
|
|
|
|
}
|
2020-06-17 12:16:08 +02:00
|
|
|
|
2008-05-21 07:56:04 +02:00
|
|
|
$wp_styles->enqueue( $handle );
|
|
|
|
}
|
2009-02-15 12:04:42 +01:00
|
|
|
|
2010-09-09 06:42:47 +02:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Removes a previously enqueued CSS stylesheet.
|
2013-09-24 04:24:09 +02:00
|
|
|
*
|
|
|
|
* @see WP_Dependencies::dequeue()
|
2010-09-09 06:42:47 +02:00
|
|
|
*
|
2013-09-16 14:46:11 +02:00
|
|
|
* @since 3.1.0
|
2013-09-24 04:24:09 +02:00
|
|
|
*
|
|
|
|
* @param string $handle Name of the stylesheet to be removed.
|
2010-09-09 06:42:47 +02:00
|
|
|
*/
|
|
|
|
function wp_dequeue_style( $handle ) {
|
2020-06-17 12:16:08 +02:00
|
|
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
|
2010-09-09 06:42:47 +02:00
|
|
|
|
2015-01-16 03:31:23 +01:00
|
|
|
wp_styles()->dequeue( $handle );
|
2010-09-09 06:42:47 +02:00
|
|
|
}
|
|
|
|
|
2009-02-15 12:04:42 +01:00
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Checks whether a CSS stylesheet has been added to the queue.
|
2009-02-15 12:04:42 +01:00
|
|
|
*
|
2013-09-16 14:46:11 +02:00
|
|
|
* @since 2.8.0
|
2009-02-15 12:04:42 +01:00
|
|
|
*
|
2009-12-24 09:21:16 +01:00
|
|
|
* @param string $handle Name of the stylesheet.
|
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/functions.wp-styles.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$list` parameter to `$status` in `wp_style_is()`.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54931
git-svn-id: http://core.svn.wordpress.org/trunk@54483 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-04 13:48:11 +01:00
|
|
|
* @param string $status Optional. Status of the stylesheet to check. Default 'enqueued'.
|
2013-09-24 04:24:09 +02:00
|
|
|
* Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
|
|
|
|
* @return bool Whether style is queued.
|
2009-02-15 12:04:42 +01:00
|
|
|
*/
|
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/functions.wp-styles.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$list` parameter to `$status` in `wp_style_is()`.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54931
git-svn-id: http://core.svn.wordpress.org/trunk@54483 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-04 13:48:11 +01:00
|
|
|
function wp_style_is( $handle, $status = 'enqueued' ) {
|
2020-06-17 12:16:08 +02:00
|
|
|
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
|
2009-02-15 12:04:42 +01:00
|
|
|
|
Code Modernization: Rename parameters that use reserved keywords in `wp-includes/functions.wp-styles.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$list` parameter to `$status` in `wp_style_is()`.
Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.
Built from https://develop.svn.wordpress.org/trunk@54931
git-svn-id: http://core.svn.wordpress.org/trunk@54483 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-12-04 13:48:11 +01:00
|
|
|
return (bool) wp_styles()->query( $handle, $status );
|
2009-02-15 12:04:42 +01:00
|
|
|
}
|
2013-07-18 21:46:38 +02:00
|
|
|
|
|
|
|
/**
|
2023-01-15 15:57:13 +01:00
|
|
|
* Adds metadata to a CSS stylesheet.
|
2013-07-18 21:46:38 +02:00
|
|
|
*
|
2021-09-02 10:30:58 +02:00
|
|
|
* Works only if the stylesheet has already been registered.
|
2013-09-24 04:24:09 +02:00
|
|
|
*
|
2013-07-18 21:46:38 +02:00
|
|
|
* Possible values for $key and $value:
|
2013-09-24 04:24:09 +02: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.
|
2021-11-19 16:14:00 +01:00
|
|
|
* 'path' string The absolute path to a stylesheet. Stylesheet will
|
2023-01-15 15:50:11 +01:00
|
|
|
* load inline when 'path' is set.
|
2013-07-18 21:46:38 +02:00
|
|
|
*
|
2020-02-07 18:42:06 +01:00
|
|
|
* @see WP_Dependencies::add_data()
|
2013-07-18 21:46:38 +02:00
|
|
|
*
|
|
|
|
* @since 3.6.0
|
2021-11-19 16:14:00 +01:00
|
|
|
* @since 5.8.0 Added 'path' as an official value for $key.
|
|
|
|
* See {@see wp_maybe_inline_styles()}.
|
2013-07-18 21:46:38 +02:00
|
|
|
*
|
2013-09-24 04:24:09 +02:00
|
|
|
* @param string $handle Name of the stylesheet.
|
|
|
|
* @param string $key Name of data point for which we're storing a value.
|
2021-11-19 16:14:00 +01:00
|
|
|
* Accepts 'conditional', 'rtl' and 'suffix', 'alt', 'title' and 'path'.
|
2014-12-01 00:24:25 +01:00
|
|
|
* @param mixed $value String containing the CSS data to be added.
|
2013-07-18 21:46:38 +02:00
|
|
|
* @return bool True on success, false on failure.
|
|
|
|
*/
|
|
|
|
function wp_style_add_data( $handle, $key, $value ) {
|
2015-01-16 03:31:23 +01:00
|
|
|
return wp_styles()->add_data( $handle, $key, $value );
|
2013-07-18 21:46:38 +02:00
|
|
|
}
|