PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/dashboard.php

https://bitbucket.org/julianelve/vendor-wordpress
PHP | 1299 lines | 936 code | 196 blank | 167 comment | 210 complexity | e8dc6fc3f273f1771bde4363b251b48e MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * WordPress Dashboard Widget Administration Screen API
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * Registers dashboard widgets.
  10. *
  11. * Handles POST data, sets up filters.
  12. *
  13. * @since 2.5.0
  14. */
  15. function wp_dashboard_setup() {
  16. global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
  17. $wp_dashboard_control_callbacks = array();
  18. $screen = get_current_screen();
  19. $update = false;
  20. $widget_options = get_option( 'dashboard_widget_options' );
  21. if ( !$widget_options || !is_array($widget_options) )
  22. $widget_options = array();
  23. /* Register Widgets and Controls */
  24. $response = wp_check_browser_version();
  25. if ( $response && $response['upgrade'] ) {
  26. add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
  27. if ( $response['insecure'] )
  28. wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
  29. else
  30. wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
  31. }
  32. // Right Now
  33. if ( is_blog_admin() && current_user_can('edit_posts') )
  34. wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
  35. if ( is_network_admin() )
  36. wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
  37. // Recent Comments Widget
  38. if ( is_blog_admin() && current_user_can('moderate_comments') ) {
  39. if ( !isset( $widget_options['dashboard_recent_comments'] ) || !isset( $widget_options['dashboard_recent_comments']['items'] ) ) {
  40. $update = true;
  41. $widget_options['dashboard_recent_comments'] = array(
  42. 'items' => 5,
  43. );
  44. }
  45. $recent_comments_title = __( 'Recent Comments' );
  46. wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments', 'wp_dashboard_recent_comments_control' );
  47. }
  48. // Incoming Links Widget
  49. if ( is_blog_admin() && current_user_can('publish_posts') ) {
  50. if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
  51. $update = true;
  52. $num_items = isset($widget_options['dashboard_incoming_links']['items']) ? $widget_options['dashboard_incoming_links']['items'] : 10;
  53. $widget_options['dashboard_incoming_links'] = array(
  54. 'home' => get_option('home'),
  55. 'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
  56. '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') ) ),
  57. 'items' => $num_items,
  58. 'show_date' => isset($widget_options['dashboard_incoming_links']['show_date']) ? $widget_options['dashboard_incoming_links']['show_date'] : false
  59. );
  60. }
  61. wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' );
  62. }
  63. // WP Plugins Widget
  64. 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' ) ) )
  65. wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_plugins' );
  66. // QuickPress Widget
  67. if ( is_blog_admin() && current_user_can('edit_posts') )
  68. wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press' );
  69. // Recent Drafts
  70. if ( is_blog_admin() && current_user_can('edit_posts') )
  71. wp_add_dashboard_widget( 'dashboard_recent_drafts', __('Recent Drafts'), 'wp_dashboard_recent_drafts' );
  72. // Primary feed (Dev Blog) Widget
  73. if ( !isset( $widget_options['dashboard_primary'] ) ) {
  74. $update = true;
  75. $widget_options['dashboard_primary'] = array(
  76. 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
  77. 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
  78. 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
  79. 'items' => 2,
  80. 'show_summary' => 1,
  81. 'show_author' => 0,
  82. 'show_date' => 1,
  83. );
  84. }
  85. wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
  86. // Secondary Feed (Planet) Widget
  87. if ( !isset( $widget_options['dashboard_secondary'] ) ) {
  88. $update = true;
  89. $widget_options['dashboard_secondary'] = array(
  90. 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
  91. 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
  92. 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
  93. 'items' => 5,
  94. 'show_summary' => 0,
  95. 'show_author' => 0,
  96. 'show_date' => 0,
  97. );
  98. }
  99. wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
  100. // Hook to register new widgets
  101. // Filter widget order
  102. if ( is_network_admin() ) {
  103. do_action( 'wp_network_dashboard_setup' );
  104. $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
  105. } elseif ( is_user_admin() ) {
  106. do_action( 'wp_user_dashboard_setup' );
  107. $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
  108. } else {
  109. do_action( 'wp_dashboard_setup' );
  110. $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
  111. }
  112. foreach ( $dashboard_widgets as $widget_id ) {
  113. $name = empty( $wp_registered_widgets[$widget_id]['all_link'] ) ? $wp_registered_widgets[$widget_id]['name'] : $wp_registered_widgets[$widget_id]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __('View all') . '</a>';
  114. wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
  115. }
  116. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
  117. check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
  118. ob_start(); // hack - but the same hack wp-admin/widgets.php uses
  119. wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
  120. ob_end_clean();
  121. wp_redirect( remove_query_arg( 'edit' ) );
  122. exit;
  123. }
  124. if ( $update )
  125. update_option( 'dashboard_widget_options', $widget_options );
  126. do_action('do_meta_boxes', $screen->id, 'normal', '');
  127. do_action('do_meta_boxes', $screen->id, 'side', '');
  128. }
  129. function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {
  130. $screen = get_current_screen();
  131. global $wp_dashboard_control_callbacks;
  132. if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
  133. $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
  134. if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
  135. list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
  136. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
  137. $callback = '_wp_dashboard_control_callback';
  138. } else {
  139. list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
  140. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
  141. }
  142. }
  143. if ( is_blog_admin () )
  144. $side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');
  145. else if (is_network_admin() )
  146. $side_widgets = array('dashboard_primary', 'dashboard_secondary');
  147. else
  148. $side_widgets = array();
  149. $location = 'normal';
  150. if ( in_array($widget_id, $side_widgets) )
  151. $location = 'side';
  152. $priority = 'core';
  153. if ( 'dashboard_browser_nag' === $widget_id )
  154. $priority = 'high';
  155. add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority );
  156. }
  157. function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
  158. echo '<form action="" method="post" class="dashboard-widget-control-form">';
  159. wp_dashboard_trigger_widget_control( $meta_box['id'] );
  160. wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
  161. echo '<input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" />';
  162. submit_button( __('Submit') );
  163. echo '</form>';
  164. }
  165. /**
  166. * Displays the dashboard.
  167. *
  168. * @since 2.5.0
  169. */
  170. function wp_dashboard() {
  171. $screen = get_current_screen();
  172. $class = 'columns-' . get_current_screen()->get_columns();
  173. ?>
  174. <div id="dashboard-widgets" class="metabox-holder <?php echo $class; ?>">
  175. <div id='postbox-container-1' class='postbox-container'>
  176. <?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
  177. </div>
  178. <div id='postbox-container-2' class='postbox-container'>
  179. <?php do_meta_boxes( $screen->id, 'side', '' ); ?>
  180. </div>
  181. <div id='postbox-container-3' class='postbox-container'>
  182. <?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
  183. </div>
  184. <div id='postbox-container-4' class='postbox-container'>
  185. <?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
  186. </div>
  187. </div>
  188. <?php
  189. wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
  190. wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
  191. }
  192. /* Dashboard Widgets */
  193. function wp_dashboard_right_now() {
  194. global $wp_registered_sidebars;
  195. $num_posts = wp_count_posts( 'post' );
  196. $num_pages = wp_count_posts( 'page' );
  197. $num_cats = wp_count_terms('category');
  198. $num_tags = wp_count_terms('post_tag');
  199. $num_comm = wp_count_comments( );
  200. echo "\n\t".'<div class="table table_content">';
  201. echo "\n\t".'<p class="sub">' . __('Content') . '</p>'."\n\t".'<table>';
  202. echo "\n\t".'<tr class="first">';
  203. // Posts
  204. $num = number_format_i18n( $num_posts->publish );
  205. $text = _n( 'Post', 'Posts', intval($num_posts->publish) );
  206. if ( current_user_can( 'edit_posts' ) ) {
  207. $num = "<a href='edit.php'>$num</a>";
  208. $text = "<a href='edit.php'>$text</a>";
  209. }
  210. echo '<td class="first b b-posts">' . $num . '</td>';
  211. echo '<td class="t posts">' . $text . '</td>';
  212. echo '</tr><tr>';
  213. /* TODO: Show status breakdown on hover
  214. if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds. Don't show if !current_user_can
  215. $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( _n( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
  216. }
  217. if ( $can_edit_posts && !empty($num_posts->draft) ) {
  218. $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>';
  219. }
  220. if ( $can_edit_posts && !empty($num_posts->future) ) {
  221. $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>';
  222. }
  223. if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
  224. $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 ) );
  225. } else {
  226. $pending_text = '';
  227. }
  228. */
  229. // Pages
  230. $num = number_format_i18n( $num_pages->publish );
  231. $text = _n( 'Page', 'Pages', $num_pages->publish );
  232. if ( current_user_can( 'edit_pages' ) ) {
  233. $num = "<a href='edit.php?post_type=page'>$num</a>";
  234. $text = "<a href='edit.php?post_type=page'>$text</a>";
  235. }
  236. echo '<td class="first b b_pages">' . $num . '</td>';
  237. echo '<td class="t pages">' . $text . '</td>';
  238. echo '</tr><tr>';
  239. // Categories
  240. $num = number_format_i18n( $num_cats );
  241. $text = _n( 'Category', 'Categories', $num_cats );
  242. if ( current_user_can( 'manage_categories' ) ) {
  243. $num = "<a href='edit-tags.php?taxonomy=category'>$num</a>";
  244. $text = "<a href='edit-tags.php?taxonomy=category'>$text</a>";
  245. }
  246. echo '<td class="first b b-cats">' . $num . '</td>';
  247. echo '<td class="t cats">' . $text . '</td>';
  248. echo '</tr><tr>';
  249. // Tags
  250. $num = number_format_i18n( $num_tags );
  251. $text = _n( 'Tag', 'Tags', $num_tags );
  252. if ( current_user_can( 'manage_categories' ) ) {
  253. $num = "<a href='edit-tags.php'>$num</a>";
  254. $text = "<a href='edit-tags.php'>$text</a>";
  255. }
  256. echo '<td class="first b b-tags">' . $num . '</td>';
  257. echo '<td class="t tags">' . $text . '</td>';
  258. echo "</tr>";
  259. do_action('right_now_content_table_end');
  260. echo "\n\t</table>\n\t</div>";
  261. echo "\n\t".'<div class="table table_discussion">';
  262. echo "\n\t".'<p class="sub">' . __('Discussion') . '</p>'."\n\t".'<table>';
  263. echo "\n\t".'<tr class="first">';
  264. // Total Comments
  265. $num = '<span class="total-count">' . number_format_i18n($num_comm->total_comments) . '</span>';
  266. $text = _n( 'Comment', 'Comments', $num_comm->total_comments );
  267. if ( current_user_can( 'moderate_comments' ) ) {
  268. $num = '<a href="edit-comments.php">' . $num . '</a>';
  269. $text = '<a href="edit-comments.php">' . $text . '</a>';
  270. }
  271. echo '<td class="b b-comments">' . $num . '</td>';
  272. echo '<td class="last t comments">' . $text . '</td>';
  273. echo '</tr><tr>';
  274. // Approved Comments
  275. $num = '<span class="approved-count">' . number_format_i18n($num_comm->approved) . '</span>';
  276. $text = _nx( 'Approved', 'Approved', $num_comm->approved, 'Right Now' );
  277. if ( current_user_can( 'moderate_comments' ) ) {
  278. $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
  279. $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>$text</a>";
  280. }
  281. echo '<td class="b b_approved">' . $num . '</td>';
  282. echo '<td class="last t">' . $text . '</td>';
  283. echo "</tr>\n\t<tr>";
  284. // Pending Comments
  285. $num = '<span class="pending-count">' . number_format_i18n($num_comm->moderated) . '</span>';
  286. $text = _n( 'Pending', 'Pending', $num_comm->moderated );
  287. if ( current_user_can( 'moderate_comments' ) ) {
  288. $num = "<a href='edit-comments.php?comment_status=moderated'>$num</a>";
  289. $text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>$text</a>";
  290. }
  291. echo '<td class="b b-waiting">' . $num . '</td>';
  292. echo '<td class="last t">' . $text . '</td>';
  293. echo "</tr>\n\t<tr>";
  294. // Spam Comments
  295. $num = number_format_i18n($num_comm->spam);
  296. $text = _nx( 'Spam', 'Spam', $num_comm->spam, 'comment' );
  297. if ( current_user_can( 'moderate_comments' ) ) {
  298. $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
  299. $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>$text</a>";
  300. }
  301. echo '<td class="b b-spam">' . $num . '</td>';
  302. echo '<td class="last t">' . $text . '</td>';
  303. echo "</tr>";
  304. do_action('right_now_table_end');
  305. do_action('right_now_discussion_table_end');
  306. echo "\n\t</table>\n\t</div>";
  307. echo "\n\t".'<div class="versions">';
  308. $theme = wp_get_theme();
  309. echo "\n\t<p>";
  310. if ( $theme->errors() ) {
  311. if ( ! is_multisite() || is_super_admin() )
  312. echo '<span class="error-message">' . __('ERROR: The themes directory is either empty or doesn&#8217;t exist. Please check your installation.') . '</span>';
  313. } elseif ( ! empty($wp_registered_sidebars) ) {
  314. $sidebars_widgets = wp_get_sidebars_widgets();
  315. $num_widgets = 0;
  316. foreach ( (array) $sidebars_widgets as $k => $v ) {
  317. if ( 'wp_inactive_widgets' == $k || 'orphaned_widgets' == substr( $k, 0, 16 ) )
  318. continue;
  319. if ( is_array($v) )
  320. $num_widgets = $num_widgets + count($v);
  321. }
  322. $num = number_format_i18n( $num_widgets );
  323. $switch_themes = $theme->display('Name');
  324. if ( current_user_can( 'switch_themes') )
  325. $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
  326. if ( current_user_can( 'edit_theme_options' ) ) {
  327. 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);
  328. } else {
  329. 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);
  330. }
  331. } else {
  332. if ( current_user_can( 'switch_themes' ) )
  333. printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $theme->display('Name') );
  334. else
  335. printf( __('Theme <span class="b">%1$s</span>'), $theme->display('Name') );
  336. }
  337. echo '</p>';
  338. // Check if search engines are asked not to index this site.
  339. if ( !is_network_admin() && !is_user_admin() && current_user_can('manage_options') && '1' != get_option('blog_public') ) {
  340. $title = apply_filters('privacy_on_link_title', __('Your site is asking search engines not to index its content') );
  341. $content = apply_filters('privacy_on_link_text', __('Search Engines Discouraged') );
  342. echo "<p><a href='options-reading.php' title='$title'>$content</a></p>";
  343. }
  344. update_right_now_message();
  345. echo "\n\t".'<br class="clear" /></div>';
  346. do_action( 'rightnow_end' );
  347. do_action( 'activity_box_end' );
  348. }
  349. function wp_network_dashboard_right_now() {
  350. $actions = array();
  351. if ( current_user_can('create_sites') )
  352. $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>';
  353. if ( current_user_can('create_users') )
  354. $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
  355. $c_users = get_user_count();
  356. $c_blogs = get_blog_count();
  357. $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
  358. $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
  359. $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
  360. if ( $actions ) {
  361. echo '<ul class="subsubsub">';
  362. foreach ( $actions as $class => $action ) {
  363. $actions[ $class ] = "\t<li class='$class'>$action";
  364. }
  365. echo implode( " |</li>\n", $actions ) . "</li>\n";
  366. echo '</ul>';
  367. }
  368. ?>
  369. <br class="clear" />
  370. <p class="youhave"><?php echo $sentence; ?></p>
  371. <?php do_action( 'wpmuadminresult', '' ); ?>
  372. <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
  373. <p>
  374. <input type="search" name="s" value="" size="30" autocomplete="off" />
  375. <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
  376. </p>
  377. </form>
  378. <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
  379. <p>
  380. <input type="search" name="s" value="" size="30" autocomplete="off" />
  381. <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
  382. </p>
  383. </form>
  384. <?php
  385. do_action( 'mu_rightnow_end' );
  386. do_action( 'mu_activity_box_end' );
  387. }
  388. function wp_dashboard_quick_press() {
  389. global $post_ID;
  390. $drafts = false;
  391. if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
  392. $view = get_permalink( $_POST['post_ID'] );
  393. $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
  394. if ( 'post-quickpress-publish' == $_POST['action'] ) {
  395. if ( current_user_can('publish_posts') )
  396. 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 );
  397. else
  398. 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 );
  399. } else {
  400. 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 );
  401. $drafts_query = new WP_Query( array(
  402. 'post_type' => 'post',
  403. 'post_status' => 'draft',
  404. 'author' => $GLOBALS['current_user']->ID,
  405. 'posts_per_page' => 1,
  406. 'orderby' => 'modified',
  407. 'order' => 'DESC'
  408. ) );
  409. if ( $drafts_query->posts )
  410. $drafts =& $drafts_query->posts;
  411. }
  412. 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>' );
  413. $_REQUEST = array(); // hack for get_default_post_to_edit()
  414. }
  415. /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
  416. $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
  417. if ( $last_post_id ) {
  418. $post = get_post( $last_post_id );
  419. if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
  420. $post = get_default_post_to_edit('post', true);
  421. update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
  422. } else {
  423. $post->post_title = ''; // Remove the auto draft title
  424. }
  425. } else {
  426. $post = get_default_post_to_edit( 'post' , true);
  427. $user_id = get_current_user_id();
  428. // Don't create an option if this is a super admin who does not belong to this site.
  429. if ( ! ( is_super_admin( $user_id ) && ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) )
  430. update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
  431. }
  432. $post_ID = (int) $post->ID;
  433. $media_settings = array(
  434. 'id' => $post->ID,
  435. 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ),
  436. );
  437. if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) {
  438. $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
  439. $media_settings['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
  440. }
  441. ?>
  442. <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
  443. <div class="input-text-wrap" id="title-wrap">
  444. <label class="screen-reader-text prompt" for="title" id="title-prompt-text"><?php _e( 'Enter title here' ); ?></label>
  445. <input type="text" name="post_title" id="title" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
  446. </div>
  447. <?php if ( current_user_can( 'upload_files' ) ) : ?>
  448. <div id="wp-content-wrap" class="wp-editor-wrap hide-if-no-js wp-media-buttons">
  449. <?php do_action( 'media_buttons', 'content' ); ?>
  450. </div>
  451. <?php endif; ?>
  452. <div class="textarea-wrap">
  453. <label class="screen-reader-text" for="content"><?php _e( 'Content' ); ?></label>
  454. <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"><?php echo esc_textarea( $post->post_content ); ?></textarea>
  455. </div>
  456. <script type="text/javascript">
  457. edCanvas = document.getElementById('content');
  458. edInsertContent = null;
  459. <?php if ( $_POST ) : ?>
  460. wp.media.editor.remove('content');
  461. wp.media.view.settings.post = <?php echo json_encode( $media_settings ); // big juicy hack. ?>;
  462. wp.media.editor.add('content');
  463. <?php endif; ?>
  464. </script>
  465. <div class="input-text-wrap" id="tags-input-wrap">
  466. <label class="screen-reader-text prompt" for="tags-input" id="tags-input-prompt-text"><?php _e( 'Tags (separate with commas)' ); ?></label>
  467. <input type="text" name="tags_input" id="tags-input" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
  468. </div>
  469. <p class="submit">
  470. <span id="publishing-action">
  471. <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'); ?>" />
  472. <span class="spinner"></span>
  473. </span>
  474. <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
  475. <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
  476. <input type="hidden" name="post_type" value="post" />
  477. <?php wp_nonce_field('add-post'); ?>
  478. <?php submit_button( __( 'Save Draft' ), 'button', 'save', false, array( 'id' => 'save-post' ) ); ?>
  479. <input type="reset" value="<?php esc_attr_e( 'Reset' ); ?>" class="button" />
  480. <br class="clear" />
  481. </p>
  482. </form>
  483. <?php
  484. if ( $drafts )
  485. wp_dashboard_recent_drafts( $drafts );
  486. }
  487. function wp_dashboard_recent_drafts( $drafts = false ) {
  488. if ( !$drafts ) {
  489. $drafts_query = new WP_Query( array(
  490. 'post_type' => 'post',
  491. 'post_status' => 'draft',
  492. 'author' => $GLOBALS['current_user']->ID,
  493. 'posts_per_page' => 5,
  494. 'orderby' => 'modified',
  495. 'order' => 'DESC'
  496. ) );
  497. $drafts =& $drafts_query->posts;
  498. }
  499. if ( $drafts && is_array( $drafts ) ) {
  500. $list = array();
  501. foreach ( $drafts as $draft ) {
  502. $url = get_edit_post_link( $draft->ID );
  503. $title = _draft_or_post_title( $draft->ID );
  504. $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>';
  505. if ( $the_content = preg_split( '#[\r\n\t ]#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
  506. $item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '&hellip;' : '' ) . '</p>';
  507. $list[] = $item;
  508. }
  509. ?>
  510. <ul>
  511. <li><?php echo join( "</li>\n<li>", $list ); ?></li>
  512. </ul>
  513. <p class="textright"><a href="edit.php?post_status=draft" ><?php _e('View all'); ?></a></p>
  514. <?php
  515. } else {
  516. _e('There are no drafts at the moment');
  517. }
  518. }
  519. /**
  520. * Display recent comments dashboard widget content.
  521. *
  522. * @since 2.5.0
  523. */
  524. function wp_dashboard_recent_comments() {
  525. global $wpdb;
  526. // Select all comment types and filter out spam later for better query performance.
  527. $comments = array();
  528. $start = 0;
  529. $widgets = get_option( 'dashboard_widget_options' );
  530. $total_items = isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] )
  531. ? absint( $widgets['dashboard_recent_comments']['items'] ) : 5;
  532. $comments_query = array( 'number' => $total_items * 5, 'offset' => 0 );
  533. if ( ! current_user_can( 'edit_posts' ) )
  534. $comments_query['status'] = 'approve';
  535. while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
  536. foreach ( $possible as $comment ) {
  537. if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
  538. continue;
  539. $comments[] = $comment;
  540. if ( count( $comments ) == $total_items )
  541. break 2;
  542. }
  543. $comments_query['offset'] += $comments_query['number'];
  544. $comments_query['number'] = $total_items * 10;
  545. }
  546. if ( $comments ) {
  547. echo '<div id="the-comment-list" data-wp-lists="list:comment">';
  548. foreach ( $comments as $comment )
  549. _wp_dashboard_recent_comments_row( $comment );
  550. echo '</div>';
  551. if ( current_user_can('edit_posts') )
  552. _get_list_table('WP_Comments_List_Table')->views();
  553. wp_comment_reply( -1, false, 'dashboard', false );
  554. wp_comment_trashnotice();
  555. } else {
  556. echo '<p>' . __( 'No comments yet.' ) . '</p>';
  557. }
  558. }
  559. function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
  560. $GLOBALS['comment'] =& $comment;
  561. $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
  562. $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
  563. $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
  564. $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
  565. $actions_string = '';
  566. if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
  567. // preorder it: Approve | Reply | Edit | Spam | Trash
  568. $actions = array(
  569. 'approve' => '', 'unapprove' => '',
  570. 'reply' => '',
  571. 'edit' => '',
  572. 'spam' => '',
  573. 'trash' => '', 'delete' => ''
  574. );
  575. $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
  576. $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
  577. $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  578. $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  579. $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  580. $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  581. $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  582. $actions['approve'] = "<a href='$approve_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' class='vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
  583. $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' class='vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
  584. $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
  585. $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.esc_attr__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
  586. $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
  587. if ( !EMPTY_TRASH_DAYS )
  588. $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
  589. else
  590. $actions['trash'] = "<a href='$trash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
  591. $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
  592. $i = 0;
  593. foreach ( $actions as $action => $link ) {
  594. ++$i;
  595. ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  596. // Reply and quickedit need a hide-if-no-js span
  597. if ( 'reply' == $action || 'quickedit' == $action )
  598. $action .= ' hide-if-no-js';
  599. $actions_string .= "<span class='$action'>$sep$link</span>";
  600. }
  601. }
  602. ?>
  603. <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
  604. <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
  605. <?php echo get_avatar( $comment, 50 ); ?>
  606. <div class="dashboard-comment-wrap">
  607. <h4 class="comment-meta">
  608. <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
  609. '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
  610. </h4>
  611. <?php
  612. else :
  613. switch ( $comment->comment_type ) :
  614. case 'pingback' :
  615. $type = __( 'Pingback' );
  616. break;
  617. case 'trackback' :
  618. $type = __( 'Trackback' );
  619. break;
  620. default :
  621. $type = ucwords( $comment->comment_type );
  622. endswitch;
  623. $type = esc_html( $type );
  624. ?>
  625. <div class="dashboard-comment-wrap">
  626. <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
  627. <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
  628. <p class="comment-author"><?php comment_author_link(); ?></p>
  629. <?php endif; // comment_type ?>
  630. <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
  631. <p class="row-actions"><?php echo $actions_string; ?></p>
  632. </div>
  633. </div>
  634. <?php
  635. }
  636. /**
  637. * The recent comments dashboard widget control.
  638. *
  639. * @since 3.0.0
  640. */
  641. function wp_dashboard_recent_comments_control() {
  642. if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
  643. $widget_options = array();
  644. if ( !isset($widget_options['dashboard_recent_comments']) )
  645. $widget_options['dashboard_recent_comments'] = array();
  646. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) {
  647. $number = absint( $_POST['widget-recent-comments']['items'] );
  648. $widget_options['dashboard_recent_comments']['items'] = $number;
  649. update_option( 'dashboard_widget_options', $widget_options );
  650. }
  651. $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : '';
  652. echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>';
  653. echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /></p>';
  654. }
  655. function wp_dashboard_incoming_links() {
  656. wp_dashboard_cached_rss_widget( 'dashboard_incoming_links', 'wp_dashboard_incoming_links_output' );
  657. }
  658. /**
  659. * Display incoming links dashboard widget content.
  660. *
  661. * @since 2.5.0
  662. */
  663. function wp_dashboard_incoming_links_output() {
  664. $widgets = get_option( 'dashboard_widget_options' );
  665. @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
  666. $rss = fetch_feed( $url );
  667. if ( is_wp_error($rss) ) {
  668. if ( is_admin() || current_user_can('manage_options') ) {
  669. echo '<p>';
  670. printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
  671. echo '</p>';
  672. }
  673. return;
  674. }
  675. if ( !$rss->get_item_quantity() ) {
  676. 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";
  677. $rss->__destruct();
  678. unset($rss);
  679. return;
  680. }
  681. echo "<ul>\n";
  682. if ( !isset($items) )
  683. $items = 10;
  684. foreach ( $rss->get_items(0, $items) as $item ) {
  685. $publisher = '';
  686. $site_link = '';
  687. $link = '';
  688. $content = '';
  689. $date = '';
  690. $link = esc_url( strip_tags( $item->get_link() ) );
  691. $author = $item->get_author();
  692. if ( $author ) {
  693. $site_link = esc_url( strip_tags( $author->get_link() ) );
  694. if ( !$publisher = esc_html( strip_tags( $author->get_name() ) ) )
  695. $publisher = __( 'Somebody' );
  696. } else {
  697. $publisher = __( 'Somebody' );
  698. }
  699. if ( $site_link )
  700. $publisher = "<a href='$site_link'>$publisher</a>";
  701. else
  702. $publisher = "<strong>$publisher</strong>";
  703. $content = $item->get_content();
  704. $content = wp_html_excerpt($content, 50) . ' ...';
  705. if ( $link )
  706. /* translators: incoming links feed, %1$s is other person, %3$s is content */
  707. $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"' );
  708. else
  709. /* translators: incoming links feed, %1$s is other person, %3$s is content */
  710. $text = __( '%1$s linked here saying, "%3$s"' );
  711. if ( !empty( $show_date ) ) {
  712. if ( $link )
  713. /* translators: incoming links feed, %1$s is other person, %3$s is content, %4$s is the date */
  714. $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s" on %4$s' );
  715. else
  716. /* translators: incoming links feed, %1$s is other person, %3$s is content, %4$s is the date */
  717. $text = __( '%1$s linked here saying, "%3$s" on %4$s' );
  718. $date = esc_html( strip_tags( $item->get_date() ) );
  719. $date = strtotime( $date );
  720. $date = gmdate( get_option( 'date_format' ), $date );
  721. }
  722. echo "\t<li>" . sprintf( $text, $publisher, $link, $content, $date ) . "</li>\n";
  723. }
  724. echo "</ul>\n";
  725. $rss->__destruct();
  726. unset($rss);
  727. }
  728. function wp_dashboard_incoming_links_control() {
  729. wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
  730. }
  731. function wp_dashboard_primary() {
  732. wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_rss_output' );
  733. }
  734. function wp_dashboard_primary_control() {
  735. wp_dashboard_rss_control( 'dashboard_primary' );
  736. }
  737. /**
  738. * {@internal Missing Short Description}}
  739. *
  740. * @since 2.5.0
  741. *
  742. * @param string $widget_id
  743. */
  744. function wp_dashboard_rss_output( $widget_id ) {
  745. $widgets = get_option( 'dashboard_widget_options' );
  746. echo '<div class="rss-widget">';
  747. wp_widget_rss_output( $widgets[$widget_id] );
  748. echo "</div>";
  749. }
  750. function wp_dashboard_secondary() {
  751. wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' );
  752. }
  753. function wp_dashboard_secondary_control() {
  754. wp_dashboard_rss_control( 'dashboard_secondary' );
  755. }
  756. /**
  757. * Display secondary dashboard RSS widget feed.
  758. *
  759. * @since 2.5.0
  760. *
  761. * @return unknown
  762. */
  763. function wp_dashboard_secondary_output() {
  764. $widgets = get_option( 'dashboard_widget_options' );
  765. @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
  766. $rss = @fetch_feed( $url );
  767. if ( is_wp_error($rss) ) {
  768. if ( is_admin() || current_user_can('manage_options') ) {
  769. echo '<div class="rss-widget"><p>';
  770. printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
  771. echo '</p></div>';
  772. }
  773. } elseif ( !$rss->get_item_quantity() ) {
  774. $rss->__destruct();
  775. unset($rss);
  776. return false;
  777. } else {
  778. echo '<div class="rss-widget">';
  779. wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
  780. echo '</div>';
  781. $rss->__destruct();
  782. unset($rss);
  783. }
  784. }
  785. function wp_dashboard_plugins() {
  786. wp_dashboard_cached_rss_widget( 'dashboard_plugins', 'wp_dashboard_plugins_output', array(
  787. 'http://wordpress.org/extend/plugins/rss/browse/popular/',
  788. 'http://wordpress.org/extend/plugins/rss/browse/new/'
  789. ) );
  790. }
  791. /**
  792. * Display plugins most popular, newest plugins, and recently updated widget text.
  793. *
  794. * @since 2.5.0
  795. */
  796. function wp_dashboard_plugins_output() {
  797. $popular = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
  798. $new = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
  799. if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
  800. $plugin_slugs = array_keys( get_plugins() );
  801. set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
  802. }
  803. foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins') ) as $feed => $label ) {
  804. if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
  805. continue;
  806. $items = $$feed->get_items(0, 5);
  807. // Pick a random, non-installed plugin
  808. while ( true ) {
  809. // Abort this foreach loop iteration if there's no plugins left of this type
  810. if ( 0 == count($items) )
  811. continue 2;
  812. $item_key = array_rand($items);
  813. $item = $items[$item_key];
  814. list($link, $frag) = explode( '#', $item->get_link() );
  815. $link = esc_url($link);
  816. if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
  817. $slug = $matches[1];
  818. else {
  819. unset( $items[$item_key] );
  820. continue;
  821. }
  822. // Is this random plugin's slug already installed? If so, try again.
  823. reset( $plugin_slugs );
  824. foreach ( $plugin_slugs as $plugin_slug ) {
  825. if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
  826. unset( $items[$item_key] );
  827. continue 2;
  828. }
  829. }
  830. // If we get to this point, then the random plugin isn't installed and we can stop the while().
  831. break;
  832. }
  833. // Eliminate some common badly formed plugin descriptions
  834. while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
  835. unset($items[$item_key]);
  836. if ( !isset($items[$item_key]) )
  837. continue;
  838. $title = esc_html( $item->get_title() );
  839. $description = esc_html( strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))) );
  840. $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
  841. '&amp;TB_iframe=true&amp;width=600&amp;height=800';
  842. echo "<h4>$label</h4>\n";
  843. echo "<h5><a href='$link'>$title</a></h5>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n";
  844. echo "<p>$description</p>\n";
  845. $$feed->__destruct();
  846. unset($$feed);
  847. }
  848. }
  849. /**
  850. * Checks to see if all of the feed url in $check_urls are cached.
  851. *
  852. * If $check_urls is empty, look for the rss feed url found in the dashboard
  853. * widget options of $widget_id. If cached, call $callback, a function that
  854. * echoes out output for this widget. If not cache, echo a "Loading..." stub
  855. * which is later replaced by AJAX call (see top of /wp-admin/index.php)
  856. *
  857. * @since 2.5.0
  858. *
  859. * @param string $widget_id
  860. * @param callback $callback
  861. * @param array $check_urls RSS feeds
  862. * @return bool False on failure. True on success.
  863. */
  864. function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
  865. $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
  866. $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
  867. if ( empty($check_urls) ) {
  868. $widgets = get_option( 'dashboard_widget_options' );
  869. if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
  870. echo $loading;
  871. return false;
  872. }
  873. $check_urls = array( $widgets[$widget_id]['url'] );
  874. }
  875. $cache_key = 'dash_' . md5( $widget_id );
  876. if ( false !== ( $output = get_transient( $cache_key ) ) ) {
  877. echo $output;
  878. return true;
  879. }
  880. if ( ! $doing_ajax ) {
  881. echo $loading;
  882. return false;
  883. }
  884. if ( $callback && is_callable( $callback ) ) {
  885. $args = array_slice( func_get_args(), 2 );
  886. array_unshift( $args, $widget_id );
  887. ob_start();
  888. call_user_func_array( $callback, $args );
  889. set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
  890. }
  891. return true;
  892. }
  893. /* Dashboard Widgets Controls */
  894. // Calls widget_control callback
  895. /**
  896. * Calls widget control callback.
  897. *
  898. * @since 2.5.0
  899. *
  900. * @param int $widget_control_id Registered Widget ID.
  901. */
  902. function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
  903. global $wp_dashboard_control_callbacks;
  904. if ( is_scalar($widget_control_id) && $widget_control_id && isset($wp_dashboard_control_callbacks[$widget_control_id]) && is_callable($wp_dashboard_control_callbacks[$widget_control_id]) ) {
  905. call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
  906. }
  907. }
  908. /**
  909. * The RSS dashboard widget control.
  910. *
  911. * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
  912. * from RSS-type widgets.
  913. *
  914. * @since 2.5.0
  915. *
  916. * @param string $widget_id
  917. * @param array $form_inputs
  918. */
  919. function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
  920. if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
  921. $widget_options = array();
  922. if ( !isset($widget_options[$widget_id]) )
  923. $widget_options[$widget_id] = array();
  924. $number = 1; // Hack to use wp_widget_rss_form()
  925. $widget_options[$widget_id]['number'] = $number;
  926. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
  927. $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
  928. $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
  929. // title is optional. If black, fill it if possible
  930. if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
  931. $rss = fetch_feed($widget_options[$widget_id]['url']);
  932. if ( is_wp_error($rss) ) {
  933. $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
  934. } else {
  935. $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
  936. $rss->__destruct();
  937. unset($rss);
  938. }
  939. }
  940. update_option( 'dashboard_widget_options', $widget_options );
  941. $cache_key = 'dash_' . md5( $widget_id );
  942. delete_transient( $cache_key );
  943. }
  944. wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
  945. }
  946. // Display File upload quota on dashboard
  947. function wp_dashboard_quota() {
  948. if ( !is_multisite() || !current_user_can('upload_files') || get_site_option( 'upload_space_check_disabled' ) )
  949. return true;
  950. $quota = get_space_allowed();
  951. $used = get_space_used();
  952. if ( $used > $quota )
  953. $percentused = '100';
  954. else
  955. $percentused = ( $used / $quota ) * 100;
  956. $used_color = ( $percentused >= 70 ) ? ' spam' : '';
  957. $used = round( $used, 2 );
  958. $percentused = number_format( $percentused );
  959. ?>
  960. <p class="sub musub"><?php _e( 'Storage Space' ); ?></p>
  961. <div class="table table_content musubtable">
  962. <table>
  963. <tr class="first">
  964. <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>
  965. <td class="t posts"><?php _e( 'Space Allowed' ); ?></td>
  966. </tr>
  967. </table>
  968. </div>
  969. <div class="table table_discussion musubtable">
  970. <table>
  971. <tr class="first">
  972. <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>
  973. <td class="last t comments<?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>
  974. </tr>
  975. </table>
  976. </div>
  977. <br class="clear" />
  978. <?php
  979. }
  980. add_action( 'activity_box_end', 'wp_dashboard_quota' );
  981. // Display Browser Nag Meta Box
  982. function wp_dashboard_browser_nag() {
  983. $notice = '';
  984. $response = wp_check_browser_version();
  985. if ( $response ) {
  986. if ( $response['insecure'] ) {
  987. $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'] ) );
  988. } else {
  989. $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'] ) );
  990. }
  991. $browser_nag_class = '';
  992. if ( !empty( $response['img_src'] ) ) {
  993. $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
  994. $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
  995. $browser_nag_class = ' has-browser-icon';
  996. }
  997. $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
  998. $browsehappy = 'http://browsehappy.com/';
  999. $locale = get_locale();
  1000. if ( 'en_US' !== $locale )
  1001. $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
  1002. $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>';
  1003. $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
  1004. $notice .= '<div class="clear"></div>';
  1005. }
  1006. echo apply_filters( 'browse-happy-notice', $notice, $response );
  1007. }
  1008. function dashboard_browser_nag_class( $classes ) {
  1009. $response = wp_check_browser_version();
  1010. if ( $response && $response['insecure'] )
  1011. $classes[] = 'browser-insecure';
  1012. return $classes;
  1013. }
  1014. /**
  1015. * Check if the user needs a browser update
  1016. *
  1017. * @since 3.2.0
  1018. *
  1019. * @return array|bool False on failure, array of browser data on success.
  1020. */
  1021. function wp_check_browser_version() {
  1022. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
  1023. return false;
  1024. $key = md5( $_SERVER['HTTP_USER_AGENT'] );
  1025. if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
  1026. global $wp_version;
  1027. $options = array(
  1028. 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
  1029. 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
  1030. );
  1031. $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
  1032. if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
  1033. return false;
  1034. /**
  1035. * Response should be an array with:
  1036. * 'name' - string - A user friendly browser name
  1037. * 'version' - string - The most recent version of the browser
  1038. * 'current_version' - string - The version of the browser the user is using
  1039. * 'upgrade' - boolean - Whether the browser needs an upgrade
  1040. * 'insecure' - boolean - Whether the browser is deemed insecure
  1041. * 'upgrade_url' - string - The url to visit to upgrade
  1042. * 'img_src' - string - An image representing the browser
  1043. * 'img_src_ssl' - string - An image (over SSL) representing the browser
  1044. */
  1045. $response = maybe_unserialize( wp_remote_retrieve_body( $response ) );
  1046. if ( ! is_array( $response ) )
  1047. return false;
  1048. set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
  1049. }
  1050. return $response;
  1051. }
  1052. /**
  1053. * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
  1054. */
  1055. function w

Large files files are truncated, but you can click here to view the full file