Advertisements

wp_add_dashboard_widget

Definition:
function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {}

Parameters

  • $widget_id
  • $widget_name
  • $callback
  • $control_callback

Source code

function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {

	$screen = get_current_screen();

	global $wp_dashboard_control_callbacks;



	if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {

		$wp_dashboard_control_callbacks[$widget_id] = $control_callback;

		if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {

			list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );

			$widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';

			$callback = '_wp_dashboard_control_callback';

		} else {

			list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );

			$widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';

		}

	}



	if ( is_blog_admin () )

		$side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');

	else if (is_network_admin() )

		$side_widgets = array('dashboard_primary', 'dashboard_secondary');

	else

		$side_widgets = array();



	$location = 'normal';

	if ( in_array($widget_id, $side_widgets) )

		$location = 'side';



	$priority = 'core';

	if ( 'dashboard_browser_nag' === $widget_id )

		$priority = 'high';



	add_meta_box( $widget_id, $widget_name, $callback, $screen->id, $location, $priority );

}

3413

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: