Make WordPress Core


Ignore:
Timestamp:
11/13/2013 10:08:47 PM (11 years ago)
Author:
nacin
Message:

Merge the new dashboard design into core.

Merges https://github.com/growthdesigner/wp-dash.

props lessbloat, joen, helen, dbernar1, kraftbj, ryelle, tillkruess, grapplerulrich, markjaquith.
see #25824.

File:
1 edited

Legend:

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

    r25868 r26144  
    3838    // Right Now
    3939    if ( is_blog_admin() && current_user_can('edit_posts') )
    40         wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
     40        add_meta_box( 'dash-right-now', 'Site Content', 'dashboard_new_right_now', 'dashboard', 'normal', 'high' );
    4141
    4242    if ( is_network_admin() )
    4343        wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
    4444
    45     // Recent Comments Widget
    46     if ( is_blog_admin() && current_user_can('moderate_comments') ) {
    47         if ( !isset( $widget_options['dashboard_recent_comments'] ) || !isset( $widget_options['dashboard_recent_comments']['items'] ) ) {
    48             $update = true;
    49             $widget_options['dashboard_recent_comments'] = array(
    50                 'items' => 5,
    51             );
    52         }
    53         $recent_comments_title = __( 'Recent Comments' );
    54         wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments', 'wp_dashboard_recent_comments_control' );
    55     }
    56 
    57     // Incoming Links Widget
    58     if ( is_blog_admin() && current_user_can('publish_posts') ) {
    59         if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
    60             $update = true;
    61             $num_items = isset($widget_options['dashboard_incoming_links']['items']) ? $widget_options['dashboard_incoming_links']['items'] : 10;
    62             $widget_options['dashboard_incoming_links'] = array(
    63                 'home' => get_option('home'),
    64                 'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
    65                 'url' => isset($widget_options['dashboard_incoming_links']['url']) ? apply_filters( 'dashboard_incoming_links_feed', $widget_options['dashboard_incoming_links']['url'] ) : apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?scoring=d&ie=utf-8&num=' . $num_items . '&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
    66                 'items' => $num_items,
    67                 'show_date' => isset($widget_options['dashboard_incoming_links']['show_date']) ? $widget_options['dashboard_incoming_links']['show_date'] : false
    68             );
    69         }
    70         wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' );
    71     }
    72 
    73     // WP Plugins Widget
    74     if ( ( ! is_multisite() && is_blog_admin() && current_user_can( 'install_plugins' ) ) || ( is_network_admin() && current_user_can( 'manage_network_plugins' ) && current_user_can( 'install_plugins' ) ) )
    75         wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_plugins' );
     45    // Activity Widget
     46    add_meta_box( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_activity', 'dashboard', 'normal', 'high' );
    7647
    7748    // QuickPress Widget
    78     if ( is_blog_admin() && current_user_can('edit_posts') )
    79         wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press' );
    80 
    81     // Recent Drafts
    82     if ( is_blog_admin() && current_user_can('edit_posts') )
    83         wp_add_dashboard_widget( 'dashboard_recent_drafts', __('Recent Drafts'), 'wp_dashboard_recent_drafts' );
    84 
    85     // Primary feed (Dev Blog) Widget
    86     if ( !isset( $widget_options['dashboard_primary'] ) ) {
    87         $update = true;
    88         $widget_options['dashboard_primary'] = array(
    89             'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
    90             'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
    91             'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
    92             'items' => 2,
    93             'show_summary' => 1,
    94             'show_author' => 0,
    95             'show_date' => 1,
    96         );
    97     }
    98     wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
    99 
    100     // Secondary Feed (Planet) Widget
    101     if ( !isset( $widget_options['dashboard_secondary'] ) ) {
    102         $update = true;
    103         $widget_options['dashboard_secondary'] = array(
    104             'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
    105             'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
    106             'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
    107             'items' => 5,
    108             'show_summary' => 0,
    109             'show_author' => 0,
    110             'show_date' => 0,
    111         );
    112     }
    113     wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
     49    if ( is_blog_admin() && current_user_can( 'edit_posts' ) )
     50        add_meta_box( 'dashboard_quick_draft', __( 'Quick Draft' ), 'wp_dashboard_quick_draft', 'dashboard', 'side', 'high' );
     51
     52    // WordPress News
     53    add_meta_box( 'dashboard_rss', __( 'WordPress News' ), 'wp_dashboard_rss', 'dashboard', 'side', 'low' );
    11454
    11555    // Hook to register new widgets
     
    166106
    167107    if ( is_blog_admin () )
    168         $side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');
     108        $side_widgets = array('dashboard_quick_draft');
    169109    else if (is_network_admin() )
    170         $side_widgets = array('dashboard_primary', 'dashboard_secondary');
     110        $side_widgets = array();
    171111    else
    172112        $side_widgets = array();
     
    225165/* Dashboard Widgets */
    226166
    227 function wp_dashboard_right_now() {
    228     global $wp_registered_sidebars;
    229 
    230     $num_posts = wp_count_posts( 'post' );
    231     $num_pages = wp_count_posts( 'page' );
    232 
    233     $num_cats  = wp_count_terms('category');
    234 
    235     $num_tags = wp_count_terms('post_tag');
    236 
     167function dashboard_new_right_now() {
     168    $theme = wp_get_theme();
     169    if ( current_user_can( 'switch_themes' ) )
     170        $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme->display('Name') );
     171    else
     172        $theme_name = $theme->display('Name');
     173?>
     174    <div class="main">
     175    <ul>
     176    <?php
     177    do_action( 'rightnow_list_start' );
     178    // Using show_in_nav_menus as my arg for grabbing what post types should show, is there better?
     179    $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
     180    $post_types = (array) apply_filters( 'rightnow_post_types', $post_types );
     181    foreach ( $post_types as $post_type => $post_type_obj ){
     182        $num_posts = wp_count_posts( $post_type );
     183        if ( $num_posts && $num_posts->publish ) {
     184            printf(
     185                '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s %3$s</a></li>',
     186                $post_type,
     187                number_format_i18n( $num_posts->publish ),
     188                $post_type_obj->label
     189            );
     190        }
     191    }
     192    // Comments
    237193    $num_comm = wp_count_comments();
    238 
    239     echo "\n\t".'<div class="table table_content">';
    240     echo "\n\t".'<p class="sub">' . __('Content') . '</p>'."\n\t".'<table>';
    241     echo "\n\t".'<tr class="first">';
    242 
    243     // Posts
    244     $num = number_format_i18n( $num_posts->publish );
    245     $text = _n( 'Post', 'Posts', intval($num_posts->publish) );
    246     if ( current_user_can( 'edit_posts' ) ) {
    247         $num = "<a href='edit.php'>$num</a>";
    248         $text = "<a href='edit.php'>$text</a>";
    249     }
    250     echo '<td class="first b b-posts">' . $num . '</td>';
    251     echo '<td class="t posts">' . $text . '</td>';
    252 
    253     echo '</tr><tr>';
    254     /* TODO: Show status breakdown on hover
    255     if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds. Don't show if !current_user_can
    256         $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( _n( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
    257     }
    258     if ( $can_edit_posts && !empty($num_posts->draft) ) {
    259         $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( _n( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>';
    260     }
    261     if ( $can_edit_posts && !empty($num_posts->future) ) {
    262         $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( _n( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>';
    263     }
    264     if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
    265         $pending_text = sprintf( _n( 'There is <a href="%1$s">%2$s post</a> pending your review.', 'There are <a href="%1$s">%2$s posts</a> pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) );
    266     } else {
    267         $pending_text = '';
    268     }
    269     */
    270 
    271     // Pages
    272     $num = number_format_i18n( $num_pages->publish );
    273     $text = _n( 'Page', 'Pages', $num_pages->publish );
    274     if ( current_user_can( 'edit_pages' ) ) {
    275         $num = "<a href='edit.php?post_type=page'>$num</a>";
    276         $text = "<a href='edit.php?post_type=page'>$text</a>";
    277     }
    278     echo '<td class="first b b_pages">' . $num . '</td>';
    279     echo '<td class="t pages">' . $text . '</td>';
    280 
    281     echo '</tr><tr>';
    282 
    283     // Categories
    284     $num = number_format_i18n( $num_cats );
    285     $text = _n( 'Category', 'Categories', $num_cats );
    286     if ( current_user_can( 'manage_categories' ) ) {
    287         $num = "<a href='edit-tags.php?taxonomy=category'>$num</a>";
    288         $text = "<a href='edit-tags.php?taxonomy=category'>$text</a>";
    289     }
    290     echo '<td class="first b b-cats">' . $num . '</td>';
    291     echo '<td class="t cats">' . $text . '</td>';
    292 
    293     echo '</tr><tr>';
    294 
    295     // Tags
    296     $num = number_format_i18n( $num_tags );
    297     $text = _n( 'Tag', 'Tags', $num_tags );
    298     if ( current_user_can( 'manage_categories' ) ) {
    299         $num = "<a href='edit-tags.php'>$num</a>";
    300         $text = "<a href='edit-tags.php'>$text</a>";
    301     }
    302     echo '<td class="first b b-tags">' . $num . '</td>';
    303     echo '<td class="t tags">' . $text . '</td>';
    304 
    305     echo "</tr>";
    306     do_action('right_now_content_table_end');
    307     echo "\n\t</table>\n\t</div>";
    308 
    309     echo "\n\t".'<div class="table table_discussion">';
    310     echo "\n\t".'<p class="sub">' . __('Discussion') . '</p>'."\n\t".'<table>';
    311     echo "\n\t".'<tr class="first">';
    312 
    313     // Total Comments
    314     $num = '<span class="total-count">' . number_format_i18n($num_comm->total_comments) . '</span>';
    315     $text = _n( 'Comment', 'Comments', $num_comm->total_comments );
    316     if ( current_user_can( 'moderate_comments' ) ) {
    317         $num = '<a href="edit-comments.php">' . $num . '</a>';
    318         $text = '<a href="edit-comments.php">' . $text . '</a>';
    319     }
    320     echo '<td class="b b-comments">' . $num . '</td>';
    321     echo '<td class="last t comments">' . $text . '</td>';
    322 
    323     echo '</tr><tr>';
    324 
    325     // Approved Comments
    326     $num = '<span class="approved-count">' . number_format_i18n($num_comm->approved) . '</span>';
    327     $text = _nx( 'Approved', 'Approved', $num_comm->approved, 'Right Now' );
    328     if ( current_user_can( 'moderate_comments' ) ) {
    329         $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
    330         $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>$text</a>";
    331     }
    332     echo '<td class="b b_approved">' . $num . '</td>';
    333     echo '<td class="last t">' . $text . '</td>';
    334 
    335     echo "</tr>\n\t<tr>";
    336 
    337     // Pending Comments
    338     $num = '<span class="pending-count">' . number_format_i18n($num_comm->moderated) . '</span>';
    339     $text = _n( 'Pending', 'Pending', $num_comm->moderated );
    340     if ( current_user_can( 'moderate_comments' ) ) {
    341         $num = "<a href='edit-comments.php?comment_status=moderated'>$num</a>";
    342         $text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>$text</a>";
    343     }
    344     echo '<td class="b b-waiting">' . $num . '</td>';
    345     echo '<td class="last t">' . $text . '</td>';
    346 
    347     echo "</tr>\n\t<tr>";
    348 
    349     // Spam Comments
    350     $num = number_format_i18n($num_comm->spam);
    351     $text = _nx( 'Spam', 'Spam', $num_comm->spam, 'comment' );
    352     if ( current_user_can( 'moderate_comments' ) ) {
    353         $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
    354         $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>$text</a>";
    355     }
    356     echo '<td class="b b-spam">' . $num . '</td>';
    357     echo '<td class="last t">' . $text . '</td>';
    358 
    359     echo "</tr>";
    360     do_action('right_now_table_end');
    361     do_action('right_now_discussion_table_end');
    362     echo "\n\t</table>\n\t</div>";
    363 
    364     echo "\n\t".'<div class="versions">';
    365     $theme = wp_get_theme();
    366 
    367     echo "\n\t<p>";
    368 
    369     if ( $theme->errors() ) {
    370         if ( ! is_multisite() || is_super_admin() )
    371             echo '<span class="error-message">' . sprintf( __( 'ERROR: %s' ), $theme->errors()->get_error_message() ) . '</span>';
    372     } elseif ( ! empty($wp_registered_sidebars) ) {
    373         $sidebars_widgets = wp_get_sidebars_widgets();
    374         $num_widgets = 0;
    375         foreach ( (array) $sidebars_widgets as $k => $v ) {
    376             if ( 'wp_inactive_widgets' == $k || 'orphaned_widgets' == substr( $k, 0, 16 ) )
    377                 continue;
    378             if ( is_array($v) )
    379                 $num_widgets = $num_widgets + count($v);
    380         }
    381         $num = number_format_i18n( $num_widgets );
    382 
    383         $switch_themes = $theme->display('Name');
    384         if ( current_user_can( 'switch_themes') )
    385             $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
    386         if ( current_user_can( 'edit_theme_options' ) ) {
    387             printf(_n('Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $switch_themes, $num);
    388         } else {
    389             printf(_n('Theme <span class="b">%1$s</span> with <span class="b">%2$s Widget</span>', 'Theme <span class="b">%1$s</span> with <span class="b">%2$s Widgets</span>', $num_widgets), $switch_themes, $num);
    390         }
    391     } else {
    392         if ( current_user_can( 'switch_themes' ) )
    393             printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $theme->display('Name') );
    394         else
    395             printf( __('Theme <span class="b">%1$s</span>'), $theme->display('Name') );
    396     }
    397     echo '</p>';
    398 
    399     // Check if search engines are asked not to index this site.
    400     if ( !is_network_admin() && !is_user_admin() && current_user_can('manage_options') && '1' != get_option('blog_public') ) {
    401         $title = apply_filters('privacy_on_link_title', __('Your site is asking search engines not to index its content') );
    402         $content = apply_filters('privacy_on_link_text', __('Search Engines Discouraged') );
    403 
    404         echo "<p><a href='options-reading.php' title='$title'>$content</a></p>";
    405     }
    406 
    407     update_right_now_message();
    408 
    409     echo "\n\t".'<br class="clear" /></div>';
     194    if ( $num_comm && $num_comm->total_comments ) {
     195        $text = _n( 'comment', 'comments', $num_comm->total_comments );
     196        printf(
     197            '<li class="comment-count"><a href="edit-comments.php">%1$s %2$s</a></li>',
     198            number_format_i18n( $num_comm->total_comments ),
     199            $text
     200        );
     201        if ( $num_comm->moderated ) {
     202            $text = _n( 'in moderation', 'in moderation', $num_comm->total_comments );
     203            printf(
     204                '<li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated">%1$s %2$s</a></li>',
     205                number_format_i18n( $num_comm->moderated ),
     206                $text
     207            );
     208        }
     209    }
     210    do_action( 'rightnow_list_end' );
     211    ?>
     212    </ul>
     213    <p><?php printf( __( 'WordPress %1$s running %2$s theme.' ), get_bloginfo( 'version', 'display' ), $theme_name ); ?></p>
     214    </div>
     215
     216    <?php
     217    // activity_box_end has a core action, but only prints content when multisite.
     218    // Using an output buffer is the only way to really check if anything's displayed here.
     219    ob_start();
    410220    do_action( 'rightnow_end' );
    411221    do_action( 'activity_box_end' );
     222    $actions = ob_get_clean();
     223
     224    if ( !empty( $actions ) ) : ?>
     225    <div class="sub">
     226        <?php echo $actions; ?>
     227    </div>
     228    <?php endif;
    412229}
    413230
     
    459276}
    460277
    461 function wp_dashboard_quick_press() {
     278/**
     279 * The Quick Draft widget display and creation of drafts
     280 *
     281 *
     282 *
     283 * @since 3.8.0
     284 *
     285 */
     286function wp_dashboard_quick_draft( $error_msg=false ) {
    462287    global $post_ID;
    463 
    464     $drafts = false;
    465     if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
    466         $view = get_permalink( $_POST['post_ID'] );
    467         $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
    468         if ( 'post-quickpress-publish' == $_POST['action'] ) {
    469             if ( current_user_can('publish_posts') )
    470                 printf( '<div class="updated"><p>' . __( 'Post published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
    471             else
    472                 printf( '<div class="updated"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    473         } else {
    474             printf( '<div class="updated"><p>' . __( 'Draft saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
    475             $drafts_query = new WP_Query( array(
    476                 'post_type' => 'post',
    477                 'post_status' => 'draft',
    478                 'author' => $GLOBALS['current_user']->ID,
    479                 'posts_per_page' => 1,
    480                 'orderby' => 'modified',
    481                 'order' => 'DESC'
    482             ) );
    483 
    484             if ( $drafts_query->posts )
    485                 $drafts =& $drafts_query->posts;
    486         }
    487         printf('<p class="easy-blogging">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="' . esc_url( admin_url( 'tools.php' ) ) . '">' . __('Press This') . '</a>' );
    488         $_REQUEST = array(); // hack for get_default_post_to_edit()
    489     }
    490288
    491289    /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
     
    494292        $post = get_post( $last_post_id );
    495293        if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
    496             $post = get_default_post_to_edit('post', true);
     294            $post = get_default_post_to_edit( 'post', true );
    497295            update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
    498296        } else {
     
    509307    $post_ID = (int) $post->ID;
    510308
    511     $media_settings = array(
    512         'id' => $post->ID,
    513         'nonce' => wp_create_nonce( 'update-post_' . $post->ID ),
    514     );
    515 
    516     if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) {
    517         $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    518         $media_settings['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
    519     }
     309    do_action( 'dashboard_quickdraft_beginning', $post );
    520310?>
    521311
    522     <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
     312    <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form">
     313
     314        <?php if ($error_msg) : ?>
     315        <div class="error"><?php _e( $error_msg ); ?></div>
     316        <?php endif; ?>
     317
    523318        <div class="input-text-wrap" id="title-wrap">
    524             <label class="screen-reader-text prompt" for="title" id="title-prompt-text"><?php _e( 'Enter title here' ); ?></label>
    525             <input type="text" name="post_title" id="title" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
     319            <label class="screen-reader-text prompt" for="title" id="title-prompt-text"><?php _e( "What's on your mind?" ); ?></label>
     320            <input type="text" name="post_title" id="title" autocomplete="off" />
    526321        </div>
    527322
    528         <?php if ( current_user_can( 'upload_files' ) ) : ?>
    529         <div id="wp-content-wrap" class="wp-editor-wrap hide-if-no-js wp-media-buttons">
    530             <?php do_action( 'media_buttons', 'content' ); ?>
     323        <div class="textarea-wrap" id="description-wrap">
     324            <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'Enter a description' ); ?></label>
     325            <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"></textarea>
    531326        </div>
    532         <?php endif; ?>
    533 
    534         <div class="textarea-wrap">
    535             <label class="screen-reader-text" for="content"><?php _e( 'Content' ); ?></label>
    536             <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"><?php echo esc_textarea( $post->post_content ); ?></textarea>
    537         </div>
    538 
    539         <script type="text/javascript">
    540         edCanvas = document.getElementById('content');
    541         edInsertContent = null;
    542         <?php if ( $_POST ) : ?>
    543         wp.media.editor.remove('content');
    544         wp.media.view.settings.post = <?php echo json_encode( $media_settings ); // big juicy hack. ?>;
    545         wp.media.editor.add('content');
    546         <?php endif; ?>
    547         </script>
    548 
    549         <div class="input-text-wrap" id="tags-input-wrap">
    550             <label class="screen-reader-text prompt" for="tags-input" id="tags-input-prompt-text"><?php _e( 'Tags (separate with commas)' ); ?></label>
    551             <input type="text" name="tags_input" id="tags-input" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
    552         </div>
    553327
    554328        <p class="submit">
    555             <span id="publishing-action">
    556                 <input type="submit" name="publish" id="publish" accesskey="p" class="button-primary" value="<?php current_user_can('publish_posts') ? esc_attr_e('Publish') : esc_attr_e('Submit for Review'); ?>" />
    557                 <span class="spinner"></span>
    558             </span>
    559             <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
     329            <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
    560330            <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
    561331            <input type="hidden" name="post_type" value="post" />
    562             <?php wp_nonce_field('add-post'); ?>
    563             <?php submit_button( __( 'Save Draft' ), 'button', 'save', false, array( 'id' => 'save-post' ) ); ?>
    564             <input type="reset" value="<?php esc_attr_e( 'Reset' ); ?>" class="button" />
     332            <?php wp_nonce_field( 'add-post' ); ?>
     333            <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
    565334            <br class="clear" />
    566335        </p>
     
    569338
    570339<?php
    571     if ( $drafts )
    572         wp_dashboard_recent_drafts( $drafts );
    573 }
    574 
    575 function wp_dashboard_recent_drafts( $drafts = false ) {
    576     if ( !$drafts ) {
    577         $drafts_query = new WP_Query( array(
    578             'post_type' => 'post',
    579             'post_status' => 'draft',
    580             'author' => $GLOBALS['current_user']->ID,
    581             'posts_per_page' => 5,
    582             'orderby' => 'modified',
    583             'order' => 'DESC'
    584         ) );
    585         $drafts =& $drafts_query->posts;
    586     }
     340    wp_dashboard_recent_quickdrafts();
     341
     342    do_action( 'dashboard_quickdraft_end' );
     343}
     344
     345/**
     346 * Show `Recent Drafts` below Quick Draft form
     347 *
     348 *
     349 *
     350 * @since 3.8.0
     351 *
     352 */
     353function wp_dashboard_recent_quickdrafts() {
     354
     355    $query_args = array(
     356        'post_type'      => 'post',
     357        'post_status'    => 'draft',
     358        'author'         => $GLOBALS['current_user']->ID,
     359        'posts_per_page' => 4,
     360        'orderby'        => 'modified',
     361        'order'          => 'DESC'
     362    );
     363    $query_args = apply_filters( 'dash_recent_quickdrafts_query_args', $query_args );
     364    $drafts_query = new WP_Query( $query_args );
     365    $drafts =& $drafts_query->posts;
     366
    587367
    588368    if ( $drafts && is_array( $drafts ) ) {
    589369        $list = array();
     370        $draft_count = 0;
    590371        foreach ( $drafts as $draft ) {
     372            if ( 3 == $draft_count )
     373                break;
     374
     375            $draft_count++;
     376
    591377            $url = get_edit_post_link( $draft->ID );
    592378            $title = _draft_or_post_title( $draft->ID );
    593             $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit &#8220;%s&#8221;' ), esc_attr( $title ) ) . "'>" . esc_html($title) . "</a> <abbr title='" . get_the_time(__('Y/m/d g:i:s A'), $draft) . "'>" . get_the_time( get_option( 'date_format' ), $draft ) . '</abbr></h4>';
     379            $item = '<div class="draft-title"><a href="' . $url . '" title="' . sprintf( __( 'Edit &#8220;%s&#8221;' ), esc_attr( $title ) ) . '">' . esc_html( $title ) . '</a> <time datetime="' . get_the_time( 'c', $draft) . '">' . get_the_time( get_option( 'date_format' ), $draft ) . '</time></div>';
    594380            if ( $the_content = wp_trim_words( $draft->post_content, 10 ) )
    595381                $item .= '<p>' . $the_content . '</p>';
    596382            $list[] = $item;
    597383        }
     384
     385        do_action( 'dashboard_quickdraft_drafts_list', $drafts );
    598386?>
    599     <ul>
    600         <li><?php echo join( "</li>\n<li>", $list ); ?></li>
    601     </ul>
    602     <p class="textright"><a href="edit.php?post_status=draft" ><?php _e('View all'); ?></a></p>
    603 <?php
    604     } else {
    605         _e('There are no drafts at the moment');
    606     }
    607 }
    608 
    609 /**
    610  * Display recent comments dashboard widget content.
    611  *
    612  * @since 2.5.0
    613  */
    614 function wp_dashboard_recent_comments() {
    615     global $wpdb;
    616 
    617     // Select all comment types and filter out spam later for better query performance.
    618     $comments = array();
    619     $start = 0;
    620 
    621     $widgets = get_option( 'dashboard_widget_options' );
    622     $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] )
    623         ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5;
    624 
    625     $comments_query = array( 'number' => $total_items * 5, 'offset' => 0 );
    626     if ( ! current_user_can( 'edit_posts' ) )
    627         $comments_query['status'] = 'approve';
    628 
    629     while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
    630         foreach ( $possible as $comment ) {
    631             if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
    632                 continue;
    633             $comments[] = $comment;
    634             if ( count( $comments ) == $total_items )
    635                 break 2;
    636         }
    637         $comments_query['offset'] += $comments_query['number'];
    638         $comments_query['number'] = $total_items * 10;
    639     }
    640 
    641     if ( $comments ) {
    642         echo '<div id="the-comment-list" data-wp-lists="list:comment">';
    643         foreach ( $comments as $comment )
    644             _wp_dashboard_recent_comments_row( $comment );
    645         echo '</div>';
    646 
    647         if ( current_user_can('edit_posts') )
    648             _get_list_table('WP_Comments_List_Table')->views();
    649 
    650         wp_comment_reply( -1, false, 'dashboard', false );
    651         wp_comment_trashnotice();
    652     } else {
    653         echo '<p>' . __( 'No comments yet.' ) . '</p>';
    654     }
     387    <div class="drafts">
     388        <?php if ( 3 < count($drafts) ) { ?>
     389        <p class="view-all"><a href="edit.php?post_status=draft" ><?php _e( 'View all' ); ?></a></p>
     390        <?php } ?>
     391        <h4><?php _e('Drafts'); ?></h4>
     392        <ul id="draft-list">
     393            <li><?php echo join( "</li>\n<li>", $list ); ?></li>
     394        </ul>
     395    </div>
     396<?php }
    655397}
    656398
     
    749491
    750492/**
    751  * The recent comments dashboard widget control.
    752  *
    753  * @since 3.0.0
    754  */
    755 function wp_dashboard_recent_comments_control() {
    756     if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
    757         $widget_options = array();
    758 
    759     if ( !isset($widget_options['dashboard_recent_comments']) )
    760         $widget_options['dashboard_recent_comments'] = array();
    761 
    762     if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) {
    763         $number = absint( $_POST['widget-recent-comments']['items'] );
    764         $widget_options['dashboard_recent_comments']['items'] = $number;
    765         update_option( 'dashboard_widget_options', $widget_options );
    766     }
    767 
    768     $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : '';
    769 
    770     echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>';
    771     echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /></p>';
    772 }
    773 
    774 function wp_dashboard_incoming_links() {
    775     wp_dashboard_cached_rss_widget( 'dashboard_incoming_links', 'wp_dashboard_incoming_links_output' );
    776 }
    777 
    778 /**
    779  * Display incoming links dashboard widget content.
    780  *
    781  * @since 2.5.0
    782  */
    783 function wp_dashboard_incoming_links_output() {
    784     $widgets = get_option( 'dashboard_widget_options' );
    785     @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
    786     $rss = fetch_feed( $url );
    787 
    788     if ( is_wp_error($rss) ) {
    789         if ( is_admin() || current_user_can('manage_options') ) {
    790             echo '<p>';
    791             printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
    792             echo '</p>';
    793         }
    794         return;
    795     }
    796 
    797     if ( !$rss->get_item_quantity() ) {
    798         echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. It has found no incoming links&hellip; yet. It&#8217;s okay &#8212; there is no rush.') . "</p>\n";
    799         $rss->__destruct();
    800         unset($rss);
    801         return;
    802     }
    803 
    804     echo "<ul>\n";
    805 
    806     if ( !isset($items) )
    807         $items = 10;
    808 
    809     foreach ( $rss->get_items(0, $items) as $item ) {
    810         $publisher = '';
    811         $site_link = '';
    812         $link = '';
    813         $content = '';
    814         $date = '';
    815         $link = esc_url( strip_tags( $item->get_link() ) );
    816 
    817         $author = $item->get_author();
    818         if ( $author ) {
    819             $site_link = esc_url( strip_tags( $author->get_link() ) );
    820 
    821             if ( !$publisher = esc_html( strip_tags( $author->get_name() ) ) )
    822                 $publisher = __( 'Somebody' );
    823         } else {
    824           $publisher = __( 'Somebody' );
    825         }
    826         if ( $site_link )
    827             $publisher = "<a href='$site_link'>$publisher</a>";
    828         else
    829             $publisher = "<strong>$publisher</strong>";
    830 
    831         $content = $item->get_content();
    832         $content = wp_html_excerpt( $content, 50, ' &hellip;' );
    833 
    834         if ( $link )
    835             /* translators: incoming links feed, %1$s is other person, %3$s is content */
    836             $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"' );
    837         else
    838             /* translators: incoming links feed, %1$s is other person, %3$s is content */
    839             $text = __( '%1$s linked here saying, "%3$s"' );
    840 
    841         if ( !empty( $show_date ) ) {
    842             if ( $link )
    843                 /* translators: incoming links feed, %1$s is other person, %3$s is content, %4$s is the date */
    844                 $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s" on %4$s' );
    845             else
    846                 /* translators: incoming links feed, %1$s is other person, %3$s is content, %4$s is the date */
    847                 $text = __( '%1$s linked here saying, "%3$s" on %4$s' );
    848             $date = esc_html( strip_tags( $item->get_date() ) );
    849             $date = strtotime( $date );
    850             $date = gmdate( get_option( 'date_format' ), $date );
    851         }
    852 
    853         echo "\t<li>" . sprintf( $text, $publisher, $link, $content, $date ) . "</li>\n";
    854     }
    855 
    856     echo "</ul>\n";
    857     $rss->__destruct();
    858     unset($rss);
    859 }
    860 
    861 function wp_dashboard_incoming_links_control() {
    862     wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
    863 }
    864 
    865 function wp_dashboard_primary() {
    866     wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' );
    867 }
    868 
    869 function wp_dashboard_primary_control() {
    870     wp_dashboard_rss_control( 'dashboard_primary' );
    871 }
    872 
    873 /**
    874  * Display primary dashboard RSS widget feed.
    875  *
    876  * @since 2.5.0
    877  *
    878  * @param string $widget_id
    879  */
    880 function wp_dashboard_rss_output( $widget_id ) {
    881     $widgets = get_option( 'dashboard_widget_options' );
    882     echo '<div class="rss-widget">';
    883     wp_widget_rss_output( $widgets[$widget_id] );
    884     echo "</div>";
    885 }
    886 
    887 function wp_dashboard_secondary() {
    888     wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' );
    889 }
    890 
    891 function wp_dashboard_secondary_control() {
    892     wp_dashboard_rss_control( 'dashboard_secondary' );
    893 }
    894 
    895 /**
    896  * Display secondary dashboard RSS widget feed.
    897  *
    898  * @since 2.5.0
    899  *
    900  * @return unknown
    901  */
    902 function wp_dashboard_secondary_output() {
    903     $widgets = get_option( 'dashboard_widget_options' );
    904     @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
    905     $rss = @fetch_feed( $url );
    906 
    907     if ( is_wp_error($rss) ) {
    908         if ( is_admin() || current_user_can('manage_options') ) {
    909             echo '<div class="rss-widget"><p>';
    910             printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
    911             echo '</p></div>';
    912         }
    913     } elseif ( !$rss->get_item_quantity() ) {
    914         $rss->__destruct();
    915         unset($rss);
     493 * callback function for `Activity` widget
     494 *
     495 *
     496 *
     497 * @since 3.8.0
     498 *
     499 */
     500function wp_dashboard_activity() {
     501
     502    echo '<div id="activity-widget">';
     503
     504    do_action( 'dashboard_activity_beginning' );
     505
     506    $future_posts = dashboard_show_published_posts( array(
     507        'display' => 2,
     508        'max'     => 5,
     509        'status'  => 'future',
     510        'order'   => 'ASC',
     511        'title'   => __( 'Publishing Soon' ),
     512        'id'      => 'future-posts',
     513    ) );
     514    $recent_posts = dashboard_show_published_posts( array(
     515        'display' => 2,
     516        'max'     => 5,
     517        'status'  => 'publish',
     518        'order'   => 'DESC',
     519        'title'   => __( 'Recently Published' ),
     520        'id'      => 'published-posts',
     521    ) );
     522
     523    do_action( 'dashboard_activity_middle' );
     524
     525    $recent_comments = dashboard_comments();
     526
     527    if ( !$future_posts && !$recent_posts && !$recent_comments ) {
     528        echo '<div class="no-activity">';
     529        echo '<p class="smiley"></p>';
     530        echo '<p>' . __( 'No activity yet!' ) . '</p>';
     531        echo '</div>';
     532    }
     533
     534    do_action( 'dashboard_activity_end' );
     535
     536    echo '</div>';
     537}
     538
     539/**
     540 * Generates `Publishing Soon` and `Recently Published` sections
     541 *
     542 *
     543 *
     544 * @since 3.8.0
     545 *
     546 */
     547function dashboard_show_published_posts( $args ) {
     548
     549    $query_args = array(
     550        'post_type'      => 'post',
     551        'post_status'    => $args['status'],
     552        'orderby'        => 'date',
     553        'order'          => $args['order'],
     554        'posts_per_page' => intval( $args['max'] ),
     555        'no_found_rows'  => true,
     556        'cache_results'  => false
     557    );
     558    $query_args = apply_filters( 'dash_show_published_posts_query_args', $query_args );
     559    $posts = new WP_Query( $query_args );
     560
     561    if ( $posts->have_posts() ) {
     562
     563        echo '<div id="' . $args['id'] . '" class="activity-block">';
     564
     565        if ( $posts->post_count > $args['display'] ) {
     566            echo '<small class="show-more"><a href="#">' . sprintf( __( 'See %s more&hellip;'), $posts->post_count - intval( $args['display'] ) ) . '</a></small>';
     567        }
     568
     569        echo '<h4>' . $args['title'] . '</h4>';
     570
     571        echo '<ul>';
     572
     573        $i = 0;
     574        while ( $posts->have_posts() ) {
     575            $posts->the_post();
     576            printf(
     577                '<li%s><span>%s, %s</span> <a href="%s">%s</a></li>',
     578                ( $i >= intval ( $args['display'] ) ? ' class="hidden"' : '' ),
     579                dashboard_relative_date( get_the_time( 'U' ) ),
     580                get_the_time(),
     581                get_edit_post_link(),
     582                get_the_title()
     583            );
     584            $i++;
     585        }
     586
     587        echo '</ul>';
     588        echo '</div>';
     589
     590    } else {
    916591        return false;
     592    }
     593
     594    wp_reset_postdata();
     595
     596    return true;
     597}
     598
     599/**
     600 * Show `Comments` section
     601 *
     602 *
     603 *
     604 * @since 3.8.0
     605 *
     606 */
     607function dashboard_comments( $total_items = 5 ) {
     608    global $wpdb;
     609
     610    // Select all comment types and filter out spam later for better query performance.
     611    $comments = array();
     612    $start = 0;
     613
     614    $comments_query = array(
     615        'number' => $total_items * 5,
     616        'offset' => 0
     617    );
     618    if ( ! current_user_can( 'edit_posts' ) )
     619        $comments_query['status'] = 'approve';
     620
     621    while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
     622        foreach ( $possible as $comment ) {
     623            if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
     624                continue;
     625            $comments[] = $comment;
     626            if ( count( $comments ) == $total_items )
     627                break 2;
     628        }
     629        $comments_query['offset'] += $comments_query['number'];
     630        $comments_query['number'] = $total_items * 10;
     631    }
     632
     633
     634
     635    if ( $comments ) {
     636        echo '<div id="latest-comments" class="activity-block">';
     637        echo '<h4>' . __( 'Comments' ) . '</h4>';
     638
     639        echo '<div id="the-comment-list" data-wp-lists="list:comment">';
     640        foreach ( $comments as $comment )
     641            _wp_dashboard_recent_comments_row( $comment );
     642        echo '</div>';
     643
     644        if ( current_user_can('edit_posts') )
     645            _get_list_table('WP_Comments_List_Table')->views();
     646
     647        wp_comment_reply( -1, false, 'dashboard', false );
     648        wp_comment_trashnotice();
     649
     650        echo '</div>';
    917651    } else {
    918         echo '<div class="rss-widget">';
    919         wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
    920         echo '</div>';
    921         $rss->__destruct();
    922         unset($rss);
    923     }
    924 }
    925 
    926 function wp_dashboard_plugins() {
    927     wp_dashboard_cached_rss_widget( 'dashboard_plugins', 'wp_dashboard_plugins_output', array(
    928         'http://wordpress.org/plugins/rss/browse/popular/',
    929         'http://wordpress.org/plugins/rss/browse/new/'
    930     ) );
    931 }
    932 
    933 /**
    934  * Display plugins most popular, newest plugins, and recently updated widget text.
    935  *
    936  * @since 2.5.0
    937  */
    938 function wp_dashboard_plugins_output() {
    939     $popular = fetch_feed( 'http://wordpress.org/plugins/rss/browse/popular/' );
    940     $new     = fetch_feed( 'http://wordpress.org/plugins/rss/browse/new/' );
    941 
    942     if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
    943         $plugin_slugs = array_keys( get_plugins() );
    944         set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
    945     }
    946 
    947     foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins') ) as $feed => $label ) {
    948         if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
    949             continue;
    950 
    951         $items = $$feed->get_items(0, 5);
    952 
    953         // Pick a random, non-installed plugin
    954         while ( true ) {
    955             // Abort this foreach loop iteration if there's no plugins left of this type
    956             if ( 0 == count($items) )
    957                 continue 2;
    958 
    959             $item_key = array_rand($items);
    960             $item = $items[$item_key];
    961 
    962             list($link, $frag) = explode( '#', $item->get_link() );
    963 
    964             $link = esc_url($link);
    965             if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
    966                 $slug = $matches[1];
    967             else {
    968                 unset( $items[$item_key] );
    969                 continue;
    970             }
    971 
    972             // Is this random plugin's slug already installed? If so, try again.
    973             reset( $plugin_slugs );
    974             foreach ( $plugin_slugs as $plugin_slug ) {
    975                 if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
    976                     unset( $items[$item_key] );
    977                     continue 2;
    978                 }
    979             }
    980 
    981             // If we get to this point, then the random plugin isn't installed and we can stop the while().
    982             break;
    983         }
    984 
    985         // Eliminate some common badly formed plugin descriptions
    986         while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
    987             unset($items[$item_key]);
    988 
    989         if ( !isset($items[$item_key]) )
    990             continue;
    991 
    992         $title = esc_html( $item->get_title() );
    993 
    994         $description = esc_html( strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))) );
    995 
    996         $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
    997                             '&amp;TB_iframe=true&amp;width=600&amp;height=800';
    998 
    999         echo "<h4>$label</h4>\n";
    1000         echo "<h5><a href='$link'>$title</a></h5>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n";
    1001         echo "<p>$description</p>\n";
    1002 
    1003         $$feed->__destruct();
    1004         unset($$feed);
    1005     }
     652        return false;
     653    }
     654    return true;
     655}
     656
     657/**
     658 * return relative date for given timestamp
     659 *
     660 *
     661 *
     662 * @since 3.8.0
     663 *
     664 */
     665function dashboard_relative_date( $time ) {
     666
     667    $diff = floor( ( $time - time() ) / DAY_IN_SECONDS );
     668
     669    if ( $diff == 0 )
     670        return __( 'Today' );
     671
     672    if ( $diff == 1 )
     673        return __( 'Tomorrow' );
     674
     675    return date( 'M jS', $time);
     676
    1006677}
    1007678
     
    1075746
    1076747/**
    1077  * The RSS dashboard widget control.
    1078  *
    1079  * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
    1080  * from RSS-type widgets.
    1081  *
    1082  * @since 2.5.0
    1083  *
    1084  * @param string $widget_id
    1085  * @param array $form_inputs
    1086  */
    1087 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
    1088     if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
     748 * Returns default WordPress News feeds
     749 *
     750 *
     751 *
     752 * @since 3.8.0
     753 *
     754 */
     755function wp_dashboard_default_feeds() {
     756    return array(
     757        'news'   => array(
     758            'link'         => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
     759            'url'          => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
     760            'title'        => '',
     761            'items'        => 1,
     762            'show_summary' => 1,
     763            'show_author'  => 0,
     764            'show_date'    => 1,
     765        ),
     766        'planet' => array(
     767            'link'         => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
     768            'url'          => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
     769            'title'        => '',
     770            'items'        => 3,
     771            'show_summary' => 0,
     772            'show_author'  => 0,
     773            'show_date'    => 0,
     774        ),
     775        'plugins' => array(
     776            'link'         => '',
     777            'url'          => array(
     778                    'popular' => 'http://wordpress.org/plugins/rss/browse/popular/'
     779            ),
     780            'title'        => '',
     781            'items'        => 1,
     782            'show_summary' => 0,
     783            'show_author'  => 0,
     784            'show_date'    => 0,
     785        )
     786    );
     787}
     788
     789/**
     790 * Check for cached feeds
     791 *
     792 *
     793 *
     794 * @since 3.8.0
     795 *
     796 */
     797function wp_dashboard_rss() {
     798    $default_feeds = wp_dashboard_default_feeds();
     799
     800    $widget_options = get_option( 'dashboard_widget_options' );
     801
     802    if ( !$widget_options || !is_array($widget_options) )
    1089803        $widget_options = array();
    1090804
    1091     if ( !isset($widget_options[$widget_id]) )
    1092         $widget_options[$widget_id] = array();
    1093 
    1094     $number = 1; // Hack to use wp_widget_rss_form()
    1095     $widget_options[$widget_id]['number'] = $number;
    1096 
    1097     if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
    1098         $_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] );
    1099         $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
    1100         $widget_options[$widget_id]['number'] = $number;
    1101         // title is optional. If black, fill it if possible
    1102         if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
    1103             $rss = fetch_feed($widget_options[$widget_id]['url']);
    1104             if ( is_wp_error($rss) ) {
    1105                 $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
    1106             } else {
    1107                 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
    1108                 $rss->__destruct();
    1109                 unset($rss);
     805    //if ( ! isset( $widget_options['dashboard_rss'] ) ) {
     806        $widget_options['dashboard_rss'] = $default_feeds;
     807        update_option( 'dashboard_widget_options', $widget_options );
     808    //}
     809
     810    foreach( $default_feeds as $key => $value ) {
     811        $default_urls[] = $value['url'];
     812    }
     813
     814    $cache_key = 'dash_' . md5( 'dashboard_rss' );
     815    delete_transient( $cache_key );
     816
     817    do_action( 'dashboard_news_beginning' );
     818
     819    wp_dashboard_cached_rss_widget( 'dashboard_rss', 'wp_dashboard_news_output', $default_urls );
     820
     821    do_action( 'dashboard_news_end' );
     822}
     823
     824/**
     825 * Display news feeds
     826 *
     827 *
     828 *
     829 * @since 3.8.0
     830 *
     831 */
     832function wp_dashboard_news_output() {
     833    $widgets = get_option( 'dashboard_widget_options' );
     834
     835    foreach( $widgets['dashboard_rss'] as $type => $args ) {
     836        $args['type'] = $type;
     837        echo '<div class="rss-widget">';
     838        wp_widget_news_output( $args['url'], $args );
     839        echo "</div>";
     840    }
     841}
     842
     843/**
     844 * Generate code for each news feed
     845 *
     846 *
     847 *
     848 * @since 3.8.0
     849 *
     850 */
     851function wp_widget_news_output( $rss, $args = array() ) {
     852
     853    // Regular RSS feeds
     854    if ( isset( $args['type'] ) && 'plugins' != $args['type'] )
     855        return wp_widget_rss_output( $rss, $args );
     856
     857    // Plugin feeds plus link to install them
     858    if ( ! is_multisite() && current_user_can( 'install_plugins' ) ) {
     859        $popular = fetch_feed( $args['url']['popular'] );
     860
     861        if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
     862            $plugin_slugs = array_keys( get_plugins() );
     863            set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
     864        }
     865
     866        echo '<ul>';
     867
     868        foreach ( array(
     869            'popular' => __( 'Popular Plugin' )
     870        ) as $feed => $label ) {
     871            if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
     872                continue;
     873
     874            $items = $$feed->get_items(0, 5);
     875
     876            // Pick a random, non-installed plugin
     877            while ( true ) {
     878                // Abort this foreach loop iteration if there's no plugins left of this type
     879                if ( 0 == count($items) )
     880                    continue 2;
     881
     882                $item_key = array_rand($items);
     883                $item = $items[$item_key];
     884
     885                list($link, $frag) = explode( '#', $item->get_link() );
     886
     887                $link = esc_url($link);
     888                if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
     889                    $slug = $matches[1];
     890                else {
     891                    unset( $items[$item_key] );
     892                    continue;
     893                }
     894
     895                // Is this random plugin's slug already installed? If so, try again.
     896                reset( $plugin_slugs );
     897                foreach ( $plugin_slugs as $plugin_slug ) {
     898                    if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
     899                        unset( $items[$item_key] );
     900                        continue 2;
     901                    }
     902                }
     903
     904                // If we get to this point, then the random plugin isn't installed and we can stop the while().
     905                break;
    1110906            }
    1111         }
    1112         update_option( 'dashboard_widget_options', $widget_options );
    1113         $cache_key = 'dash_' . md5( $widget_id );
    1114         delete_transient( $cache_key );
    1115     }
    1116 
    1117     wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
     907
     908            // Eliminate some common badly formed plugin descriptions
     909            while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
     910                unset($items[$item_key]);
     911
     912            if ( !isset($items[$item_key]) )
     913                continue;
     914
     915            $title = esc_html( $item->get_title() );
     916
     917            $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
     918
     919            $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&amp;TB_iframe=true&amp;width=600&amp;height=800';
     920
     921            echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a></h5>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>";
     922
     923            $$feed->__destruct();
     924            unset( $$feed );
     925        }
     926
     927        echo '</ul>';
     928    }
    1118929}
    1119930
     
    1128939*/
    1129940function wp_dashboard_quota() {
    1130     if ( !is_multisite() || !current_user_can('upload_files') || get_site_option( 'upload_space_check_disabled' ) )
     941    if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
    1131942        return true;
    1132943
     
    1138949    else
    1139950        $percentused = ( $used / $quota ) * 100;
    1140     $used_color = ( $percentused >= 70 ) ? ' spam' : '';
     951    $used_class = ( $percentused >= 70 ) ? ' warning' : '';
    1141952    $used = round( $used, 2 );
    1142953    $percentused = number_format( $percentused );
    1143954
    1144955    ?>
    1145     <p class="sub musub"><?php _e( 'Storage Space' ); ?></p>
    1146     <div class="table table_content musubtable">
    1147     <table>
    1148         <tr class="first">
    1149             <td class="first b b-posts"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>' ), esc_url( admin_url( 'upload.php' ) ), number_format_i18n( $quota ) ); ?></td>
    1150             <td class="t posts"><?php _e( 'Space Allowed' ); ?></td>
    1151         </tr>
    1152     </table>
    1153     </div>
    1154     <div class="table table_discussion musubtable">
    1155     <table>
    1156         <tr class="first">
    1157             <td class="b b-comments"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>' ), esc_url( admin_url( 'upload.php' ) ), number_format_i18n( $used, 2 ), $percentused ); ?></td>
    1158             <td class="last t comments<?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>
    1159         </tr>
    1160     </table>
    1161     </div>
    1162     <br class="clear" />
     956    <h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4>
     957    <div class="mu-storage">
     958    <ul>
     959        <li class="storage-count">
     960            <?php printf(
     961                '<a href="%1$s" title="%3$s">%2$sMB %4$s</a>',
     962                esc_url( admin_url( 'upload.php' ) ),
     963                number_format_i18n( $quota ),
     964                __( 'Manage Uploads' ),
     965                __( 'Space Allowed' )
     966            ); ?>
     967        </li><li class="storage-count <?php echo $used_class; ?>">
     968            <?php printf(
     969                '<a href="%1$s" title="%4$s" class="musublink">%2$sMB (%3$s%%) %5$s</a>',
     970                esc_url( admin_url( 'upload.php' ) ),
     971                number_format_i18n( $used, 2 ),
     972                $percentused,
     973                __( 'Manage Uploads' ),
     974                __( 'Space Used' )
     975            ); ?>
     976        </li>
     977    </ul>
     978    </div>
    1163979    <?php
    1164980}
Note: See TracChangeset for help on using the changeset viewer.