wp_dashboard_setup

Registers dashboard widgets.

Description

wp_dashboard_setup(); 

Handles POST data, sets up filters.


Usage

  1. if ( !function_exists( 'wp_dashboard_setup' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_dashboard_setup(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_setup() { 
  2. global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; 
  3. $wp_dashboard_control_callbacks = array(); 
  4. $screen = get_current_screen(); 
  5.  
  6. /** Register Widgets and Controls */ 
  7.  
  8. $response = wp_check_browser_version(); 
  9.  
  10. if ( $response && $response['upgrade'] ) { 
  11. if ( $response['insecure'] ) 
  12. wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' ); 
  13. else 
  14. wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' ); 
  15.  
  16. // Right Now 
  17. if ( is_blog_admin() && current_user_can('edit_posts') ) 
  18. wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' ); 
  19.  
  20. if ( is_network_admin() ) 
  21. wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' ); 
  22.  
  23. // Activity Widget 
  24. if ( is_blog_admin() ) { 
  25. wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' ); 
  26.  
  27. // QuickPress Widget 
  28. if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { 
  29. $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Drafts' ) ); 
  30. wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' ); 
  31.  
  32. // WordPress News 
  33. wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress News' ), 'wp_dashboard_primary' ); 
  34.  
  35. if ( is_network_admin() ) { 
  36.  
  37. /** 
  38. * Fires after core widgets for the Network Admin dashboard have been registered. 
  39. * @since 3.1.0 
  40. */ 
  41.  
  42. /** 
  43. * Filters the list of widgets to load for the Network Admin dashboard. 
  44. * @since 3.1.0 
  45. * @param array $dashboard_widgets An array of dashboard widgets. 
  46. */ 
  47. $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() ); 
  48. } elseif ( is_user_admin() ) { 
  49.  
  50. /** 
  51. * Fires after core widgets for the User Admin dashboard have been registered. 
  52. * @since 3.1.0 
  53. */ 
  54.  
  55. /** 
  56. * Filters the list of widgets to load for the User Admin dashboard. 
  57. * @since 3.1.0 
  58. * @param array $dashboard_widgets An array of dashboard widgets. 
  59. */ 
  60. $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() ); 
  61. } else { 
  62.  
  63. /** 
  64. * Fires after core widgets for the admin dashboard have been registered. 
  65. * @since 2.5.0 
  66. */ 
  67.  
  68. /** 
  69. * Filters the list of widgets to load for the admin dashboard. 
  70. * @since 2.5.0 
  71. * @param array $dashboard_widgets An array of dashboard widgets. 
  72. */ 
  73. $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() ); 
  74.  
  75. foreach ( $dashboard_widgets as $widget_id ) { 
  76. $name = empty( $wp_registered_widgets[$widget_id]['all_link'] ) ? $wp_registered_widgets[$widget_id]['name'] : $wp_registered_widgets[$widget_id]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __('View all') . '</a>'; 
  77. wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] ); 
  78.  
  79. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) { 
  80. check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' ); 
  81. ob_start(); // hack - but the same hack wp-admin/widgets.php uses 
  82. wp_dashboard_trigger_widget_control( $_POST['widget_id'] ); 
  83. ob_end_clean(); 
  84. wp_redirect( remove_query_arg( 'edit' ) ); 
  85. exit; 
  86.  
  87. /** This action is documented in wp-admin/edit-form-advanced.php */ 
  88. do_action( 'do_meta_boxes', $screen->id, 'normal', '' ); 
  89.  
  90. /** This action is documented in wp-admin/edit-form-advanced.php */ 
  91. do_action( 'do_meta_boxes', $screen->id, 'side', '' );