Make WordPress Core

Changeset 26220


Ignore:
Timestamp:
11/15/2013 08:14:44 PM (13 years ago)
Author:
nacin
Message:

Dash cleanup.

  • Use wp_add_dashboard_widget() rather than add_meta_box().
  • Use original functions like wp_dashboard_primary(), wp_dashboard_right_now(), wp_dashboard_quick_press() (where possible).
  • Only include plugins section of the news widget when appropriate, which necessitates the set_current_screen() via the ajax action.
  • Remove some debug cruft that was preventing caching and invalidation.
  • Simplify lots of things where possible.

see #25824.

Location:
trunk/src/wp-admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/wp-admin.css

    r26219 r26220  
    29702970/* Dashboard Quick Draft */
    29712971
    2972 #dashboard_quick_draft div.updated {
     2972#dashboard_quick_press div.updated {
    29732973        margin-bottom: 10px;
    29742974        border: 1px solid #eee;
     
    29762976}
    29772977
    2978 #dashboard_quick_draft form {
     2978#dashboard_quick_press form {
    29792979        padding: 0 12px 1px 12px;
    29802980        overflow: hidden;
    29812981}
    29822982
    2983 #dashboard_quick_draft .drafts,
    2984 #dashboard_quick_draft .easy-blogging {
     2983#dashboard_quick_press .drafts,
     2984#dashboard_quick_press .easy-blogging {
    29852985        padding: 8px 12px 0;
    29862986}
     
    30133013}
    30143014
    3015 #dashboard_quick_draft input,
    3016 #dashboard_quick_draft textarea {
     3015#dashboard_quick_press input,
     3016#dashboard_quick_press textarea {
    30173017        box-sizing: border-box;
    30183018        -moz-box-sizing:border-box;
     
    30213021}
    30223022
    3023 #dashboard_quick_draft textarea {
     3023#dashboard_quick_press textarea {
    30243024        resize: vertical;
    30253025}
     
    30713071/* Dashboard Quick Draft - Drafts list */
    30723072
    3073 #dashboard_quick_draft .drafts {
     3073#dashboard_quick_press .drafts {
    30743074        border-top: 1px solid #eee;
    30753075        margin-top: 12px;
    30763076}
    30773077
    3078 #dashboard_quick_draft .drafts abbr {
     3078#dashboard_quick_press .drafts abbr {
    30793079        border: none;
    30803080}
    30813081
    3082 #dashboard_quick_draft .drafts h4 {
     3082#dashboard_quick_press .drafts h4 {
    30833083        margin: 0 0 8px 0;
    30843084        font-weight: normal;
    30853085}
    30863086
    3087 #dashboard_quick_draft .drafts .view-all {
     3087#dashboard_quick_press .drafts .view-all {
    30883088        float: right;
    30893089        margin-top: 0;
  • trunk/src/wp-admin/includes/ajax-actions.php

    r26144 r26220  
    234234        require_once ABSPATH . 'wp-admin/includes/dashboard.php';
    235235
     236        $pagenow = $_GET['pagenow'];
     237        if ( $pagenow === 'dashboard-user' || $pagenow === 'dashboard-network' || $pagenow === 'dashboard' ) {
     238                set_current_screen( $pagenow );
     239        }
     240
    236241        switch ( $_GET['widget'] ) {
    237                 case 'dashboard_rss' :
    238                         wp_dashboard_rss();
     242                case 'dashboard_primary' :
     243                        wp_dashboard_primary();
    239244                        break;
    240245        }
  • trunk/src/wp-admin/includes/dashboard.php

    r26144 r26220  
    3838        // Right Now
    3939        if ( is_blog_admin() && current_user_can('edit_posts') )
    40                 add_meta_box( 'dash-right-now', 'Site Content', 'dashboard_new_right_now', 'dashboard', 'normal', 'high' );
     40                wp_add_dashboard_widget( 'dash-right-now', __( 'Site Content' ), 'wp_dashboard_right_now' );
    4141
    4242        if ( is_network_admin() )
     
    4444
    4545        // Activity Widget
    46         add_meta_box( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_activity', 'dashboard', 'normal', 'high' );
     46        wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_activity' );
    4747
    4848        // QuickPress Widget
    4949        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' );
     50                wp_add_dashboard_widget( 'dashboard_quick_press', __( 'Quick Draft' ), 'wp_dashboard_quick_press' );
    5151
    5252        // WordPress News
    53         add_meta_box( 'dashboard_rss', __( 'WordPress News' ), 'wp_dashboard_rss', 'dashboard', 'side', 'low' );
     53        wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress News' ), 'wp_dashboard_primary' );
    5454
    5555        // Hook to register new widgets
     
    105105        }
    106106
    107         if ( is_blog_admin () )
    108                 $side_widgets = array('dashboard_quick_draft');
    109         else if (is_network_admin() )
    110                 $side_widgets = array();
    111         else
    112                 $side_widgets = array();
     107        $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
    113108
    114109        $location = 'normal';
     
    119114        if ( 'dashboard_browser_nag' === $widget_id )
    120115                $priority = 'high';
     116        elseif ( 'dashboard_primary' === $widget_id )
     117                $priority = 'low';
    121118
    122119        add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
     
    165162/* Dashboard Widgets */
    166163
    167 function dashboard_new_right_now() {
     164/**
     165 * Dashboard widget that displays some basic stats about the site.
     166 *
     167 * Formerly 'Right Now'. A streamlined 'Site Content' as of 3.8.
     168 *
     169 * @since 2.7.0
     170 */
     171function wp_dashboard_right_now() {
    168172        $theme = wp_get_theme();
    169173        if ( current_user_can( 'switch_themes' ) )
     
    284288 *
    285289 */
    286 function wp_dashboard_quick_draft( $error_msg=false ) {
     290function wp_dashboard_quick_press( $error_msg=false ) {
    287291        global $post_ID;
    288292
     
    306310
    307311        $post_ID = (int) $post->ID;
    308 
    309         do_action( 'dashboard_quickdraft_beginning', $post );
    310312?>
    311313
     
    339341<?php
    340342        wp_dashboard_recent_quickdrafts();
    341 
    342         do_action( 'dashboard_quickdraft_end' );
    343343}
    344344
     
    678678
    679679/**
     680 * Display generic dashboard RSS widget feed.
     681 *
     682 * @since 2.5.0
     683 *
     684 * @param string $widget_id
     685 */
     686function wp_dashboard_rss_output( $widget_id ) {
     687        $widgets = get_option( 'dashboard_widget_options' );
     688        echo '<div class="rss-widget">';
     689        wp_widget_rss_output( $widgets[ $widget_id ] );
     690        echo "</div>";
     691}
     692
     693/**
    680694 * Checks to see if all of the feed url in $check_urls are cached.
    681695 *
     
    746760
    747761/**
    748  * Returns default WordPress News feeds
    749  *
    750  *
    751  *
    752  * @since 3.8.0
    753  *
    754  */
    755 function wp_dashboard_default_feeds() {
    756         return array(
     762 * WordPress News dashboard widget.
     763 *
     764 * @since 2.7.0
     765 */
     766function wp_dashboard_primary() {
     767        $feeds = array(
    757768                'news'   => array(
    758769                        'link'         => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
     
    772783                        'show_author'  => 0,
    773784                        'show_date'    => 0,
    774                 ),
    775                 'plugins' => array(
     785                )
     786        );
     787
     788        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' ) ) ) {
     789                $feeds['plugins'] = array(
    776790                        'link'         => '',
    777791                        'url'          => array(
    778                                         'popular' => 'http://wordpress.org/plugins/rss/browse/popular/'
     792                                'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
    779793                        ),
    780794                        'title'        => '',
     
    783797                        'show_author'  => 0,
    784798                        'show_date'    => 0,
    785                 )
    786         );
    787 }
    788 
    789 /**
    790  * Check for cached feeds
    791  *
    792  *
     799                );
     800        }
     801
     802        wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
     803}
     804
     805/**
     806 * Display the WordPress news feeds.
    793807 *
    794808 * @since 3.8.0
    795  *
    796  */
    797 function 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) )
    803                 $widget_options = array();
    804 
    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  */
    832 function wp_dashboard_news_output() {
    833         $widgets = get_option( 'dashboard_widget_options' );
    834 
    835         foreach( $widgets['dashboard_rss'] as $type => $args ) {
     809 */
     810function wp_dashboard_primary_output( $widget_id, $feeds ) {
     811        foreach( $feeds as $type => $args ) {
    836812                $args['type'] = $type;
    837813                echo '<div class="rss-widget">';
    838                 wp_widget_news_output( $args['url'], $args );
     814                if ( $type === 'plugins' ) {
     815                        wp_dashboard_plugins_output( $args['url'], $args );
     816                } else {
     817                        wp_widget_rss_output( $args['url'], $args );
     818                }
    839819                echo "</div>";
    840820        }
     
    842822
    843823/**
    844  * Generate code for each news feed
    845  *
    846  *
    847  *
    848  * @since 3.8.0
    849  *
    850  */
    851 function 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 
     824 * Display plugins text for the WordPress news widget.
     825 *
     826 * @since 2.5.0
     827 */
     828function wp_dashboard_plugins_output( $rss, $args = array() ) {
    857829        // 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() )
     830        $popular = fetch_feed( $args['url']['popular'] );
     831
     832        if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
     833                $plugin_slugs = array_keys( get_plugins() );
     834                set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
     835        }
     836
     837        echo '<ul>';
     838
     839        foreach ( array(
     840                'popular' => __( 'Popular Plugin' )
     841        ) as $feed => $label ) {
     842                if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
     843                        continue;
     844
     845                $items = $$feed->get_items(0, 5);
     846
     847                // Pick a random, non-installed plugin
     848                while ( true ) {
     849                        // Abort this foreach loop iteration if there's no plugins left of this type
     850                        if ( 0 == count($items) )
     851                                continue 2;
     852
     853                        $item_key = array_rand($items);
     854                        $item = $items[$item_key];
     855
     856                        list($link, $frag) = explode( '#', $item->get_link() );
     857
     858                        $link = esc_url($link);
     859                        if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
     860                                $slug = $matches[1];
     861                        else {
     862                                unset( $items[$item_key] );
    872863                                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) )
     864                        }
     865
     866                        // Is this random plugin's slug already installed? If so, try again.
     867                        reset( $plugin_slugs );
     868                        foreach ( $plugin_slugs as $plugin_slug ) {
     869                                if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
     870                                        unset( $items[$item_key] );
    880871                                        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;
    893872                                }
    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;
    906873                        }
    907874
    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         }
     875                        // If we get to this point, then the random plugin isn't installed and we can stop the while().
     876                        break;
     877                }
     878
     879                // Eliminate some common badly formed plugin descriptions
     880                while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
     881                        unset($items[$item_key]);
     882
     883                if ( !isset($items[$item_key]) )
     884                        continue;
     885
     886                $title = esc_html( $item->get_title() );
     887
     888                $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
     889
     890                $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';
     891
     892                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>";
     893
     894                $$feed->__destruct();
     895                unset( $$feed );
     896        }
     897
     898        echo '</ul>';
    929899}
    930900
  • trunk/src/wp-admin/includes/deprecated.php

    r26144 r26220  
    731731function wp_dashboard_quick_press_output() {
    732732        _deprecated_function( __FUNCTION__, '3.2', 'wp_dashboard_quick_press()' );
    733         wp_dashboard_quick_draft();
     733        wp_dashboard_quick_press();
    734734}
    735735
  • trunk/src/wp-admin/js/dashboard.js

    r26144 r26220  
     1/* global pagenow */
    12var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad;
    23
     
    2930
    3031        // These widgets are sometimes populated via ajax
    31         ajaxWidgets = [
    32                 'dashboard_rss'
    33         ];
     32        ajaxWidgets = ['dashboard_primary'];
    3433
    3534        ajaxPopulateWidgets = function(el) {
     
    3938                                p = e.parent();
    4039                                setTimeout( function(){
    41                                         p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id, '', function() {
     40                                        p.load( ajaxurl + '?action=dashboard-widgets&widget=' + id + '&pagenow=' + pagenow, '', function() {
    4241                                                p.hide().slideDown('normal', function(){
    4342                                                        $(this).css('display', '');
Note: See TracChangeset for help on using the changeset viewer.