Make WordPress Core

Changeset 49123

Timestamp:
10/10/2020 08:38:49 PM (4 years ago)
Author:
johnbillion
Message:

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

Props davidjlaietta, soulseekah, johnbillion

Fixes #42791

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/dashboard.php

    r49114 r49123  
    1616 * @global array $wp_registered_widgets
    1717 * @global array $wp_registered_widget_controls
    18  * @global array $wp_dashboard_control_callbacks
     18 * @global $wp_dashboard_control_callbacks
    1919 */
    2020function wp_dashboard_setup() {
     
    158158 *
    159159 * @since 2.7.0
    160  *
    161  * @global array $wp_dashboard_control_callbacks
     160 * @since 5.6.0 The `$context` and `$priority` parameters were added.
     161 *
     162 * @global callable[] $wp_dashboard_control_callbacks
    162163 *
    163164 * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
     
    168169 * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
    169170 *                                   (which is the second parameter passed to your callback). Default null.
    170  */
    171 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
     171 * @param string   $context          Optional. The context within the screen where the box should display.
     172 *                                   Accepts 'normal', 'side', 'column3', or 'column4'. Default 'normal'.
     173 * @param string   $priority         Optional. The priority within the context where the box should show.
     174 *                                   Accepts 'high', 'core', 'default', or 'low'. Default 'core'.
     175 */
     176function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core' ) {
    172177    $screen = get_current_screen();
    173178    global $wp_dashboard_control_callbacks;
     
    195200    $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
    196201
    197     $location = 'normal';
    198202    if ( in_array( $widget_id, $side_widgets, true ) ) {
    199         $location = 'side';
     203        $ = 'side';
    200204    }
    201205
    202206    $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
    203207
    204     $priority = 'core';
    205208    if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
    206209        $priority = 'high';
    207210    }
    208211
    209     add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
     212    if ( empty( $context ) ) {
     213        $context = 'normal';
     214    }
     215    if ( empty( $priority ) ) {
     216        $priority = 'core';
     217    }
     218
     219    add_meta_box( $widget_id, $widget_name, $callback, $screen, $context, $priority, $callback_args );
    210220}
    211221
     
    11401150 * @since 2.5.0
    11411151 *
    1142  * @global array $wp_dashboard_control_callbacks
     1152 * @global $wp_dashboard_control_callbacks
    11431153 *
    11441154 * @param int $widget_control_id Registered Widget ID.
  • trunk/src/wp-admin/includes/template.php

    r49108 r49123  
    10151015 *                                              make sure your menu slug conforms to the limits of sanitize_key()
    10161016 *                                              otherwise the 'screen' menu may not correctly render on your page.
    1017  * @param string                 $context       Optional. The context within the screen where the boxes
     1017 * @param string                 $context       Optional. The context within the screen where the box
    10181018 *                                              should display. Available contexts vary from screen to
    10191019 *                                              screen. Post edit screen contexts include 'normal', 'side',
     
    10211021 *                                              and 'side'. Menus meta boxes (accordion sections) all use
    10221022 *                                              the 'side' context. Global default is 'advanced'.
    1023  * @param string                 $priority      Optional. The priority within the context where the boxes
    1024  *                                              should show ('high', 'low'). Default 'default'.
     1023 * @param string                 $priority      Optional. The priority within the context where the box
     1024 *                                              . Default 'default'.
    10251025 * @param array                  $callback_args Optional. Data that should be set as the $args property
    10261026 *                                              of the box array (which is the second parameter passed
  • trunk/tests/phpunit/tests/admin/includesTemplate.php

    r48939 r49123  
    202202    }
    203203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
     224
     225
     226
     227
     228
     229
     230
     231
     232
     233
     234
     235
     236
     237
     238
     239
     240
    204241}
Note: See TracChangeset for help on using the changeset viewer.