WP_Theme_JSON::get_viewport_media_queries( mixed $viewport_settings = null, array $options = array() ): array
- Since
- 7.1.0
- Source
wp-includes/class-wp-theme-json.php:720
Description
Breakpoint values are read from settings.viewport, sanitized, and normalized before the media query strings are generated. By default, the returned keys are the theme.json style-state names (@mobile, @tablet).
When $options['include_desktop'] is truthy, @desktop is included.
Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$viewport_settingsmixedoptional- Viewport settings from theme.json.Default:
null $optionsarrayoptional- Options for generating media queries.Default:
array()$include_desktopbooldefault: falseWhether to include the desktop media query.
Return value
array- Responsive media queries.
Performance profile
How much work a call to WP_Theme_JSON::get_viewport_media_queries() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 14–41
- Plugin surface
- None
- Called by
- 4
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 46.
Nothing here hands control to plugin code.
4 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme_JSON::get_viewport_media_queries() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14–41 | ::sanitize_viewport_settings() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 46 | 14–41 | 5 | |
| 8.5 | 46 | 14–41 | 5 | |
| 8.4 | 46 | 14–41 | 5 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 47 | 14–42 | 5 | |
| 8.2 | 47 | 14–42 | 5 | |
| 8.1 | 47 | 14–42 | 5 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 48 | 14–42 | 5 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 1
- static::sanitize_viewport_settings()
Used by · 4
- block_core_navigation_add_support_classes_to_container()Adds Navigation block support classes to inner list containers.
- wp_render_block_states_support()Renders per-instance state styles on the frontend.
- wp_render_block_visibility_support()Render nothing if the block is hidden, or add viewport visibility styles.
- wp_render_layout_support_flag()Renders the layout config to the block wrapper.
Source code
public static function get_viewport_media_queries( $viewport_settings = null, $options = array() ) { $breakpoints = static::sanitize_viewport_settings( $viewport_settings ); $responsive_media_queries = array(); if ( isset( $breakpoints['mobile'] ) ) { $responsive_media_queries['@mobile'] = "@media (width <= {$breakpoints['mobile']})"; } if ( isset( $breakpoints['tablet'] ) ) { $responsive_media_queries['@tablet'] = isset( $breakpoints['mobile'] ) ? sprintf( '@media (%s < width <= %s)', $breakpoints['mobile'], $breakpoints['tablet'] ) : "@media (width <= {$breakpoints['tablet']})"; } if ( ! empty( $options['include_desktop'] ) ) { if ( isset( $breakpoints['tablet'] ) ) { $desktop_breakpoint = $breakpoints['tablet']; } else { $desktop_breakpoint = $breakpoints['mobile']; } $responsive_media_queries['@desktop'] = "@media (width > {$desktop_breakpoint})"; } return $responsive_media_queries; }Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-theme-json.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.