Advertisements

wp_register_sidebar_widget

Definition:
function wp_register_sidebar_widget($id, $name, $output_callback, $options = array() {}

Register widget for use in sidebars.
The default widget option is ‘classname’ that can be override.

Parameters

  • int|string $id: Widget ID.
  • string $name: Widget display title.
  • callback $output_callback: Run when widget is called.
  • array|string $options: Optional. Widget Options.
  • mixed $params,…: Widget parameters to add to widget.

Return values

returns:Will return if $output_callback is empty after removing widget.

Defined actions

  • wp_register_sidebar_widget
    do_action( 'wp_register_sidebar_widget', $widget );

Source code

function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) {

	global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks;



	$id = strtolower($id);



	if ( empty($output_callback) ) {

		unset($wp_registered_widgets[$id]);

		return;

	}



	$id_base = _get_widget_id_base($id);

	if ( in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($output_callback) ) {

		if ( isset($wp_registered_widget_controls[$id]) )

			unset($wp_registered_widget_controls[$id]);



		if ( isset($wp_registered_widget_updates[$id_base]) )

			unset($wp_registered_widget_updates[$id_base]);



		return;

	}



	$defaults = array('classname' => $output_callback);

	$options = wp_parse_args($options, $defaults);

	$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;

	}

}

4023

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: