X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7f1521bf193b382565eb753043c161f4cb3fcda7..3194d1bb103c2d8db4f44feeced5e58ee2756658:/wp-admin/includes/dashboard.php diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index 7179aa34..144fcc04 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -12,6 +12,10 @@ * Handles POST data, sets up filters. * * @since 2.5.0 + * + * @global array $wp_registered_widgets + * @global array $wp_registered_widget_controls + * @global array $wp_dashboard_control_callbacks */ function wp_dashboard_setup() { global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; @@ -43,7 +47,7 @@ function wp_dashboard_setup() { } // QuickPress Widget - if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) { + if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { $quick_draft_title = sprintf( '%1$s %2$s', __( 'Quick Draft' ), __( 'Drafts' ) ); wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' ); } @@ -125,6 +129,16 @@ function wp_dashboard_setup() { do_action( 'do_meta_boxes', $screen->id, 'side', '' ); } +/** + * + * @global array $wp_dashboard_control_callbacks + * + * @param string $widget_id + * @param string $widget_name + * @param callable $callback + * @param callable $control_callback + * @param array $callback_args + */ function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) { $screen = get_current_screen(); global $wp_dashboard_control_callbacks; @@ -154,6 +168,11 @@ function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_ add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args ); } +/** + * + * @param type $dashboard + * @param type $meta_box + */ function _wp_dashboard_control_callback( $dashboard, $meta_box ) { echo '
'; wp_dashboard_trigger_widget_control( $meta_box['id'] ); @@ -240,13 +259,15 @@ function wp_dashboard_right_now() { ?>
  • moderated ) { - /* translators: Number of comments in moderation */ - $text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) ); - ?> -
  • - moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) ); + ?> +
  • + - 'submit_users' ) ); ?> + 'submit_users' ) ); ?>

    @@ -389,7 +413,7 @@ function wp_network_dashboard_right_now() {

    - 'submit_sites' ) ); ?> + 'submit_sites' ) ); ?>

    'modified', 'order' => 'DESC' ); + + /** + * Filter the post query arguments for the 'Recent Drafts' dashboard widget. + * + * @since 4.4.0 + * + * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget. + */ + $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args ); + $drafts = get_posts( $query_args ); if ( ! $drafts ) { return; @@ -498,9 +540,9 @@ function wp_dashboard_recent_drafts( $drafts = false ) { echo '
    '; if ( count( $drafts ) > 3 ) { - echo '

    ' . _x( 'View all', 'drafts' ) . "

    \n"; + echo '

    ' . _x( 'View all', 'drafts' ) . "

    \n"; } - echo '

    ' . __( 'Drafts' ) . "

    \n
    "; } +/** + * @global WP_Comment $comment + * + * @param WP_Comment $comment + * @param bool $show_date + */ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { - $GLOBALS['comment'] =& $comment; + $GLOBALS['comment'] = clone $comment; - $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); - - if ( current_user_can( 'edit_post', $comment->comment_post_ID ) ) { + if ( $comment->comment_post_ID > 0 && current_user_can( 'edit_post', $comment->comment_post_ID ) ) { + $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); $comment_post_url = get_edit_post_link( $comment->comment_post_ID ); $comment_post_link = "$comment_post_title"; } else { - $comment_post_link = $comment_post_title; + $comment_post_link = ''; } - $comment_link = '#'; - $actions_string = ''; if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) { // Pre-order it: Approve | Reply | Edit | Spam | Trash. @@ -539,7 +584,8 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { 'reply' => '', 'edit' => '', 'spam' => '', - 'trash' => '', 'delete' => '' + 'trash' => '', 'delete' => '', + 'view' => '', ); $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); @@ -556,10 +602,16 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { $actions['edit'] = "". __('Edit') . ''; $actions['reply'] = '' . __('Reply') . ''; $actions['spam'] = "" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . ''; - if ( !EMPTY_TRASH_DAYS ) + + if ( ! EMPTY_TRASH_DAYS ) { $actions['delete'] = "" . __('Delete Permanently') . ''; - else + } else { $actions['trash'] = "" . _x('Trash', 'verb') . ''; + } + + if ( '1' === $comment->comment_approved ) { + $actions['view'] = '' . _x( 'View', 'verb' ) . ''; + } /** * Filter the action links displayed for each comment in the 'Recent Comments' @@ -567,10 +619,10 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { * * @since 2.6.0 * - * @param array $actions An array of comment actions. Default actions include: - * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam', - * 'Delete', and 'Trash'. - * @param object $comment The comment object. + * @param array $actions An array of comment actions. Default actions include: + * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam', + * 'Delete', and 'Trash'. + * @param WP_Comment $comment The comment object. */ $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment ); @@ -589,17 +641,33 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { ?> -
    comment_ID) ) ); ?>> +
    > comment_type || 'comment' == $comment->comment_type ) : ?> -
    -

    - ' . get_comment_author_link() . '', $comment_post_link.' '.$comment_link, ' ' . __( '[Pending]' ) . '' ); ?> -

    +
    +

    + ' . get_comment_author_link( $comment ) . '', + $comment_post_link, + ' ' . __( '[Pending]' ) . '' + ); + } else { + printf( + /* translators: 1: comment author, 2: notification if the comment is pending */ + __( 'From %1$s %2$s' ), + '' . get_comment_author_link( $comment ) . '', + ' ' . __( '[Pending]' ) . '' + ); + } + ?> +

    -
    +
    -

    $type", $comment_post_link." ".$comment_link ); ?>

    -

    +

    $type", $comment_post_link ); ?>

    +

    -

    +

    '; - echo '

    ' . $args['title'] . '

    '; + echo '

    ' . $args['title'] . '

    '; echo '
      '; @@ -721,6 +790,9 @@ function wp_dashboard_recent_posts( $args ) { $relative = __( 'Today' ); } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) { $relative = __( 'Tomorrow' ); + } elseif ( date( 'Y', $time ) !== date( 'Y', current_time( 'timestamp' ) ) ) { + /* translators: date and time format for recent posts on the dashboard, from a different calendar year, see http://php.net/date */ + $relative = date_i18n( __( 'M jS Y' ), $time ); } else { /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */ $relative = date_i18n( __( 'M jS' ), $time ); @@ -766,6 +838,9 @@ function wp_dashboard_recent_comments( $total_items = 5 ) { $comments_query['status'] = 'approve'; while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) { + if ( ! is_array( $possible ) ) { + break; + } foreach ( $possible as $comment ) { if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) continue; @@ -779,7 +854,7 @@ function wp_dashboard_recent_comments( $total_items = 5 ) { if ( $comments ) { echo '
      '; - echo '

      ' . __( 'Comments' ) . '

      '; + echo '

      ' . __( 'Comments' ) . '

      '; echo '
      '; foreach ( $comments as $comment ) @@ -824,7 +899,7 @@ function wp_dashboard_rss_output( $widget_id ) { * @since 2.5.0 * * @param string $widget_id - * @param callback $callback + * @param callable $callback * @param array $check_urls RSS feeds * @return bool False on failure. True on success. */ @@ -841,7 +916,8 @@ function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = ar $check_urls = array( $widgets[$widget_id]['url'] ); } - $cache_key = 'dash_' . md5( $widget_id ); + $locale = get_locale(); + $cache_key = 'dash_' . md5( $widget_id . '_' . $locale ); if ( false !== ( $output = get_transient( $cache_key ) ) ) { echo $output; return true; @@ -863,14 +939,17 @@ function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = ar return true; } -/* Dashboard Widgets Controls */ +// +// Dashboard Widgets Controls +// -// Calls widget_control callback /** * Calls widget control callback. * * @since 2.5.0 * + * @global array $wp_dashboard_control_callbacks + * * @param int $widget_control_id Registered Widget ID. */ function wp_dashboard_trigger_widget_control( $widget_control_id = false ) { @@ -942,7 +1021,7 @@ function wp_dashboard_primary() { * * @param string $link The widget's primary link URL. */ - 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ), + 'link' => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ), /** * Filter the primary feed URL for the 'WordPress News' dashboard widget. @@ -994,7 +1073,15 @@ function wp_dashboard_primary() { * @param string $title Title attribute for the widget's secondary link. */ 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ), - 'items' => 3, + + /** + * Filter the number of secondary link items for the 'WordPress News' dashboard widget. + * + * @since 4.4.0 + * + * @param string $items How many items to show in the secondary feed. + */ + 'items' => apply_filters( 'dashboard_secondary_items', 3 ), 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0, @@ -1027,7 +1114,7 @@ function wp_dashboard_primary() { * @param array $feeds Array of RSS feeds. */ function wp_dashboard_primary_output( $widget_id, $feeds ) { - foreach( $feeds as $type => $args ) { + foreach ( $feeds as $type => $args ) { $args['type'] = $type; echo '
      '; if ( $type === 'plugins' ) { @@ -1137,7 +1224,7 @@ function wp_dashboard_quota() { $percentused = number_format( $percentused ); ?> -

      +

      • @@ -1170,7 +1257,6 @@ function wp_dashboard_quota() {
      %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) ); + /* translators: %s: browser name and link */ + $msg = sprintf( __( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ), + sprintf( '%s', esc_url( $response['update_url'] ), esc_html( $response['name'] ) ) + ); } else { - $msg = sprintf( __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) ); + /* translators: %s: browser name and link */ + $msg = sprintf( __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ), + sprintf( '%s', esc_url( $response['update_url'] ), esc_html( $response['name'] ) ) + ); } $browser_nag_class = ''; @@ -1214,6 +1306,12 @@ function wp_dashboard_browser_nag() { echo apply_filters( 'browse-happy-notice', $notice, $response ); } +/** + * @since 3.2.0 + * + * @param array $classes + * @return array + */ function dashboard_browser_nag_class( $classes ) { $response = wp_check_browser_version(); @@ -1228,6 +1326,8 @@ function dashboard_browser_nag_class( $classes ) { * * @since 3.2.0 * + * @global string $wp_version + * * @return array|bool False on failure, array of browser data on success. */ function wp_check_browser_version() { @@ -1252,8 +1352,8 @@ function wp_check_browser_version() { /** * Response should be an array with: * 'name' - string - A user friendly browser name - * 'version' - string - The most recent version of the browser - * 'current_version' - string - The version of the browser the user is using + * 'version' - string - The version of the browser the user is using + * 'current_version' - string - The most recent version of the browser * 'upgrade' - boolean - Whether the browser needs an upgrade * 'insecure' - boolean - Whether the browser is deemed insecure * 'upgrade_url' - string - The url to visit to upgrade @@ -1284,12 +1384,12 @@ function wp_dashboard_empty() {} function wp_welcome_panel() { ?>
      -

      +

      -

      +

      @@ -1298,7 +1398,7 @@ function wp_welcome_panel() {
      -

      +

      • ' . __( 'Edit your front page' ) . '', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?>
      • @@ -1315,7 +1415,7 @@ function wp_welcome_panel() {
      -

      +