function gutenberg_render_block_legacy_widget in Gutenberg 8
Renders the `core/legacy-widget` block on server.
Parameters
array $attributes The block attributes.:
Return value
string Returns the post content with the legacy widget added.
See also
WP_Widget
1 string reference to 'gutenberg_render_block_legacy_widget'
- gutenberg_register_block_core_legacy_widget in vendor/
gutenberg/ block-library/ blocks/ legacy-widget.php - Register legacy widget block.
File
- vendor/
gutenberg/ block-library/ blocks/ legacy-widget.php, line 17
Code
function gutenberg_render_block_legacy_widget($attributes) {
if (!isset($attributes['identifier'])) {
return '';
}
$identifier = $attributes['identifier'];
if (isset($attributes['isCallbackWidget']) && $attributes['isCallbackWidget']) {
global $wp_registered_widgets;
if (!isset($wp_registered_widgets[$identifier])) {
return '';
}
$widget = $wp_registered_widgets[$identifier];
$params = array_merge(array(
'widget_id' => $identifier,
'widget_name' => $widget['name'],
), (array) $wp_registered_widgets[$identifier]['params']);
$params = apply_filters('dynamic_sidebar_params', $params);
$callback = $widget['callback'];
if (is_callable($callback)) {
ob_start();
call_user_func_array($callback, $params);
return ob_get_clean();
}
return '';
}
ob_start();
the_widget($identifier, $attributes['instance']);
return ob_get_clean();
}