On this page
WP_Customize_Widgets::render_widget_partial( WP_Customize_Partial $partial, array $context ): string|false
Renders a specific widget using the supplied sidebar arguments.
Description
See also
Parameters
$partialWP_Customize_Partial Required-
Partial.
$contextarray Required-
Sidebar args supplied as container context.
sidebar_idstringID for sidebar for widget to render into.sidebar_instance_numberintDisambiguating instance number.
Return
string|false
Source
File: wp-includes/class-wp-customize-widgets.php. View all references
public function render_widget_partial( $partial, $context ) {
$id_data = $partial->id_data();
$widget_id = array_shift( $id_data['keys'] );
if ( ! is_array( $context )
|| empty( $context['sidebar_id'] )
|| ! is_registered_sidebar( $context['sidebar_id'] )
) {
return false;
}
$this->rendering_sidebar_id = $context['sidebar_id'];
if ( isset( $context['sidebar_instance_number'] ) ) {
$this->context_sidebar_instance_number = (int) $context['sidebar_instance_number'];
}
// Filter sidebars_widgets so that only the queried widget is in the sidebar.
$this->rendering_widget_id = $widget_id;
$filter_callback = array( $this, 'filter_sidebars_widgets_for_rendering_widget' );
add_filter( 'sidebars_widgets', $filter_callback, 1000 );
// Render the widget.
ob_start();
$this->rendering_sidebar_id = $context['sidebar_id'];
dynamic_sidebar( $this->rendering_sidebar_id );
$container = ob_get_clean();
// Reset variables for next partial render.
remove_filter( 'sidebars_widgets', $filter_callback, 1000 );
$this->context_sidebar_instance_number = null;
$this->rendering_sidebar_id = null;
$this->rendering_widget_id = null;
return $container;
}
Related
Uses
| Uses | Description |
|---|---|
| is_registered_sidebar() wp-includes/widgets.php | Checks if a sidebar is registered. |
| remove_filter() wp-includes/plugin.php | Removes a callback function from a filter hook. |
| dynamic_sidebar() wp-includes/widgets.php | Display dynamic sidebar. |
| add_filter() wp-includes/plugin.php | Adds a callback function to a filter hook. |
Changelog
| Version | Description |
|---|---|
| 4.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_widgets/render_widget_partial