1

I have been reading through the Wordpress Source, trying to get a better understanding of how dynamic sidebars are rendered.

However, I am hitting a sticking point...

894 | do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );

I can't find where add_action('dynamic_sidebar', ... ) is defined. Without out that part, I am sort of lost in what happens.

See the code here:

https://github.com/WordPress/WordPress/blob/b7c13e27c255e1fc1f03ab2ab432f1652a0ac212/wp-includes/widgets.php#L894

And to give more context, I am trying to figure out how to grab an array of widgets, and then from there, how would you render each one.

I need finer control than dynamic_sidebar(...); gives me

1 Answer 1

1

That action is just there in case a plugin or theme wants to do something before sidebars are rendered. The code you're looking for is in widgets.php, just before and just after that action:

$callback = $wp_registered_widgets[$id]['callback'];

do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );

if ( is_callable($callback) ) {
    call_user_func_array($callback, $params);
    $did_one = true;
}

In the wp_register_sidebar_widget() function, you can see where $wp_registered_widgets[$id] gets set to an array of information about the widget, including the display/output callback:

$widget = array(
    'name' => $name,
    'id' => $id,
    'callback' => $output_callback,
    'params' => array_slice(func_get_args(), 4)
);
$widget = array_merge($widget, $options);

if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || did_action( 'widgets_init' ) ) ) {
    do_action( 'wp_register_sidebar_widget', $widget );
    $wp_registered_widgets[$id] = $widget;
}
1
  • Ok, I think I got it now... Just to clarify, it is actually the callback that is doing the widget rendering then? and is there any standard way a widget renders/ any code one can recommend to get a better idea of individual widget rendering?
    – user37710
    Commented Sep 9, 2013 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.