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"; } - ?>
@@ -281,6 +300,7 @@ // Posts and Pages. foreach ( array( 'post', 'page' ) as $post_type ) { $num_posts = wp_count_posts( $post_type ); + if ( $num_posts && $num_posts->publish ) { if ( 'post' === $post_type ) { /* translators: %s: Number of posts. */ @@ -289,8 +309,10 @@ /* translators: %s: Number of pages. */ $text = _n( '%s Page', '%s Pages', $num_posts->publish ); } + $text = sprintf( $text, number_format_i18n( $num_posts->publish ) ); $post_type_object = get_post_type_object( $post_type ); + if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { printf( '
  • %2$s
  • ', $post_type, $text ); } else { @@ -298,25 +320,25 @@ } } } + // Comments. $num_comm = wp_count_comments(); + if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) { /* translators: %s: Number of comments. */ $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) ); ?> -
  • +
  • + +
  • moderated ); /* translators: %s: Number of comments. */ $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n ); ?> -
  • +
  • + +
  • $content

    "; @@ -416,6 +441,7 @@ */ function wp_network_dashboard_right_now() { $actions = array(); + if ( current_user_can( 'create_sites' ) ) { $actions['create-site'] = '' . __( 'Create a New Site' ) . ''; } @@ -458,18 +484,18 @@ do_action( 'wpmuadminresult' ); ?> -
    +

    - + 'submit_users' ) ); ?>

    -
    +

    - + 'submit_sites' ) ); ?>

    @@ -496,7 +522,7 @@ * * @global int $post_ID * - * @param string $error_msg Optional. Error message. Default false. + * @param string|false $error_msg Optional. Error message. Default false. */ function wp_dashboard_quick_press( $error_msg = false ) { global $post_ID; @@ -505,10 +531,12 @@ return; } - /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */ + // Check if a new auto-draft (= no new post_ID) is needed or if the old can be used. $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID. + if ( $last_post_id ) { $post = get_post( $last_post_id ); + if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore. $post = get_default_post_to_edit( 'post', true ); update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID. @@ -518,6 +546,7 @@ } else { $post = get_default_post_to_edit( 'post', true ); $user_id = get_current_user_id(); + // Don't create an option if this is a super admin who does not belong to this site. if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) { update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID. @@ -567,7 +596,7 @@ * * @since 2.7.0 * - * @param WP_Post[] $drafts Optional. Array of posts to display. Default false. + * @param WP_Post[]|false $drafts Optional. Array of posts to display. Default false. */ function wp_dashboard_recent_drafts( $drafts = false ) { if ( ! $drafts ) { @@ -596,6 +625,7 @@ } echo '
    '; + if ( count( $drafts ) > 3 ) { printf( '

    %s

    ' . "\n", @@ -603,15 +633,18 @@ __( 'View all drafts' ) ); } - echo '

    ' . __( 'Your Recent Drafts' ) . "

    \n
      "; + + echo '

      ' . __( 'Your Recent Drafts' ) . "

      \n"; + echo '
        '; /* translators: Maximum number of words used in a preview of a draft on the dashboard. */ - $draft_length = intval( _x( '10', 'draft_length' ) ); + $draft_length = (int) _x( '10', 'draft_length' ); $drafts = array_slice( $drafts, 0, 3 ); foreach ( $drafts as $draft ) { $url = get_edit_post_link( $draft->ID ); $title = _draft_or_post_title( $draft->ID ); + echo "
      • \n"; printf( '
        %s
        ', @@ -622,13 +655,17 @@ get_the_time( 'c', $draft ), get_the_time( __( 'F j, Y' ), $draft ) ); + $the_content = wp_trim_words( $draft->post_content, $draft_length ); + if ( $the_content ) { echo '

        ' . $the_content . '

        '; } echo "
      • \n"; } - echo "
      \n
    "; + + echo "\n"; + echo '
    '; } /** @@ -646,7 +683,6 @@ $GLOBALS['comment'] = clone $comment; if ( $comment->comment_post_ID > 0 ) { - $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); $comment_post_url = get_the_permalink( $comment->comment_post_ID ); $comment_post_link = "$comment_post_title"; @@ -928,7 +964,7 @@ 'post_status' => $args['status'], 'orderby' => 'date', 'order' => $args['order'], - 'posts_per_page' => intval( $args['max'] ), + 'posts_per_page' => (int) $args['max'], 'no_found_rows' => true, 'cache_results' => false, 'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable', @@ -942,7 +978,8 @@ * @param array $query_args The arguments passed to WP_Query to produce the list of posts. */ $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args ); - $posts = new WP_Query( $query_args ); + + $posts = new WP_Query( $query_args ); if ( $posts->have_posts() ) { @@ -960,15 +997,16 @@ $posts->the_post(); $time = get_the_time( 'U' ); - if ( gmdate( 'Y-m-d', $time ) == $today ) { + + if ( gmdate( 'Y-m-d', $time ) === $today ) { $relative = __( 'Today' ); - } elseif ( gmdate( 'Y-m-d', $time ) == $tomorrow ) { + } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) { $relative = __( 'Tomorrow' ); } elseif ( gmdate( 'Y', $time ) !== $year ) { - /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/date */ + /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */ $relative = date_i18n( __( 'M jS Y' ), $time ); } else { - /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/date */ + /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/manual/datetime.format.php */ $relative = date_i18n( __( 'M jS' ), $time ); } @@ -1015,6 +1053,7 @@ 'number' => $total_items * 5, 'offset' => 0, ); + if ( ! current_user_can( 'edit_posts' ) ) { $comments_query['status'] = 'approve'; } @@ -1023,21 +1062,25 @@ if ( ! is_array( $possible ) ) { break; } + foreach ( $possible as $comment ) { if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) { continue; } + $comments[] = $comment; - if ( count( $comments ) == $total_items ) { + + if ( count( $comments ) === $total_items ) { break 2; } } + $comments_query['offset'] += $comments_query['number']; $comments_query['number'] = $total_items * 10; } if ( $comments ) { - echo '
    '; + echo '
    '; echo '

    ' . __( 'Recent Comments' ) . '

    '; echo '
      '; @@ -1099,16 +1142,19 @@ if ( empty( $check_urls ) ) { $widgets = get_option( 'dashboard_widget_options' ); + if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) { echo $loading; return false; } + $check_urls = array( $widgets[ $widget_id ]['url'] ); } $locale = get_user_locale(); $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); $output = get_transient( $cache_key ); + if ( false !== $output ) { echo $output; return true; @@ -1139,14 +1185,17 @@ * * @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|false $widget_control_id Optional. Registered widget ID. Default false. */ function wp_dashboard_trigger_widget_control( $widget_control_id = false ) { global $wp_dashboard_control_callbacks; - if ( is_scalar( $widget_control_id ) && $widget_control_id && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] ) && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] ) ) { + if ( is_scalar( $widget_control_id ) && $widget_control_id + && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] ) + && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] ) + ) { call_user_func( $wp_dashboard_control_callbacks[ $widget_control_id ], '', @@ -1171,6 +1220,7 @@ */ function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { $widget_options = get_option( 'dashboard_widget_options' ); + if ( ! $widget_options ) { $widget_options = array(); } @@ -1199,7 +1249,9 @@ unset( $rss ); } } + update_option( 'dashboard_widget_options', $widget_options ); + $locale = get_user_locale(); $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); delete_transient( $cache_key ); @@ -1379,13 +1431,28 @@
    - {{ event.formatted_date }} + {{ event.user_formatted_date }} <# if ( 'meetup' === event.type ) { #> - {{ event.formatted_time }} + + {{ event.user_formatted_time }} {{ event.timeZoneAbbreviation }} + <# } #>
    <# } ) #> + + <# if ( data.events.length <= 2 ) { #> +
  • + Help organize the next one!' ), + __( 'https://make.wordpress.org/community/organize-event-landing-page/' ) + ); + ?> +
  • + <# } #> +