render_block_core_legacy_widget

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

WordPress Version: 6.1

/**
 * Server-side rendering of the `core/legacy-widget` block.
 *
 * @package WordPress
 */
/**
 * Renders the 'core/legacy-widget' block.
 *
 * @param array $attributes The block attributes.
 *
 * @return string Rendered block.
 */
function render_block_core_legacy_widget($attributes)
{
    global $wp_widget_factory;
    if (isset($attributes['id'])) {
        $sidebar_id = wp_find_widgets_sidebar($attributes['id']);
        return wp_render_widget($attributes['id'], $sidebar_id);
    }
    if (!isset($attributes['idBase'])) {
        return '';
    }
    $id_base = $attributes['idBase'];
    $widget_key = $wp_widget_factory->get_widget_key($id_base);
    $widget_object = $wp_widget_factory->get_widget_object($id_base);
    if (!$widget_key || !$widget_object) {
        return '';
    }
    if (isset($attributes['instance']['encoded'], $attributes['instance']['hash'])) {
        $serialized_instance = base64_decode($attributes['instance']['encoded']);
        if (!hash_equals(wp_hash($serialized_instance), (string) $attributes['instance']['hash'])) {
            return '';
        }
        $instance = unserialize($serialized_instance);
    } else {
        $instance = array();
    }
    $args = array('widget_id' => $widget_object->id, 'widget_name' => $widget_object->name);
    ob_start();
    the_widget($widget_key, $instance, $args);
    return ob_get_clean();
}

WordPress Version: 9.5

/**
 * Server-side rendering of the `core/legacy-widget` block.
 *
 * @package WordPress
 */
/**
 * Renders the 'core/legacy-widget' block.
 *
 * @param array $attributes The block attributes.
 *
 * @return string Rendered block.
 */
function render_block_core_legacy_widget($attributes)
{
    global $wp_widget_factory;
    if (isset($attributes['id'])) {
        $sidebar_id = wp_find_widgets_sidebar($attributes['id']);
        return wp_render_widget($attributes['id'], $sidebar_id);
    }
    if (!isset($attributes['idBase'])) {
        return '';
    }
    $id_base = $attributes['idBase'];
    if (method_exists($wp_widget_factory, 'get_widget_key') && method_exists($wp_widget_factory, 'get_widget_object')) {
        $widget_key = $wp_widget_factory->get_widget_key($id_base);
        $widget_object = $wp_widget_factory->get_widget_object($id_base);
    } else {
        /*
         * This file is copied from the published @wordpress/widgets package when WordPress
         * Core is built. Because the package is a dependency of both WordPress Core and the
         * Gutenberg plugin where the block editor is developed, this fallback condition is
         * required until the minimum required version of WordPress for the plugin is raised
         * to 5.8.
         */
        $widget_key = gutenberg_get_widget_key($id_base);
        $widget_object = gutenberg_get_widget_object($id_base);
    }
    if (!$widget_key || !$widget_object) {
        return '';
    }
    if (isset($attributes['instance']['encoded'], $attributes['instance']['hash'])) {
        $serialized_instance = base64_decode($attributes['instance']['encoded']);
        if (!hash_equals(wp_hash($serialized_instance), (string) $attributes['instance']['hash'])) {
            return '';
        }
        $instance = unserialize($serialized_instance);
    } else {
        $instance = array();
    }
    $args = array('widget_id' => $widget_object->id, 'widget_name' => $widget_object->name);
    ob_start();
    the_widget($widget_key, $instance, $args);
    return ob_get_clean();
}

WordPress Version: 5.9

/**
 * Server-side rendering of the `core/legacy-widget` block.
 *
 * @package WordPress
 */
/**
 * Renders the 'core/legacy-widget' block.
 *
 * @param array $attributes The block attributes.
 *
 * @return string Rendered block.
 */
function render_block_core_legacy_widget($attributes)
{
    global $wp_widget_factory;
    if (isset($attributes['id'])) {
        $sidebar_id = wp_find_widgets_sidebar($attributes['id']);
        return wp_render_widget($attributes['id'], $sidebar_id);
    }
    if (!isset($attributes['idBase'])) {
        return '';
    }
    $id_base = $attributes['idBase'];
    if (method_exists($wp_widget_factory, 'get_widget_key') && method_exists($wp_widget_factory, 'get_widget_object')) {
        $widget_key = $wp_widget_factory->get_widget_key($id_base);
        $widget_object = $wp_widget_factory->get_widget_object($id_base);
    } else {
        /*
         * This file is copied from the published @wordpress/widgets package when WordPress
         * Core is built. Because the package is a dependency of both WordPress Core and the
         * Gutenberg plugin where the block editor is developed, this fallback condition is
         * required until the minimum required version of WordPress for the plugin is raised
         * to 5.8.
         */
        $widget_key = gutenberg_get_widget_key($id_base);
        $widget_object = gutenberg_get_widget_object($id_base);
    }
    if (!$widget_key || !$widget_object) {
        return '';
    }
    if (isset($attributes['instance']['encoded'], $attributes['instance']['hash'])) {
        $serialized_instance = base64_decode($attributes['instance']['encoded']);
        if (wp_hash($serialized_instance) !== $attributes['instance']['hash']) {
            return '';
        }
        $instance = unserialize($serialized_instance);
    } else {
        $instance = array();
    }
    $args = array('widget_id' => $widget_object->id, 'widget_name' => $widget_object->name);
    ob_start();
    the_widget($widget_key, $instance, $args);
    return ob_get_clean();
}

