Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/wp-includes/global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ function wp_get_global_settings( $path = array(), $context = array() ) {
return _wp_array_get( $settings, $path, $settings );
}

/**
* Returns CSS media queries for responsive viewport style states.
*
* Breakpoint values are read from the viewport settings, sanitized, and
* normalized before the media query strings are generated. By default, the
* returned keys are `@mobile` and `@tablet`. When `$options['include_desktop']`
* is truthy, `@desktop` is included.
*
* @since 7.2.0
*
* @param mixed $viewport_settings Viewport settings from theme.json.
* @param array $options {
* Optional. Options for generating media queries.
*
* @type bool $include_desktop Whether to include the desktop media query. Default false.
* }
* @return array Responsive media queries.
*/
function wp_get_viewport_media_queries( $viewport_settings = null, $options = array() ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's appropriate, should we direct users in the docs to prefer this function over the class method? E.g., something like:

* Use this instead of calling WP_Theme_JSON::get_viewport_media_queries() directly, which is not a public API

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be necessary because the whole class is documented as not public. I assume anyone who doesn't read the class docs also won't bother to look for this function 😅

return WP_Theme_JSON::get_viewport_media_queries( $viewport_settings, $options );
}

/**
* Gets the styles resulting of merging core, theme, and user data.
*
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/tests/theme/wpGetGlobalStylesAndSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

require_once __DIR__ . '/base.php';

/**
* Test functions in global-styles-and-settings.php.
*
* @package WordPress
* @subpackage Theme
*
* @group themes
*
* @covers ::wp_get_viewport_media_queries
*/
class Tests_Theme_WpGetGlobalStylesAndSettings extends WP_Theme_UnitTestCase {

/**
* @ticket 82082
*/
public function test_wp_get_viewport_media_queries_returns_media_queries() {
$this->assertSame(
array(
'@mobile' => '@media (width <= 640px)',
'@tablet' => '@media (640px < width <= 960px)',
'@desktop' => '@media (width > 960px)',
),
wp_get_viewport_media_queries(
array(
'mobile' => '640px',
'tablet' => '960px',
),
array(
'include_desktop' => true,
)
)
);
}
}
Loading