PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/includes/dashboard.php

https://bitbucket.org/abnopanda/wordpress
PHP | 1279 lines | 918 code | 194 blank | 167 comment | 207 complexity | dbf22d86a072e7823d7277cf9fa1a1a1 MD5 | raw file

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

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