Changeset 26220 for trunk/src/wp-admin/includes/dashboard.php
- Timestamp:
- 11/15/2013 08:14:44 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/dashboard.php
r26144 r26220 38 38 // Right Now 39 39 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' ); 41 41 42 42 if ( is_network_admin() ) … … 44 44 45 45 // 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' ); 47 47 48 48 // QuickPress Widget 49 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' );50 wp_add_dashboard_widget( 'dashboard_quick_press', __( 'Quick Draft' ), 'wp_dashboard_quick_press' ); 51 51 52 52 // 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' ); 54 54 55 55 // Hook to register new widgets … … 105 105 } 106 106 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' ); 113 108 114 109 $location = 'normal'; … … 119 114 if ( 'dashboard_browser_nag' === $widget_id ) 120 115 $priority = 'high'; 116 elseif ( 'dashboard_primary' === $widget_id ) 117 $priority = 'low'; 121 118 122 119 add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args ); … … 165 162 /* Dashboard Widgets */ 166 163 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 */ 171 function wp_dashboard_right_now() { 168 172 $theme = wp_get_theme(); 169 173 if ( current_user_can( 'switch_themes' ) ) … … 284 288 * 285 289 */ 286 function wp_dashboard_quick_ draft( $error_msg=false ) {290 function wp_dashboard_quick_press( $error_msg=false ) { 287 291 global $post_ID; 288 292 … … 306 310 307 311 $post_ID = (int) $post->ID; 308 309 do_action( 'dashboard_quickdraft_beginning', $post );310 312 ?> 311 313 … … 339 341 <?php 340 342 wp_dashboard_recent_quickdrafts(); 341 342 do_action( 'dashboard_quickdraft_end' );343 343 } 344 344 … … 678 678 679 679 /** 680 * Display generic dashboard RSS widget feed. 681 * 682 * @since 2.5.0 683 * 684 * @param string $widget_id 685 */ 686 function 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 /** 680 694 * Checks to see if all of the feed url in $check_urls are cached. 681 695 * … … 746 760 747 761 /** 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 */ 766 function wp_dashboard_primary() { 767 $feeds = array( 757 768 'news' => array( 758 769 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ), … … 772 783 'show_author' => 0, 773 784 '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( 776 790 'link' => '', 777 791 'url' => array( 778 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/'792 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/', 779 793 ), 780 794 'title' => '', … … 783 797 'show_author' => 0, 784 798 '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. 793 807 * 794 808 * @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 */ 810 function wp_dashboard_primary_output( $widget_id, $feeds ) { 811 foreach( $feeds as $type => $args ) { 836 812 $args['type'] = $type; 837 813 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 } 839 819 echo "</div>"; 840 820 } … … 842 822 843 823 /** 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 */ 828 function wp_dashboard_plugins_output( $rss, $args = array() ) { 857 829 // 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] ); 872 863 continue; 873 874 $items = $$feed->get_items(0, 5); 875 876 // Pick a random, non-installed plugin877 while ( true) {878 // Abort this foreach loop iteration if there's no plugins left of this type879 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] ); 880 871 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 872 } 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;906 873 } 907 874 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) . '&TB_iframe=true&width=600&height=800'; 920 921 echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a></h5> <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) . '&TB_iframe=true&width=600&height=800'; 891 892 echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a></h5> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>"; 893 894 $$feed->__destruct(); 895 unset( $$feed ); 896 } 897 898 echo '</ul>'; 929 899 } 930 900
Note: See TracChangeset
for help on using the changeset viewer.