wp_enqueue_registered_block_scripts_and_styles

The timeline below displays how wordpress function wp_enqueue_registered_block_scripts_and_styles has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Enqueues registered block scripts and styles, depending on current rendered
 * context (only enqueuing editor scripts while in context of the editor).
 *
 * @since 5.0.0
 *
 * @global WP_Screen $current_screen WordPress current screen object.
 */
function wp_enqueue_registered_block_scripts_and_styles()
{
    global $current_screen;
    if (wp_should_load_separate_core_block_assets()) {
        return;
    }
    $load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();
    $block_registry = WP_Block_Type_Registry::get_instance();
    foreach ($block_registry->get_all_registered() as $block_name => $block_type) {
        // Front-end and editor styles.
        foreach ($block_type->style_handles as $style_handle) {
            wp_enqueue_style($style_handle);
        }
        // Front-end and editor scripts.
        foreach ($block_type->script_handles as $script_handle) {
            wp_enqueue_script($script_handle);
        }
        if ($load_editor_scripts_and_styles) {
            // Editor styles.
            foreach ($block_type->editor_style_handles as $editor_style_handle) {
                wp_enqueue_style($editor_style_handle);
            }
            // Editor scripts.
            foreach ($block_type->editor_script_handles as $editor_script_handle) {
                wp_enqueue_script($editor_script_handle);
            }
        }
    }
}

WordPress Version: 5.8

/**
 * Enqueues registered block scripts and styles, depending on current rendered
 * context (only enqueuing editor scripts while in context of the editor).
 *
 * @since 5.0.0
 *
 * @global WP_Screen $current_screen WordPress current screen object.
 */
function wp_enqueue_registered_block_scripts_and_styles()
{
    global $current_screen;
    if (wp_should_load_separate_core_block_assets()) {
        return;
    }
    $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();
    $block_registry = WP_Block_Type_Registry::get_instance();
    foreach ($block_registry->get_all_registered() as $block_name => $block_type) {
        // Front-end styles.
        if (!empty($block_type->style)) {
            wp_enqueue_style($block_type->style);
        }
        // Front-end script.
        if (!empty($block_type->script)) {
            wp_enqueue_script($block_type->script);
        }
        // Editor styles.
        if ($load_editor_scripts && !empty($block_type->editor_style)) {
            wp_enqueue_style($block_type->editor_style);
        }
        // Editor script.
        if ($load_editor_scripts && !empty($block_type->editor_script)) {
            wp_enqueue_script($block_type->editor_script);
        }
    }
}

WordPress Version: 5.6

/**
 * Enqueues registered block scripts and styles, depending on current rendered
 * context (only enqueuing editor scripts while in context of the editor).
 *
 * @since 5.0.0
 *
 * @global WP_Screen $current_screen WordPress current screen object.
 */
function wp_enqueue_registered_block_scripts_and_styles()
{
    global $current_screen;
    $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();
    $block_registry = WP_Block_Type_Registry::get_instance();
    foreach ($block_registry->get_all_registered() as $block_name => $block_type) {
        // Front-end styles.
        if (!empty($block_type->style)) {
            wp_enqueue_style($block_type->style);
        }
        // Front-end script.
        if (!empty($block_type->script)) {
            wp_enqueue_script($block_type->script);
        }
        // Editor styles.
        if ($load_editor_scripts && !empty($block_type->editor_style)) {
            wp_enqueue_style($block_type->editor_style);
        }
        // Editor script.
        if ($load_editor_scripts && !empty($block_type->editor_script)) {
            wp_enqueue_script($block_type->editor_script);
        }
    }
}

WordPress Version: 5.3

/**
 * Enqueues registered block scripts and styles, depending on current rendered
 * context (only enqueuing editor scripts while in context of the editor).
 *
 * @since 5.0.0
 *
 * @global WP_Screen $current_screen WordPress current screen object.
 */
function wp_enqueue_registered_block_scripts_and_styles()
{
    global $current_screen;
    $is_editor = $current_screen instanceof WP_Screen && $current_screen->is_block_editor();
    $block_registry = WP_Block_Type_Registry::get_instance();
    foreach ($block_registry->get_all_registered() as $block_name => $block_type) {
        // Front-end styles.
        if (!empty($block_type->style)) {
            wp_enqueue_style($block_type->style);
        }
        // Front-end script.
        if (!empty($block_type->script)) {
            wp_enqueue_script($block_type->script);
        }
        // Editor styles.
        if ($is_editor && !empty($block_type->editor_style)) {
            wp_enqueue_style($block_type->editor_style);
        }
        // Editor script.
        if ($is_editor && !empty($block_type->editor_script)) {
            wp_enqueue_script($block_type->editor_script);
        }
    }
}

WordPress Version: 5.0

/**
 * Enqueues registered block scripts and styles, depending on current rendered
 * context (only enqueuing editor scripts while in context of the editor).
 *
 * @since 5.0.0
 *
 * @global WP_Screen $current_screen
 */
function wp_enqueue_registered_block_scripts_and_styles()
{
    global $current_screen;
    $is_editor = $current_screen instanceof WP_Screen && $current_screen->is_block_editor();
    $block_registry = WP_Block_Type_Registry::get_instance();
    foreach ($block_registry->get_all_registered() as $block_name => $block_type) {
        // Front-end styles.
        if (!empty($block_type->style)) {
            wp_enqueue_style($block_type->style);
        }
        // Front-end script.
        if (!empty($block_type->script)) {
            wp_enqueue_script($block_type->script);
        }
        // Editor styles.
        if ($is_editor && !empty($block_type->editor_style)) {
            wp_enqueue_style($block_type->editor_style);
        }
        // Editor script.
        if ($is_editor && !empty($block_type->editor_script)) {
            wp_enqueue_script($block_type->editor_script);
        }
    }
}