+/**
+ * WordPress News dashboard widget.
+ *
+ * @since 2.7.0
+ */
+function wp_dashboard_primary() {
+ $feeds = array(
+ 'news' => array(
+
+ /**
+ * Filter the primary link URL for the 'WordPress News' dashboard widget.
+ *
+ * @since 2.5.0
+ *
+ * @param string $link The widget's primary link URL.
+ */
+ 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
+
+ /**
+ * Filter the primary feed URL for the 'WordPress News' dashboard widget.
+ *
+ * @since 2.3.0
+ *
+ * @param string $url The widget's primary feed URL.
+ */
+ 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
+
+ /**
+ * Filter the primary link title for the 'WordPress News' dashboard widget.
+ *
+ * @since 2.3.0
+ *
+ * @param string $title Title attribute for the widget's primary link.
+ */
+ 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
+ 'items' => 1,
+ 'show_summary' => 1,
+ 'show_author' => 0,
+ 'show_date' => 1,
+ ),
+ 'planet' => array(
+
+ /**
+ * Filter the secondary link URL for the 'WordPress News' dashboard widget.
+ *
+ * @since 2.3.0
+ *
+ * @param string $link The widget's secondary link URL.
+ */
+ 'link' => apply_filters( 'dashboard_secondary_link', __( 'https://planet.wordpress.org/' ) ),
+
+ /**
+ * Filter the secondary feed URL for the 'WordPress News' dashboard widget.
+ *
+ * @since 2.3.0
+ *
+ * @param string $url The widget's secondary feed URL.
+ */
+ 'url' => apply_filters( 'dashboard_secondary_feed', __( 'https://planet.wordpress.org/feed/' ) ),
+
+ /**
+ * Filter the secondary link title for the 'WordPress News' dashboard widget.
+ *
+ * @since 2.3.0
+ *
+ * @param string $title Title attribute for the widget's secondary link.
+ */
+ 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
+ 'items' => 3,
+ 'show_summary' => 0,
+ 'show_author' => 0,
+ 'show_date' => 0,
+ )
+ );
+
+ 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' ) ) ) {
+ $feeds['plugins'] = array(
+ 'link' => '',
+ 'url' => array(
+ 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
+ ),
+ 'title' => '',
+ 'items' => 1,
+ 'show_summary' => 0,
+ 'show_author' => 0,
+ 'show_date' => 0,
+ );
+ }
+
+ wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
+}
+
+/**
+ * Display the WordPress news feeds.
+ *
+ * @since 3.8.0
+ *
+ * @param string $widget_id Widget ID.
+ * @param array $feeds Array of RSS feeds.
+ */
+function wp_dashboard_primary_output( $widget_id, $feeds ) {
+ foreach( $feeds as $type => $args ) {
+ $args['type'] = $type;
+ echo '<div class="rss-widget">';
+ if ( $type === 'plugins' ) {
+ wp_dashboard_plugins_output( $args['url'], $args );
+ } else {
+ wp_widget_rss_output( $args['url'], $args );
+ }
+ echo "</div>";
+ }
+}
+
+/**
+ * Display plugins text for the WordPress news widget.
+ *
+ * @since 2.5.0
+ */
+function wp_dashboard_plugins_output( $rss, $args = array() ) {
+ // Plugin feeds plus link to install them
+ $popular = fetch_feed( $args['url']['popular'] );
+
+ if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
+ $plugin_slugs = array_keys( get_plugins() );
+ set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
+ }
+
+ echo '<ul>';
+
+ foreach ( array( $popular ) as $feed ) {
+ if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() )
+ continue;
+
+ $items = $feed->get_items(0, 5);
+
+ // Pick a random, non-installed plugin
+ while ( true ) {
+ // Abort this foreach loop iteration if there's no plugins left of this type
+ if ( 0 == count($items) )
+ continue 2;
+
+ $item_key = array_rand($items);
+ $item = $items[$item_key];
+
+ list($link, $frag) = explode( '#', $item->get_link() );
+
+ $link = esc_url($link);
+ if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
+ $slug = $matches[1];
+ else {
+ unset( $items[$item_key] );
+ continue;
+ }
+
+ // Is this random plugin's slug already installed? If so, try again.
+ reset( $plugin_slugs );
+ foreach ( $plugin_slugs as $plugin_slug ) {
+ if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
+ unset( $items[$item_key] );
+ continue 2;
+ }
+ }
+
+ // If we get to this point, then the random plugin isn't installed and we can stop the while().
+ break;
+ }
+
+ // Eliminate some common badly formed plugin descriptions
+ while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
+ unset($items[$item_key]);
+
+ if ( !isset($items[$item_key]) )
+ continue;
+
+ $title = esc_html( $item->get_title() );
+
+ $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800';
+ echo "<li class='dashboard-news-plugin'><span>" . __( 'Popular Plugin' ) . ":</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>";
+
+ $feed->__destruct();
+ unset( $feed );
+ }
+
+ echo '</ul>';
+}
+
+/**
+ * Display file upload quota on dashboard.
+ *
+ * Runs on the activity_box_end hook in wp_dashboard_right_now().
+ *
+ * @since 3.0.0
+ *
+ * @return bool|null True if not multisite, user can't upload files, or the space check option is disabled.
+*/
+function wp_dashboard_quota() {
+ if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
+ return true;
+
+ $quota = get_space_allowed();
+ $used = get_space_used();
+
+ if ( $used > $quota )
+ $percentused = '100';
+ else
+ $percentused = ( $used / $quota ) * 100;
+ $used_class = ( $percentused >= 70 ) ? ' warning' : '';
+ $used = round( $used, 2 );
+ $percentused = number_format( $percentused );
+
+ ?>
+ <h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4>
+ <div class="mu-storage">
+ <ul>
+ <li class="storage-count">
+ <?php $text = sprintf(
+ /* translators: number of megabytes */
+ __( '%s MB Space Allowed' ),
+ number_format_i18n( $quota )
+ );
+ printf(
+ '<a href="%1$s" title="%2$s">%3$s</a>',
+ esc_url( admin_url( 'upload.php' ) ),
+ __( 'Manage Uploads' ),
+ $text
+ ); ?>
+ </li><li class="storage-count <?php echo $used_class; ?>">
+ <?php $text = sprintf(
+ /* translators: 1: number of megabytes, 2: percentage */
+ __( '%1$s MB (%2$s%%) Space Used' ),
+ number_format_i18n( $used, 2 ),
+ $percentused
+ );
+ printf(
+ '<a href="%1$s" title="%2$s" class="musublink">%3$s</a>',
+ esc_url( admin_url( 'upload.php' ) ),
+ __( 'Manage Uploads' ),
+ $text
+ ); ?>
+ </li>
+ </ul>
+ </div>
+ <?php
+}
+add_action( 'activity_box_end', 'wp_dashboard_quota' );
+
+// Display Browser Nag Meta Box
+function wp_dashboard_browser_nag() {
+ $notice = '';
+ $response = wp_check_browser_version();
+
+ if ( $response ) {
+ if ( $response['insecure'] ) {
+ $msg = sprintf( __( "It looks like you're using an insecure version of <a href='%s'>%s</a>. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) );
+ } else {
+ $msg = sprintf( __( "It looks like you're using an old version of <a href='%s'>%s</a>. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) );
+ }
+
+ $browser_nag_class = '';
+ if ( !empty( $response['img_src'] ) ) {
+ $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
+
+ $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
+ $browser_nag_class = ' has-browser-icon';
+ }
+ $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
+
+ $browsehappy = 'http://browsehappy.com/';
+ $locale = get_locale();
+ if ( 'en_US' !== $locale )
+ $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
+
+ $notice .= '<p>' . sprintf( __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ), esc_url( $browsehappy ) ) . '</p>';
+ $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
+ $notice .= '<div class="clear"></div>';
+ }
+
+ /**
+ * Filter the notice output for the 'Browse Happy' nag meta box.
+ *
+ * @since 3.2.0
+ *
+ * @param string $notice The notice content.
+ * @param array $response An array containing web browser information.
+ */
+ echo apply_filters( 'browse-happy-notice', $notice, $response );
+}
+
+function dashboard_browser_nag_class( $classes ) {
+ $response = wp_check_browser_version();
+
+ if ( $response && $response['insecure'] )
+ $classes[] = 'browser-insecure';
+
+ return $classes;
+}
+
+/**
+ * Check if the user needs a browser update
+ *
+ * @since 3.2.0
+ *
+ * @return array|bool False on failure, array of browser data on success.
+ */
+function wp_check_browser_version() {
+ if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
+ return false;
+
+ $key = md5( $_SERVER['HTTP_USER_AGENT'] );
+
+ if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
+ global $wp_version;
+
+ $options = array(
+ 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
+ );
+
+ $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options );
+
+ if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
+ return false;
+
+ /**
+ * Response should be an array with:
+ * 'name' - string - A user friendly browser name
+ * 'version' - string - The most recent version of the browser
+ * 'current_version' - string - The version of the browser the user is using
+ * 'upgrade' - boolean - Whether the browser needs an upgrade
+ * 'insecure' - boolean - Whether the browser is deemed insecure
+ * 'upgrade_url' - string - The url to visit to upgrade
+ * 'img_src' - string - An image representing the browser
+ * 'img_src_ssl' - string - An image (over SSL) representing the browser
+ */
+ $response = json_decode( wp_remote_retrieve_body( $response ), true );
+
+ if ( ! is_array( $response ) )
+ return false;
+
+ set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
+ }
+
+ return $response;
+}
+
+/**
+ * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
+ */
+function wp_dashboard_empty() {}
+
+/**
+ * Displays a welcome panel to introduce users to WordPress.
+ *
+ * @since 3.3.0
+ */
+function wp_welcome_panel() {
+ ?>
+ <div class="welcome-panel-content">
+ <h3><?php _e( 'Welcome to WordPress!' ); ?></h3>
+ <p class="about-description"><?php _e( 'We’ve assembled some links to get you started:' ); ?></p>
+ <div class="welcome-panel-column-container">
+ <div class="welcome-panel-column">
+ <?php if ( current_user_can( 'customize' ) ): ?>
+ <h4><?php _e( 'Get Started' ); ?></h4>
+ <a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Customize Your Site' ); ?></a>
+ <?php endif; ?>
+ <a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
+ <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
+ <p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), admin_url( 'themes.php' ) ); ?></p>
+ <?php endif; ?>
+ </div>
+ <div class="welcome-panel-column">
+ <h4><?php _e( 'Next Steps' ); ?></h4>
+ <ul>
+ <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
+ <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
+ <?php else : ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add an About page' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
+ <?php endif; ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
+ </ul>
+ </div>
+ <div class="welcome-panel-column welcome-panel-last">
+ <h4><?php _e( 'More Actions' ); ?></h4>
+ <ul>
+ <?php if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) : ?>
+ <li><div class="welcome-icon welcome-widgets-menus"><?php
+ if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
+ printf( __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
+ admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) );
+ } elseif ( current_theme_supports( 'widgets' ) ) {
+ echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
+ } else {
+ echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
+ }
+ ?></div></li>
+ <?php endif; ?>
+ <?php if ( current_user_can( 'manage_options' ) ) : ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
+ <?php endif; ?>
+ <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'http://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <?php
+}