WordPress Version: 8.6

/**
 * Server-side rendering of the `core/legacy-widget` block.
 *
 * @package WordPress
 */
/**
 * Renders the 'core/legacy-widget' block.
 *
 * @param array $attributes The block attributes.
 *
 * @return string Rendered block.
 */
function render_block_core_legacy_widget($attributes)
{
    global $wp_widget_factory;
    if (isset($attributes['id'])) {
        $sidebar_id = wp_find_widgets_sidebar($attributes['id']);
        return wp_render_widget($attributes['id'], $sidebar_id);
    }
    if (!isset($attributes['idBase'])) {
        return '';
    }
    $id_base = $attributes['idBase'];
    if (method_exists($wp_widget_factory, 'get_widget_key') && method_exists($wp_widget_factory, 'get_widget_object')) {
        $widget_key = $wp_widget_factory->get_widget_key($id_base);
        $widget_object = $wp_widget_factory->get_widget_object($id_base);
    } else {
        /*
         * This file is copied from the published @wordpress/widgets package when WordPress
         * Core is built. Because the package is a dependency of both WordPress Core and the
         * Gutenberg plugin where the block editor is developed, this fallback condition is
         * required until the minimum required version of WordPress for the plugin is raised
         * to 5.8.
         */
        $widget_key = gutenberg_get_widget_key($id_base);
        $widget_object = gutenberg_get_widget_object($id_base);
    }
    if (!$widget_key || !$widget_object) {
        return '';
    }
    if (isset($attributes['instance']['encoded'], $attributes['instance']['hash'])) {
        $serialized_instance = base64_decode($attributes['instance']['encoded']);
        if (!hash_equals(wp_hash($serialized_instance), (string) $attributes['instance']['hash'])) {
            return '';
        }
        $instance = unserialize($serialized_instance);
    } else {
        $instance = array();
    }
    $args = array('widget_id' => $widget_object->id, 'widget_name' => $widget_object->name);
    ob_start();
    the_widget($widget_key, $instance, $args);
    return ob_get_clean();
}

WordPress Version: 5.8

/**
 * Server-side rendering of the `core/legacy-widget` block.
 *
 * @package WordPress
 */
/**
 * Renders the 'core/legacy-widget' block.
 *
 * @param array $attributes The block attributes.
 *
 * @return string Rendered block.
 */
function render_block_core_legacy_widget($attributes)
{
    global $wp_widget_factory;
    if (isset($attributes['id'])) {
        $sidebar_id = wp_find_widgets_sidebar($attributes['id']);
        return wp_render_widget($attributes['id'], $sidebar_id);
    }
    if (!isset($attributes['idBase'])) {
        return '';
    }
    $id_base = $attributes['idBase'];
    if (method_exists($wp_widget_factory, 'get_widget_key') && method_exists($wp_widget_factory, 'get_widget_object')) {
        $widget_key = $wp_widget_factory->get_widget_key($id_base);
        $widget_object = $wp_widget_factory->get_widget_object($id_base);
    } else {
        /*
         * This file is copied from the published @wordpress/widgets package when WordPress
         * Core is built. Because the package is a dependency of both WordPress Core and the
         * Gutenberg plugin where the block editor is developed, this fallback condition is
         * required until the minimum required version of WordPress for the plugin is raised
         * to 5.8.
         */
        $widget_key = gutenberg_get_widget_key($id_base);
        $widget_object = gutenberg_get_widget_object($id_base);
    }
    if (!$widget_key || !$widget_object) {
        return '';
    }
    if (isset($attributes['instance']['encoded'], $attributes['instance']['hash'])) {
        $serialized_instance = base64_decode($attributes['instance']['encoded']);
        if (wp_hash($serialized_instance) !== $attributes['instance']['hash']) {
            return '';
        }
        $instance = unserialize($serialized_instance);
    } else {
        $instance = array();
    }
    $args = array('widget_id' => $widget_object->id, 'widget_name' => $widget_object->name);
    ob_start();
    the_widget($widget_key, $instance, $args);
    return ob_get_clean();
}