wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



_wp_enqueue_media_upload_pipeline_script › WordPress Function

Seit7.2.0
Veraltetn/v
› _wp_enqueue_media_upload_pipeline_script ( $handle )
Zugriff:
  • private
Parameter:
  • (string) $handle The screen script to enqueue.
    Erforderlich: Ja
Definiert in:
Codex:

Enqueues a screen's client-side upload integration script along with the shared pipeline glue and its settings.

Nothing is enqueued unless client-side media processing is enabled and the browser honors Document-Isolation-Policy: without isolation the page never becomes cross-origin isolated, the script would no-op, and the whole wp-upload-media dependency chain would be loaded for nothing. The same goes for a screen wp_set_up_cross_origin_isolation() did not isolate, such as the Customizer or the Site Icon picker: the media frame loads there too, but its uploads stay on the classic path. The screen script self-guards at runtime too: when the browser turns out not to be isolated or lacks client-side media support, it no-ops and the classic plupload flow keeps handling uploads.


Quellcode

function _wp_enqueue_media_upload_pipeline_script( string $handle ): void {
	if (
		! wp_is_client_side_media_processing_enabled() ||
		! wp_is_document_isolation_policy_supported() ||
		! wp_is_cross_origin_isolated_request()
	) {
		return;
	}

	wp_enqueue_script( $handle );

	// Both screen scripts share the pipeline script, so add its settings once.
	if ( wp_scripts()->get_data( 'media-upload-pipeline', 'settings_added' ) ) {
		return;
	}
	wp_scripts()->add_data( 'media-upload-pipeline', 'settings_added', true );

	$settings = wp_get_media_library_upload_settings();

	// wp_enqueue_media() can run on the front end, where there is no screen.
	$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;

	// The block editor configures the upload-media store itself; the pipeline waits for it.
	$settings['isBlockEditor'] = $screen && $screen->is_block_editor();

	$js_function = <<<'JS'
		( settings ) => {
			window._wpMediaUploadPipelineSettings = settings;
		}
		JS;

	wp_add_inline_script(
		'media-upload-pipeline',
		sprintf( '( %s )( %s );', $js_function, wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ),
		'before'
	);
}