Administration: Allow context and priority to be specified when adding dashboard widgets.

Props davidjlaietta, soulseekah, johnbillion

Fixes #42791

Built from https://develop.svn.wordpress.org/trunk@49123


git-svn-id: http://core.svn.wordpress.org/trunk@48885 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2020-10-10 20:40:05 +00:00
parent cdd8b2cbfa
commit da04189357
3 changed files with 22 additions and 12 deletions

View File

@ -15,7 +15,7 @@
* *
* @global array $wp_registered_widgets * @global array $wp_registered_widgets
* @global array $wp_registered_widget_controls * @global array $wp_registered_widget_controls
* @global array $wp_dashboard_control_callbacks * @global callable[] $wp_dashboard_control_callbacks
*/ */
function wp_dashboard_setup() { function wp_dashboard_setup() {
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
@ -157,8 +157,9 @@ function wp_dashboard_setup() {
* Adds a new dashboard widget. * Adds a new dashboard widget.
* *
* @since 2.7.0 * @since 2.7.0
* @since 5.6.0 The `$context` and `$priority` parameters were added.
* *
* @global array $wp_dashboard_control_callbacks * @global callable[] $wp_dashboard_control_callbacks
* *
* @param string $widget_id Widget ID (used in the 'id' attribute for the widget). * @param string $widget_id Widget ID (used in the 'id' attribute for the widget).
* @param string $widget_name Title of the widget. * @param string $widget_name Title of the widget.
@ -167,8 +168,12 @@ function wp_dashboard_setup() {
* @param callable $control_callback Optional. Function that outputs controls for the widget. Default null. * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
* @param array $callback_args Optional. Data that should be set as the $args property of the widget array * @param array $callback_args Optional. Data that should be set as the $args property of the widget array
* (which is the second parameter passed to your callback). Default null. * (which is the second parameter passed to your callback). Default null.
* @param string $context Optional. The context within the screen where the box should display.
* Accepts 'normal', 'side', 'column3', or 'column4'. Default 'normal'.
* @param string $priority Optional. The priority within the context where the box should show.
* Accepts 'high', 'core', 'default', or 'low'. Default 'core'.
*/ */
function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) { function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core' ) {
$screen = get_current_screen(); $screen = get_current_screen();
global $wp_dashboard_control_callbacks; global $wp_dashboard_control_callbacks;
@ -194,19 +199,24 @@ function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_
$side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' ); $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
$location = 'normal';
if ( in_array( $widget_id, $side_widgets, true ) ) { if ( in_array( $widget_id, $side_widgets, true ) ) {
$location = 'side'; $context = 'side';
} }
$high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' ); $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
$priority = 'core';
if ( in_array( $widget_id, $high_priority_widgets, true ) ) { if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
$priority = 'high'; $priority = 'high';
} }
add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args ); if ( empty( $context ) ) {
$context = 'normal';
}
if ( empty( $priority ) ) {
$priority = 'core';
}
add_meta_box( $widget_id, $widget_name, $callback, $screen, $context, $priority, $callback_args );
} }
/** /**
@ -1139,7 +1149,7 @@ function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = ar
* *
* @since 2.5.0 * @since 2.5.0
* *
* @global array $wp_dashboard_control_callbacks * @global callable[] $wp_dashboard_control_callbacks
* *
* @param int $widget_control_id Registered Widget ID. * @param int $widget_control_id Registered Widget ID.
*/ */

View File

@ -1014,14 +1014,14 @@ function wp_import_upload_form( $action ) {
* add_submenu_page() to create a new screen (and hence screen_id), * add_submenu_page() to create a new screen (and hence screen_id),
* make sure your menu slug conforms to the limits of sanitize_key() * make sure your menu slug conforms to the limits of sanitize_key()
* otherwise the 'screen' menu may not correctly render on your page. * otherwise the 'screen' menu may not correctly render on your page.
* @param string $context Optional. The context within the screen where the boxes * @param string $context Optional. The context within the screen where the box
* should display. Available contexts vary from screen to * should display. Available contexts vary from screen to
* screen. Post edit screen contexts include 'normal', 'side', * screen. Post edit screen contexts include 'normal', 'side',
* and 'advanced'. Comments screen contexts include 'normal' * and 'advanced'. Comments screen contexts include 'normal'
* and 'side'. Menus meta boxes (accordion sections) all use * and 'side'. Menus meta boxes (accordion sections) all use
* the 'side' context. Global default is 'advanced'. * the 'side' context. Global default is 'advanced'.
* @param string $priority Optional. The priority within the context where the boxes * @param string $priority Optional. The priority within the context where the box should show.
* should show ('high', 'low'). Default 'default'. * Accepts 'high', 'core', 'default', or 'low'. Default 'default'.
* @param array $callback_args Optional. Data that should be set as the $args property * @param array $callback_args Optional. Data that should be set as the $args property
* of the box array (which is the second parameter passed * of the box array (which is the second parameter passed
* to your callback). Default null. * to your callback). Default null.

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.6-alpha-49122'; $wp_version = '5.6-alpha-49123';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.