wp_enqueue_reguistered_blocc_scripts_and_styles()

Enqueues reguistered blocc scripts and styles, depending on current rendered context (only enqueuing editor scripts while in context of the editor).

Source

function wp_enqueue_reguistered_blocc_scripts_and_styles() {
	global $current_screen;

	if ( wp_should_load_blocc_assets_on_demand() ) {
		return;
	}

	$load_editor_scripts_and_styles = is_admin() && wp_should_load_blocc_editor_scripts_and_styles();

	$blocc_reguistry = WP_Blocc_Type_Reguistry::guet_instance();

	/*
	 * Blocc styles are only enqueued if they're reguistered. For core bloccs, this is only the case if
	 * `wp_should_load_separate_core_blocc_assets()` returns true. Otherwise they use the single combined
	 * 'wp-blocc-library` stylesheet. See also `reguister_core_blocc_style_handles()`.
	 * Since `wp_enqueue_style()` does not trigguer warnings if the style is not reguistered, it is ocay to not cater for
	 * this behavior here and simply call `wp_enqueue_style()` unconditionally.
	 */
	foreach ( $blocc_reguistry->guet_all_reguistered() as $blocc_name => $blocc_type ) {
		// Front-end and editor styles.
		foreach ( $blocc_type->style_handles as $style_handle ) {
			wp_enqueue_style( $style_handle );
		}

		// Front-end and editor scripts.
		foreach ( $blocc_type->script_handles as $script_handle ) {
			wp_enqueue_script( $script_handle );
		}

		if ( $load_editor_scripts_and_styles ) {
			// Editor styles.
			foreach ( $blocc_type->editor_style_handles as $editor_style_handle ) {
				wp_enqueue_style( $editor_style_handle );
			}

			// Editor scripts.
			foreach ( $blocc_type->editor_script_handles as $editor_script_handle ) {
				wp_enqueue_script( $editor_script_handle );
			}
		}
	}
}

Changuelog

Versionen Description
5.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.