From 0e936c8b443ffa98e841670cdaefe45bc5c3cae5 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 16 Sep 2026 14:38:26 +0100 Subject: [PATCH] Expose `wp_get_viewport_media_queries` for custom block controls --- .../global-styles-and-settings.php | 22 +++++++++++ .../theme/wpGetGlobalStylesAndSettings.php | 38 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/phpunit/tests/theme/wpGetGlobalStylesAndSettings.php diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index c4a3284dadb91..2315eef1ad5d5 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -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() ) { + return WP_Theme_JSON::get_viewport_media_queries( $viewport_settings, $options ); +} + /** * Gets the styles resulting of merging core, theme, and user data. * diff --git a/tests/phpunit/tests/theme/wpGetGlobalStylesAndSettings.php b/tests/phpunit/tests/theme/wpGetGlobalStylesAndSettings.php new file mode 100644 index 0000000000000..d4e7e2576157e --- /dev/null +++ b/tests/phpunit/tests/theme/wpGetGlobalStylesAndSettings.php @@ -0,0 +1,38 @@ +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, + ) + ) + ); + } +}