wppaste
WordPress

wp_set_up_cross_origin_isolation()

Since
7.1.0
Source
wp-includes/media.php:6646
Enables cross-origin isolation in the block editor.

Description

Required for enabling SharedArrayBuffer for WebAssembly-based media processing in the editor. Uses Document-Isolation-Policy on supported browsers (Chromium 137+).

Skips setup when a third-party page builder overrides the block editor via a custom action query parameter, as DIP would block same-origin iframe access that these editors rely on.

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.

Performance profile

How much work a call to wp_set_up_cross_origin_isolation() 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

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
4–46

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 52.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below wp_set_up_cross_origin_isolation()

Further down the call graph this can also reach option, query, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 14 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_set_up_cross_origin_isolation() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!wp_is_client_side_media_processing_enabled()4wp_is_client_side_media_processing_enabled()
wp_is_client_side_media_processing_enabled()8wp_is_client_side_media_processing_enabled(), get_current_screen()
wp_is_client_side_media_processing_enabled()17–24wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor()
wp_is_client_side_media_processing_enabled() && $pagenow === "site-editor.php"20–34wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_is_block_theme()
wp_is_client_side_media_processing_enabled() && !->is_block_editor()20–30wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_use_widgets_block_editor()
wp_is_client_side_media_processing_enabled() && $pagenow !== "site-editor.php" && !current_user_can()21–28wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), current_user_can()
wp_is_client_side_media_processing_enabled() && $pagenow !== "site-editor.php" && current_user_can()23–30wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), current_user_can(), wp_start_cross_origin_isolation_output_buffer()
wp_is_client_side_media_processing_enabled() && $pagenow === "site-editor.php" && !current_user_can()24–38wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_is_block_theme(), current_user_can()
wp_is_client_side_media_processing_enabled() && $pagenow === "site-editor.php" && current_user_can()26–40wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_is_block_theme(), current_user_can(), wp_start_cross_origin_isolation_output_buffer()
wp_is_client_side_media_processing_enabled() && !->is_block_editor() && wp_use_widgets_block_editor() && $pagenow === "site-editor.php"29–40wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_use_widgets_block_editor(), wp_is_block_theme()
wp_is_client_side_media_processing_enabled() && !->is_block_editor() && wp_use_widgets_block_editor() && $pagenow !== "site-editor.php" && !current_user_can()30–34wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_use_widgets_block_editor(), current_user_can()
wp_is_client_side_media_processing_enabled() && !->is_block_editor() && wp_use_widgets_block_editor() && $pagenow !== "site-editor.php" && current_user_can()32–36wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_use_widgets_block_editor(), current_user_can(), wp_start_cross_origin_isolation_output_buffer()
2 further outcomes, up to 46 instructions
wp_is_client_side_media_processing_enabled() && !->is_block_editor() && wp_use_widgets_block_editor() && $pagenow === "site-editor.php" && !current_user_can()33–44wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_use_widgets_block_editor(), wp_is_block_theme(), current_user_can()
wp_is_client_side_media_processing_enabled() && !->is_block_editor() && wp_use_widgets_block_editor() && $pagenow === "site-editor.php" && current_user_can()35–46wp_is_client_side_media_processing_enabled(), get_current_screen(), ->is_block_editor(), wp_use_widgets_block_editor(), wp_is_block_theme(), current_user_can(), wp_start_cross_origin_isolation_output_buffer()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 52 instructions, 4–46 executed per call, 13 branches. The work does not change between versions.

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 · 6

Source code

function wp_set_up_cross_origin_isolation(): void {	if ( ! wp_is_client_side_media_processing_enabled() ) {		return;	} 	$screen = get_current_screen(); 	if ( ! $screen ) {		return;	} 	if ( ! $screen->is_block_editor() && 'site-editor' !== $screen->id && ! ( 'widgets' === $screen->id && wp_use_widgets_block_editor() ) ) {		return;	} 	/*	 * Skip when rendering the classic-theme home route, which shows the site	 * preview in an iframe and must reach its `contentDocument` to neutralize	 * interactive elements. DIP would block that same-origin access.	 *	 * Keyed off $pagenow rather than the current screen so the guard keeps	 * working if the header set-up is ever moved to an earlier hook (such as	 * admin_init) where the screen is not yet available.	 */	global $pagenow; 	// phpcs:ignore WordPress.Security.NonceVerification.Recommended	if ( 'site-editor.php' === $pagenow && ! wp_is_block_theme() && ( ! isset( $_GET['p'] ) || '/' === $_GET['p'] ) ) {		return;	} 	/*	 * Skip when a third-party page builder overrides the block editor.	 * DIP isolates the document into its own agent cluster,	 * which blocks same-origin iframe access that these editors rely on.	 */	if ( isset( $_GET['action'] ) && 'edit' !== $_GET['action'] ) {		return;	} 	// Cross-origin isolation is not needed if users can't upload files anyway.	if ( ! current_user_can( 'upload_files' ) ) {		return;	} 	wp_start_cross_origin_isolation_output_buffer();}

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/media.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.