diff -r 34716fd837a4 -r be944660c56a wp/wp-admin/includes/dashboard.php --- a/wp/wp-admin/includes/dashboard.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-admin/includes/dashboard.php Wed Sep 21 18:19:35 2022 +0200 @@ -15,10 +15,11 @@ * * @global array $wp_registered_widgets * @global array $wp_registered_widget_controls - * @global array $wp_dashboard_control_callbacks + * @global callable[] $wp_dashboard_control_callbacks */ function wp_dashboard_setup() { global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; + $wp_dashboard_control_callbacks = array(); $screen = get_current_screen(); @@ -28,6 +29,7 @@ if ( $response && $response['upgrade'] ) { add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' ); + if ( $response['insecure'] ) { wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' ); } else { @@ -37,9 +39,13 @@ // PHP Version. $response = wp_check_php_version(); - if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] && current_user_can( 'update_php' ) ) { + + if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] + && current_user_can( 'update_php' ) + ) { add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' ); - wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' ); + + wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' ); } // Site Health. @@ -157,8 +163,9 @@ * Adds a new dashboard widget. * * @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_name Title of the widget. @@ -167,10 +174,15 @@ * @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 * (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' ) { + global $wp_dashboard_control_callbacks; + $screen = get_current_screen(); - global $wp_dashboard_control_callbacks; $private_callback_args = array( '__widget_basename' => $widget_name ); @@ -180,9 +192,10 @@ $callback_args = array_merge( $callback_args, $private_callback_args ); } - if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) { + if ( $control_callback && is_callable( $control_callback ) && current_user_can( 'edit_dashboard' ) ) { $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback; - if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) { + + if ( isset( $_GET['edit'] ) && $widget_id === $_GET['edit'] ) { list($url) = explode( '#', add_query_arg( 'edit', false ), 2 ); $widget_name .= ' ' . __( 'Cancel' ) . ''; $callback = '_wp_dashboard_control_callback'; @@ -194,19 +207,25 @@ $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' ); - $location = 'normal'; if ( in_array( $widget_id, $side_widgets, true ) ) { - $location = 'side'; + $context = 'side'; } $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' ); - $priority = 'core'; if ( in_array( $widget_id, $high_priority_widgets, true ) ) { $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 ); } /** @@ -236,10 +255,10 @@ $screen = get_current_screen(); $columns = absint( $screen->get_columns() ); $columns_css = ''; + if ( $columns ) { $columns_css = " columns-$columns"; } - ?>