From 3a836ea224ca66e3fdbd643aa1dcb68f713af626 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Tue, 23 Feb 2016 20:40:43 +0000 Subject: [PATCH] Styles: Clarify the allowed values for the `$media` parameter of `wp_register_style()`/`wp_enqueue_style()`. Adds unit test. Fixes #35921. git-svn-id: https://develop.svn.wordpress.org/trunk@36649 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.wp-styles.php | 9 ++--- tests/phpunit/tests/dependencies/styles.php | 37 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/functions.wp-styles.php b/src/wp-includes/functions.wp-styles.php index 5acea977fe..31993b6c97 100644 --- a/src/wp-includes/functions.wp-styles.php +++ b/src/wp-includes/functions.wp-styles.php @@ -106,8 +106,9 @@ function wp_add_inline_style( $handle, $data ) { * @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'. + * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like + * '(orientation: portrait)' and '(max-width: 640px)'. + * * @return bool Whether the style has been registered. True on success, false on failure. */ function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { @@ -149,8 +150,8 @@ function wp_deregister_style( $handle ) { * 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'. + * Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like + * '(orientation: portrait)' and '(max-width: 640px)'. */ function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) { _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); diff --git a/tests/phpunit/tests/dependencies/styles.php b/tests/phpunit/tests/dependencies/styles.php index a2d74f5eec..0994cb3d26 100644 --- a/tests/phpunit/tests/dependencies/styles.php +++ b/tests/phpunit/tests/dependencies/styles.php @@ -261,4 +261,41 @@ CSS; $this->assertEquals( $expected, get_echo( 'wp_print_styles' ) ); } + /** + * @ticket 35921 + * @dataProvider data_styles_with_media + */ + function test_wp_enqueue_style_with_media( $expected, $media ) { + wp_enqueue_style( 'handle', 'http://example.com', array(), 1, $media ); + $this->assertContains( $expected, get_echo( 'wp_print_styles' ) ); + } + + function data_styles_with_media() { + return array( + array( + "media='all'", + 'all' + ), + array( + "media='(orientation: portrait)'", + '(orientation: portrait)' + ), + array( + "media='(max-width: 640px)'", + '(max-width: 640px)' + ), + array( + "media='print and (min-width: 25cm)'", + 'print and (min-width: 25cm)' + ), + array( + "media='screen and (color), projection and (color)'", + 'screen and (color), projection and (color)' + ), + array( + "media='not screen and (color)'", + 'not screen and (color)' + ), + ); + } }