PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/APP/wp-admin/includes/dashboard.php

https://bitbucket.org/AFelipeTrujillo/goblog
PHP | 1354 lines | 806 code | 190 blank | 358 comment | 174 complexity | 58aca13d7c38a8b4e4b955ea875a4b0b MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  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', __( 'At a Glance' ), '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. // Activity Widget
  38. if ( is_blog_admin() ) {
  39. wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
  40. }
  41. // QuickPress Widget
  42. if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
  43. $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Drafts' ) );
  44. wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
  45. }
  46. // WordPress News
  47. wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress News' ), 'wp_dashboard_primary' );
  48. if ( is_network_admin() ) {
  49. /**
  50. * Fires after core widgets for the Network Admin dashboard have been registered.
  51. *
  52. * @since 3.1.0
  53. */
  54. do_action( 'wp_network_dashboard_setup' );
  55. /**
  56. * Filter the list of widgets to load for the Network Admin dashboard.
  57. *
  58. * @since 3.1.0
  59. *
  60. * @param array $dashboard_widgets An array of dashboard widgets.
  61. */
  62. $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
  63. } elseif ( is_user_admin() ) {
  64. /**
  65. * Fires after core widgets for the User Admin dashboard have been registered.
  66. *
  67. * @since 3.1.0
  68. */
  69. do_action( 'wp_user_dashboard_setup' );
  70. /**
  71. * Filter the list of widgets to load for the User Admin dashboard.
  72. *
  73. * @since 3.1.0
  74. *
  75. * @param array $dashboard_widgets An array of dashboard widgets.
  76. */
  77. $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
  78. } else {
  79. /**
  80. * Fires after core widgets for the admin dashboard have been registered.
  81. *
  82. * @since 2.5.0
  83. */
  84. do_action( 'wp_dashboard_setup' );
  85. /**
  86. * Filter the list of widgets to load for the admin dashboard.
  87. *
  88. * @since 2.5.0
  89. *
  90. * @param array $dashboard_widgets An array of dashboard widgets.
  91. */
  92. $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
  93. }
  94. foreach ( $dashboard_widgets as $widget_id ) {
  95. $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>';
  96. wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
  97. }
  98. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
  99. check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
  100. ob_start(); // hack - but the same hack wp-admin/widgets.php uses
  101. wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
  102. ob_end_clean();
  103. wp_redirect( remove_query_arg( 'edit' ) );
  104. exit;
  105. }
  106. if ( $update )
  107. update_option( 'dashboard_widget_options', $widget_options );
  108. /** This action is documented in wp-admin/edit-form-advanced.php */
  109. do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
  110. /** This action is documented in wp-admin/edit-form-advanced.php */
  111. do_action( 'do_meta_boxes', $screen->id, 'side', '' );
  112. }
  113. function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
  114. $screen = get_current_screen();
  115. global $wp_dashboard_control_callbacks;
  116. if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
  117. $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
  118. if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
  119. list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
  120. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
  121. $callback = '_wp_dashboard_control_callback';
  122. } else {
  123. list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
  124. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
  125. }
  126. }
  127. $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
  128. $location = 'normal';
  129. if ( in_array($widget_id, $side_widgets) )
  130. $location = 'side';
  131. $priority = 'core';
  132. if ( 'dashboard_browser_nag' === $widget_id )
  133. $priority = 'high';
  134. add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
  135. }
  136. function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
  137. echo '<form action="" method="post" class="dashboard-widget-control-form">';
  138. wp_dashboard_trigger_widget_control( $meta_box['id'] );
  139. wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
  140. echo '<input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" />';
  141. submit_button( __('Submit') );
  142. echo '</form>';
  143. }
  144. /**
  145. * Displays the dashboard.
  146. *
  147. * @since 2.5.0
  148. */
  149. function wp_dashboard() {
  150. $screen = get_current_screen();
  151. $columns = absint( $screen->get_columns() );
  152. $columns_css = '';
  153. if ( $columns ) {
  154. $columns_css = " columns-$columns";
  155. }
  156. ?>
  157. <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
  158. <div id='postbox-container-1' class='postbox-container'>
  159. <?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
  160. </div>
  161. <div id='postbox-container-2' class='postbox-container'>
  162. <?php do_meta_boxes( $screen->id, 'side', '' ); ?>
  163. </div>
  164. <div id='postbox-container-3' class='postbox-container'>
  165. <?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
  166. </div>
  167. <div id='postbox-container-4' class='postbox-container'>
  168. <?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
  169. </div>
  170. </div>
  171. <?php
  172. wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
  173. wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
  174. }
  175. //
  176. // Dashboard Widgets
  177. //
  178. /**
  179. * Dashboard widget that displays some basic stats about the site.
  180. *
  181. * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
  182. *
  183. * @since 2.7.0
  184. */
  185. function wp_dashboard_right_now() {
  186. $theme = wp_get_theme();
  187. if ( current_user_can( 'switch_themes' ) )
  188. $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme->display('Name') );
  189. else
  190. $theme_name = $theme->display('Name');
  191. ?>
  192. <div class="main">
  193. <ul>
  194. <?php
  195. // Posts and Pages
  196. foreach ( array( 'post', 'page' ) as $post_type ) {
  197. $num_posts = wp_count_posts( $post_type );
  198. if ( $num_posts && $num_posts->publish ) {
  199. if ( 'post' == $post_type ) {
  200. $text = _n( '%s Post', '%s Posts', $num_posts->publish );
  201. } else {
  202. $text = _n( '%s Page', '%s Pages', $num_posts->publish );
  203. }
  204. $text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
  205. $post_type_object = get_post_type_object( $post_type );
  206. if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
  207. printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
  208. } else {
  209. printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
  210. }
  211. }
  212. }
  213. // Comments
  214. $num_comm = wp_count_comments();
  215. if ( $num_comm && $num_comm->total_comments ) {
  216. $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->total_comments ), number_format_i18n( $num_comm->total_comments ) );
  217. ?>
  218. <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
  219. <?php
  220. if ( $num_comm->moderated ) {
  221. /* translators: Number of comments in moderation */
  222. $text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) );
  223. ?>
  224. <li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li>
  225. <?php
  226. }
  227. }
  228. /**
  229. * Filter the array of extra elements to list in the 'At a Glance'
  230. * dashboard widget.
  231. *
  232. * Prior to 3.8.0, the widget was named 'Right Now'. Each element
  233. * is wrapped in list-item tags on output.
  234. *
  235. * @since 3.8.0
  236. *
  237. * @param array $items Array of extra 'At a Glance' widget items.
  238. */
  239. $elements = apply_filters( 'dashboard_glance_items', array() );
  240. if ( $elements ) {
  241. echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
  242. }
  243. ?>
  244. </ul>
  245. <?php
  246. update_right_now_message();
  247. // Check if search engines are asked not to index this site.
  248. if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '1' != get_option( 'blog_public' ) ) {
  249. /**
  250. * Filter the link title attribute for the 'Search Engines Discouraged'
  251. * message displayed in the 'At a Glance' dashboard widget.
  252. *
  253. * Prior to 3.8.0, the widget was named 'Right Now'.
  254. *
  255. * @since 3.0.0
  256. *
  257. * @param string $title Default attribute text.
  258. */
  259. $title = apply_filters( 'privacy_on_link_title', __( 'Your site is asking search engines not to index its content' ) );
  260. /**
  261. * Filter the link label for the 'Search Engines Discouraged' message
  262. * displayed in the 'At a Glance' dashboard widget.
  263. *
  264. * Prior to 3.8.0, the widget was named 'Right Now'.
  265. *
  266. * @since 3.0.0
  267. *
  268. * @param string $content Default text.
  269. */
  270. $content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) );
  271. echo "<p><a href='options-reading.php' title='$title'>$content</a></p>";
  272. }
  273. ?>
  274. </div>
  275. <?php
  276. /*
  277. * activity_box_end has a core action, but only prints content when multisite.
  278. * Using an output buffer is the only way to really check if anything's displayed here.
  279. */
  280. ob_start();
  281. /**
  282. * Fires at the end of the 'At a Glance' dashboard widget.
  283. *
  284. * Prior to 3.8.0, the widget was named 'Right Now'.
  285. *
  286. * @since 2.5.0
  287. */
  288. do_action( 'rightnow_end' );
  289. /**
  290. * Fires at the end of the 'At a Glance' dashboard widget.
  291. *
  292. * Prior to 3.8.0, the widget was named 'Right Now'.
  293. *
  294. * @since 2.0.0
  295. */
  296. do_action( 'activity_box_end' );
  297. $actions = ob_get_clean();
  298. if ( !empty( $actions ) ) : ?>
  299. <div class="sub">
  300. <?php echo $actions; ?>
  301. </div>
  302. <?php endif;
  303. }
  304. function wp_network_dashboard_right_now() {
  305. $actions = array();
  306. if ( current_user_can('create_sites') )
  307. $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>';
  308. if ( current_user_can('create_users') )
  309. $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
  310. $c_users = get_user_count();
  311. $c_blogs = get_blog_count();
  312. $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
  313. $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
  314. $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
  315. if ( $actions ) {
  316. echo '<ul class="subsubsub">';
  317. foreach ( $actions as $class => $action ) {
  318. $actions[ $class ] = "\t<li class='$class'>$action";
  319. }
  320. echo implode( " |</li>\n", $actions ) . "</li>\n";
  321. echo '</ul>';
  322. }
  323. ?>
  324. <br class="clear" />
  325. <p class="youhave"><?php echo $sentence; ?></p>
  326. <?php
  327. /**
  328. * Fires in the Network Admin 'Right Now' dashboard widget
  329. * just before the user and site search form fields.
  330. *
  331. * @since MU
  332. *
  333. * @param null $unused
  334. */
  335. do_action( 'wpmuadminresult', '' );
  336. ?>
  337. <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
  338. <p>
  339. <input type="search" name="s" value="" size="30" autocomplete="off" />
  340. <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
  341. </p>
  342. </form>
  343. <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
  344. <p>
  345. <input type="search" name="s" value="" size="30" autocomplete="off" />
  346. <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
  347. </p>
  348. </form>
  349. <?php
  350. /**
  351. * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
  352. *
  353. * @since MU
  354. */
  355. do_action( 'mu_rightnow_end' );
  356. /**
  357. * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
  358. *
  359. * @since MU
  360. */
  361. do_action( 'mu_activity_box_end' );
  362. }
  363. /**
  364. * The Quick Draft widget display and creation of drafts.
  365. *
  366. * @since 3.8.0
  367. *
  368. * @param string $error_msg Optional. Error message. Default false.
  369. */
  370. function wp_dashboard_quick_press( $error_msg = false ) {
  371. global $post_ID;
  372. /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
  373. $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
  374. if ( $last_post_id ) {
  375. $post = get_post( $last_post_id );
  376. if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
  377. $post = get_default_post_to_edit( 'post', true );
  378. update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
  379. } else {
  380. $post->post_title = ''; // Remove the auto draft title
  381. }
  382. } else {
  383. $post = get_default_post_to_edit( 'post' , true);
  384. $user_id = get_current_user_id();
  385. // Don't create an option if this is a super admin who does not belong to this site.
  386. if ( ! ( is_super_admin( $user_id ) && ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) )
  387. update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
  388. }
  389. $post_ID = (int) $post->ID;
  390. ?>
  391. <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
  392. <?php if ( $error_msg ) : ?>
  393. <div class="error"><?php echo $error_msg; ?></div>
  394. <?php endif; ?>
  395. <div class="input-text-wrap" id="title-wrap">
  396. <label class="screen-reader-text prompt" for="title" id="title-prompt-text">
  397. <?php
  398. /** This filter is documented in wp-admin/edit-form-advanced.php */
  399. echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
  400. ?>
  401. </label>
  402. <input type="text" name="post_title" id="title" autocomplete="off" />
  403. </div>
  404. <div class="textarea-wrap" id="description-wrap">
  405. <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'What&#8217;s on your mind?' ); ?></label>
  406. <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"></textarea>
  407. </div>
  408. <p class="submit">
  409. <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
  410. <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
  411. <input type="hidden" name="post_type" value="post" />
  412. <?php wp_nonce_field( 'add-post' ); ?>
  413. <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
  414. <br class="clear" />
  415. </p>
  416. </form>
  417. <?php
  418. wp_dashboard_recent_drafts();
  419. }
  420. /**
  421. * Show recent drafts of the user on the dashboard.
  422. *
  423. * @since 2.7.0
  424. */
  425. function wp_dashboard_recent_drafts( $drafts = false ) {
  426. if ( ! $drafts ) {
  427. $query_args = array(
  428. 'post_type' => 'post',
  429. 'post_status' => 'draft',
  430. 'author' => get_current_user_id(),
  431. 'posts_per_page' => 4,
  432. 'orderby' => 'modified',
  433. 'order' => 'DESC'
  434. );
  435. $drafts = get_posts( $query_args );
  436. if ( ! $drafts ) {
  437. return;
  438. }
  439. }
  440. echo '<div class="drafts">';
  441. if ( count( $drafts ) > 3 ) {
  442. echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n";
  443. }
  444. echo '<h4 class="hide-if-no-js">' . __( 'Drafts' ) . "</h4>\n<ul>";
  445. $drafts = array_slice( $drafts, 0, 3 );
  446. foreach ( $drafts as $draft ) {
  447. $url = get_edit_post_link( $draft->ID );
  448. $title = _draft_or_post_title( $draft->ID );
  449. echo "<li>\n";
  450. echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
  451. echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( get_option( 'date_format' ), $draft ) . '</time></div>';
  452. if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
  453. echo '<p>' . $the_content . '</p>';
  454. }
  455. echo "</li>\n";
  456. }
  457. echo "</ul>\n</div>";
  458. }
  459. function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
  460. $GLOBALS['comment'] =& $comment;
  461. $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
  462. if ( current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
  463. $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
  464. $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
  465. } else {
  466. $comment_post_link = $comment_post_title;
  467. }
  468. $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
  469. $actions_string = '';
  470. if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
  471. // preorder it: Approve | Reply | Edit | Spam | Trash
  472. $actions = array(
  473. 'approve' => '', 'unapprove' => '',
  474. 'reply' => '',
  475. 'edit' => '',
  476. 'spam' => '',
  477. 'trash' => '', 'delete' => ''
  478. );
  479. $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
  480. $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
  481. $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  482. $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  483. $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  484. $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  485. $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  486. $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>';
  487. $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>';
  488. $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
  489. $actions['reply'] = '<a onclick="window.commentReply && 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>';
  490. $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>';
  491. if ( !EMPTY_TRASH_DAYS )
  492. $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>';
  493. else
  494. $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>';
  495. /**
  496. * Filter the action links displayed for each comment in the 'Recent Comments'
  497. * dashboard widget.
  498. *
  499. * @since 2.6.0
  500. *
  501. * @param array $actions An array of comment actions. Default actions include:
  502. * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
  503. * 'Delete', and 'Trash'.
  504. * @param object $comment The comment object.
  505. */
  506. $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
  507. $i = 0;
  508. foreach ( $actions as $action => $link ) {
  509. ++$i;
  510. ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  511. // Reply and quickedit need a hide-if-no-js span
  512. if ( 'reply' == $action || 'quickedit' == $action )
  513. $action .= ' hide-if-no-js';
  514. $actions_string .= "<span class='$action'>$sep$link</span>";
  515. }
  516. }
  517. ?>
  518. <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
  519. <?php echo get_avatar( $comment, 50, 'mystery' ); ?>
  520. <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
  521. <div class="dashboard-comment-wrap">
  522. <h4 class="comment-meta">
  523. <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
  524. '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
  525. </h4>
  526. <?php
  527. else :
  528. switch ( $comment->comment_type ) :
  529. case 'pingback' :
  530. $type = __( 'Pingback' );
  531. break;
  532. case 'trackback' :
  533. $type = __( 'Trackback' );
  534. break;
  535. default :
  536. $type = ucwords( $comment->comment_type );
  537. endswitch;
  538. $type = esc_html( $type );
  539. ?>
  540. <div class="dashboard-comment-wrap">
  541. <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
  542. <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
  543. <p class="comment-author"><?php comment_author_link(); ?></p>
  544. <?php endif; // comment_type ?>
  545. <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
  546. <p class="row-actions"><?php echo $actions_string; ?></p>
  547. </div>
  548. </div>
  549. <?php
  550. }
  551. /**
  552. * Callback function for Activity widget.
  553. *
  554. * @since 3.8.0
  555. */
  556. function wp_dashboard_site_activity() {
  557. echo '<div id="activity-widget">';
  558. $future_posts = wp_dashboard_recent_posts( array(
  559. 'max' => 5,
  560. 'status' => 'future',
  561. 'order' => 'ASC',
  562. 'title' => __( 'Publishing Soon' ),
  563. 'id' => 'future-posts',
  564. ) );
  565. $recent_posts = wp_dashboard_recent_posts( array(
  566. 'max' => 5,
  567. 'status' => 'publish',
  568. 'order' => 'DESC',
  569. 'title' => __( 'Recently Published' ),
  570. 'id' => 'published-posts',
  571. ) );
  572. $recent_comments = wp_dashboard_recent_comments();
  573. if ( !$future_posts && !$recent_posts && !$recent_comments ) {
  574. echo '<div class="no-activity">';
  575. echo '<p class="smiley"></p>';
  576. echo '<p>' . __( 'No activity yet!' ) . '</p>';
  577. echo '</div>';
  578. }
  579. echo '</div>';
  580. }
  581. /**
  582. * Generates Publishing Soon and Recently Published sections.
  583. *
  584. * @since 3.8.0
  585. *
  586. * @param array $args {
  587. * An array of query and display arguments.
  588. *
  589. * @type int $max Number of posts to display.
  590. * @type string $status Post status.
  591. * @type string $order Designates ascending ('ASC') or descending ('DESC') order.
  592. * @type string $title Section title.
  593. * @type string $id The container id.
  594. * }
  595. * @return bool False if no posts were found. True otherwise.
  596. */
  597. function wp_dashboard_recent_posts( $args ) {
  598. $query_args = array(
  599. 'post_type' => 'post',
  600. 'post_status' => $args['status'],
  601. 'orderby' => 'date',
  602. 'order' => $args['order'],
  603. 'posts_per_page' => intval( $args['max'] ),
  604. 'no_found_rows' => true,
  605. 'cache_results' => false,
  606. 'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
  607. );
  608. $posts = new WP_Query( $query_args );
  609. if ( $posts->have_posts() ) {
  610. echo '<div id="' . $args['id'] . '" class="activity-block">';
  611. echo '<h4>' . $args['title'] . '</h4>';
  612. echo '<ul>';
  613. $i = 0;
  614. $today = date( 'Y-m-d', current_time( 'timestamp' ) );
  615. $tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
  616. while ( $posts->have_posts() ) {
  617. $posts->the_post();
  618. $time = get_the_time( 'U' );
  619. if ( date( 'Y-m-d', $time ) == $today ) {
  620. $relative = __( 'Today' );
  621. } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
  622. $relative = __( 'Tomorrow' );
  623. } else {
  624. /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */
  625. $relative = date_i18n( __( 'M jS' ), $time );
  626. }
  627. if ( current_user_can( 'edit_post', get_the_ID() ) ) {
  628. /* translators: 1: relative date, 2: time, 3: post edit link, 4: post title */
  629. $format = __( '<span>%1$s, %2$s</span> <a href="%3$s">%4$s</a>' );
  630. printf( "<li>$format</li>", $relative, get_the_time(), get_edit_post_link(), _draft_or_post_title() );
  631. } else {
  632. /* translators: 1: relative date, 2: time, 3: post title */
  633. $format = __( '<span>%1$s, %2$s</span> %3$s' );
  634. printf( "<li>$format</li>", $relative, get_the_time(), _draft_or_post_title() );
  635. }
  636. }
  637. echo '</ul>';
  638. echo '</div>';
  639. } else {
  640. return false;
  641. }
  642. wp_reset_postdata();
  643. return true;
  644. }
  645. /**
  646. * Show Comments section.
  647. *
  648. * @since 3.8.0
  649. *
  650. * @param int $total_items Optional. Number of comments to query. Default 5.
  651. * @return bool False if no comments were found. True otherwise.
  652. */
  653. function wp_dashboard_recent_comments( $total_items = 5 ) {
  654. global $wpdb;
  655. // Select all comment types and filter out spam later for better query performance.
  656. $comments = array();
  657. $start = 0;
  658. $comments_query = array(
  659. 'number' => $total_items * 5,
  660. 'offset' => 0
  661. );
  662. if ( ! current_user_can( 'edit_posts' ) )
  663. $comments_query['status'] = 'approve';
  664. while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
  665. foreach ( $possible as $comment ) {
  666. if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
  667. continue;
  668. $comments[] = $comment;
  669. if ( count( $comments ) == $total_items )
  670. break 2;
  671. }
  672. $comments_query['offset'] += $comments_query['number'];
  673. $comments_query['number'] = $total_items * 10;
  674. }
  675. if ( $comments ) {
  676. echo '<div id="latest-comments" class="activity-block">';
  677. echo '<h4>' . __( 'Comments' ) . '</h4>';
  678. echo '<div id="the-comment-list" data-wp-lists="list:comment">';
  679. foreach ( $comments as $comment )
  680. _wp_dashboard_recent_comments_row( $comment );
  681. echo '</div>';
  682. if ( current_user_can('edit_posts') )
  683. _get_list_table('WP_Comments_List_Table')->views();
  684. wp_comment_reply( -1, false, 'dashboard', false );
  685. wp_comment_trashnotice();
  686. echo '</div>';
  687. } else {
  688. return false;
  689. }
  690. return true;
  691. }
  692. /**
  693. * Display generic dashboard RSS widget feed.
  694. *
  695. * @since 2.5.0
  696. *
  697. * @param string $widget_id
  698. */
  699. function wp_dashboard_rss_output( $widget_id ) {
  700. $widgets = get_option( 'dashboard_widget_options' );
  701. echo '<div class="rss-widget">';
  702. wp_widget_rss_output( $widgets[ $widget_id ] );
  703. echo "</div>";
  704. }
  705. /**
  706. * Checks to see if all of the feed url in $check_urls are cached.
  707. *
  708. * If $check_urls is empty, look for the rss feed url found in the dashboard
  709. * widget options of $widget_id. If cached, call $callback, a function that
  710. * echoes out output for this widget. If not cache, echo a "Loading..." stub
  711. * which is later replaced by AJAX call (see top of /wp-admin/index.php)
  712. *
  713. * @since 2.5.0
  714. *
  715. * @param string $widget_id
  716. * @param callback $callback
  717. * @param array $check_urls RSS feeds
  718. * @return bool False on failure. True on success.
  719. */
  720. function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
  721. $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&#8230;' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
  722. $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
  723. if ( empty($check_urls) ) {
  724. $widgets = get_option( 'dashboard_widget_options' );
  725. if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
  726. echo $loading;
  727. return false;
  728. }
  729. $check_urls = array( $widgets[$widget_id]['url'] );
  730. }
  731. $cache_key = 'dash_' . md5( $widget_id );
  732. if ( false !== ( $output = get_transient( $cache_key ) ) ) {
  733. echo $output;
  734. return true;
  735. }
  736. if ( ! $doing_ajax ) {
  737. echo $loading;
  738. return false;
  739. }
  740. if ( $callback && is_callable( $callback ) ) {
  741. $args = array_slice( func_get_args(), 2 );
  742. array_unshift( $args, $widget_id );
  743. ob_start();
  744. call_user_func_array( $callback, $args );
  745. set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
  746. }
  747. return true;
  748. }
  749. /* Dashboard Widgets Controls */
  750. // Calls widget_control callback
  751. /**
  752. * Calls widget control callback.
  753. *
  754. * @since 2.5.0
  755. *
  756. * @param int $widget_control_id Registered Widget ID.
  757. */
  758. function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
  759. global $wp_dashboard_control_callbacks;
  760. 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]) ) {
  761. call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
  762. }
  763. }
  764. /**
  765. * The RSS dashboard widget control.
  766. *
  767. * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
  768. * from RSS-type widgets.
  769. *
  770. * @since 2.5.0
  771. *
  772. * @param string $widget_id
  773. * @param array $form_inputs
  774. */
  775. function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
  776. if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
  777. $widget_options = array();
  778. if ( !isset($widget_options[$widget_id]) )
  779. $widget_options[$widget_id] = array();
  780. $number = 1; // Hack to use wp_widget_rss_form()
  781. $widget_options[$widget_id]['number'] = $number;
  782. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
  783. $_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] );
  784. $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
  785. $widget_options[$widget_id]['number'] = $number;
  786. // title is optional. If black, fill it if possible
  787. if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
  788. $rss = fetch_feed($widget_options[$widget_id]['url']);
  789. if ( is_wp_error($rss) ) {
  790. $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
  791. } else {
  792. $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
  793. $rss->__destruct();
  794. unset($rss);
  795. }
  796. }
  797. update_option( 'dashboard_widget_options', $widget_options );
  798. $cache_key = 'dash_' . md5( $widget_id );
  799. delete_transient( $cache_key );
  800. }
  801. wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
  802. }
  803. /**
  804. * WordPress News dashboard widget.
  805. *
  806. * @since 2.7.0
  807. */
  808. function wp_dashboard_primary() {
  809. $feeds = array(
  810. 'news' => array(
  811. /**
  812. * Filter the primary link URL for the 'WordPress News' dashboard widget.
  813. *
  814. * @since 2.5.0
  815. *
  816. * @param string $link The widget's primary link URL.
  817. */
  818. 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
  819. /**
  820. * Filter the primary feed URL for the 'WordPress News' dashboard widget.
  821. *
  822. * @since 2.3.0
  823. *
  824. * @param string $url The widget's primary feed URL.
  825. */
  826. 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
  827. /**
  828. * Filter the primary link title for the 'WordPress News' dashboard widget.
  829. *
  830. * @since 2.3.0
  831. *
  832. * @param string $title Title attribute for the widget's primary link.
  833. */
  834. 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
  835. 'items' => 1,
  836. 'show_summary' => 1,
  837. 'show_author' => 0,
  838. 'show_date' => 1,
  839. ),
  840. 'planet' => array(
  841. /**
  842. * Filter the secondary link URL for the 'WordPress News' dashboard widget.
  843. *
  844. * @since 2.3.0
  845. *
  846. * @param string $link The widget's secondary link URL.
  847. */
  848. 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
  849. /**
  850. * Filter the secondary feed URL for the 'WordPress News' dashboard widget.
  851. *
  852. * @since 2.3.0
  853. *
  854. * @param string $url The widget's secondary feed URL.
  855. */
  856. 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
  857. /**
  858. * Filter the secondary link title for the 'WordPress News' dashboard widget.
  859. *
  860. * @since 2.3.0
  861. *
  862. * @param string $title Title attribute for the widget's secondary link.
  863. */
  864. 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
  865. 'items' => 3,
  866. 'show_summary' => 0,
  867. 'show_author' => 0,
  868. 'show_date' => 0,
  869. )
  870. );
  871. 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' ) ) ) {
  872. $feeds['plugins'] = array(
  873. 'link' => '',
  874. 'url' => array(
  875. 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
  876. ),
  877. 'title' => '',
  878. 'items' => 1,
  879. 'show_summary' => 0,
  880. 'show_author' => 0,
  881. 'show_date' => 0,
  882. );
  883. }
  884. wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
  885. }
  886. /**
  887. * Display the WordPress news feeds.
  888. *
  889. * @since 3.8.0
  890. *
  891. * @param string $widget_id Widget ID.
  892. * @param array $feeds Array of RSS feeds.
  893. */
  894. function wp_dashboard_primary_output( $widget_id, $feeds ) {
  895. foreach( $feeds as $type => $args ) {
  896. $args['type'] = $type;
  897. echo '<div class="rss-widget">';
  898. if ( $type === 'plugins' ) {
  899. wp_dashboard_plugins_output( $args['url'], $args );
  900. } else {
  901. wp_widget_rss_output( $args['url'], $args );
  902. }
  903. echo "</div>";
  904. }
  905. }
  906. /**
  907. * Display plugins text for the WordPress news widget.
  908. *
  909. * @since 2.5.0
  910. */
  911. function wp_dashboard_plugins_output( $rss, $args = array() ) {
  912. // Plugin feeds plus link to install them
  913. $popular = fetch_feed( $args['url']['popular'] );
  914. if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
  915. $plugin_slugs = array_keys( get_plugins() );
  916. set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
  917. }
  918. echo '<ul>';
  919. foreach ( array(
  920. 'popular' => __( 'Popular Plugin' )
  921. ) as $feed => $label ) {
  922. if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
  923. continue;
  924. $items = $$feed->get_items(0, 5);
  925. // Pick a random, non-installed plugin
  926. while ( true ) {
  927. // Abort this foreach loop iteration if there's no plugins left of this type
  928. if ( 0 == count($items) )
  929. continue 2;
  930. $item_key = array_rand($items);
  931. $item = $items[$item_key];
  932. list($link, $frag) = explode( '#', $item->get_link() );
  933. $link = esc_url($link);
  934. if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
  935. $slug = $matches[1];
  936. else {
  937. unset( $items[$item_key] );
  938. continue;
  939. }
  940. // Is this random plugin's slug already installed? If so, try again.
  941. reset( $plugin_slugs );
  942. foreach ( $plugin_slugs as $plugin_slug ) {
  943. if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
  944. unset( $items[$item_key] );
  945. continue 2;
  946. }
  947. }
  948. // If we get to this point, then the random plugin isn't installed and we can stop the while().
  949. break;
  950. }
  951. // Eliminate some common badly formed plugin descriptions
  952. while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
  953. unset($items[$item_key]);
  954. if ( !isset($items[$item_key]) )
  955. continue;
  956. $title = esc_html( $item->get_title() );
  957. $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
  958. $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&amp;TB_iframe=true&amp;width=600&amp;height=800';
  959. echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a>&nbsp;<span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>";
  960. $$feed->__destruct();
  961. unset( $$feed );
  962. }
  963. echo '</ul>';
  964. }
  965. /**
  966. * Display file upload quota on dashboard.
  967. *
  968. * Runs on the activity_box_end hook in wp_dashboard_right_now().
  969. *
  970. * @since 3.0.0
  971. *
  972. * @return bool True if not multisite, user can't upload files, or the space check option is disabled.
  973. */
  974. function wp_dashboard_quota() {
  975. if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
  976. return true;
  977. $quota = get_space_allowed();
  978. $used = get_space_used();
  979. if ( $used > $quota )
  980. $percentused = '100';
  981. else
  982. $percentused = ( $used / $quota ) * 100;
  983. $used_class = ( $percentused >= 70 ) ? ' warning' : '';
  984. $used = round( $used, 2 );
  985. $percentused = number_format( $percentused );
  986. ?>
  987. <h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4>
  988. <div class="mu-storage">
  989. <ul>
  990. <li class="storage-count">
  991. <?php $text = sprintf(
  992. /* translators: number of megabytes */
  993. __( '%s MB Space Allowed' ),
  994. number_format_i18n( $quota )
  995. );
  996. printf(
  997. '<a href="%1$s" title="%2$s">%3$s</a>',
  998. esc_url( admin_url( 'upload.php' ) ),
  999. __( 'Manage Uploads' ),
  1000. $text
  1001. ); ?>
  1002. </li><li class="storage-count <?php echo $used_class; ?>">
  1003. <?php $text = sprintf(
  1004. /* translators: 1: number of megabytes, 2: percentage */
  1005. __( '%1$s MB (%2$s%%) Space Used' ),
  1006. number_format_i18n( $used, 2 ),
  1007. $percentused
  1008. );
  1009. printf(
  1010. '<a href="%1$s" title="%2$s" class="musublink">%3$s</a>',
  1011. esc_url( admin_url( 'upload.php' ) ),
  1012. __( 'Manage Uploads' ),
  1013. $text
  1014. ); ?>
  1015. </li>
  1016. </ul>
  1017. </div>
  1018. <?php
  1019. }
  1020. add_action( 'activity_box_end', 'wp_dashboard_quota' );
  1021. // Display Browser Nag Meta Box
  1022. function wp_dashboard_browser_nag() {
  1023. $notice = '';
  1024. $response = wp_check_browser_version();
  1025. if ( $response ) {
  1026. if ( $response['insecure'] ) {
  1027. $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'] ) );
  1028. } else {
  1029. $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'] ) );
  1030. }
  1031. $browser_nag_class = '';
  1032. if ( !empty( $response['img_src'] ) ) {
  1033. $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
  1034. $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
  1035. $browser_nag_class = ' has-browser-icon';
  1036. }
  1037. $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
  1038. $browsehappy = 'http://browsehappy.com/';
  1039. $locale = get_locale();
  1040. if ( 'en_US' !== $locale )
  1041. $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
  1042. $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>';
  1043. $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
  1044. $notice .= '<div class="clear"></div>';
  1045. }
  1046. /**
  1047. * Filter the notice output for the 'Browse Happy' nag meta box.
  1048. *
  1049. * @since 3.2.0
  1050. *
  1051. * @param string $notice The notice content.
  1052. * @param array $response An array containing web browser information.
  1053. */
  1054. echo apply_filters( 'browse-happy-notice', $notice, $response );
  1055. }
  1056. function dashboard_browser_nag_class( $classes ) {
  1057. $response = wp_check_browser_version();
  1058. if ( $response && $response['insecure'] )
  1059. $classes[] = 'browser-insecure';
  1060. return $classes;
  1061. }
  1062. /**
  1063. * Check if the user needs a browser update
  1064. *
  1065. * @since 3.2.0
  1066. *
  1067. * @return array|bool False on failure, array of browser data on success.
  1068. */
  1069. function wp_check_browser_version() {
  1070. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
  1071. return false;
  1072. $key = md5( $_SERVER['HTTP_USER_AGENT'] );
  1073. if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
  1074. global $wp_version;
  1075. $options = array(
  1076. 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
  1077. 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
  1078. );
  1079. $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options );
  1080. if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
  1081. return false;
  1082. /**
  1083. * Response should be an array with:
  1084. * 'name' - string - A user friendly browser name
  1085. * 'version' - string - The most recent version of the browser
  1086. * 'current_version' - string - The version of the browser the user is using
  1087. * 'upgrade' - boolean - Whether the browser needs an upgrade
  1088. * 'insecure' - boolean - Whether the browser is deemed insecure
  1089. * 'upgrade_url' - string - The url to visit to upgrade
  1090. * 'img_src' - string - An image representing the browser
  1091. * 'img_src_ssl' - string - An image (over SSL) representing the browser
  1092. */
  1093. $response = json_decode( wp_remote_retrieve_body( $response ), true );
  1094. if ( ! is_array( $response ) )
  1095. return false;
  1096. set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
  1097. }
  1098. return $response;
  1099. }
  1100. /**
  1101. * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
  1102. */
  1103. function wp_dashboard_empty() {}
  1104. /**
  1105. * Displays a welcome panel to introduce users to WordPress.
  1106. *
  1107. * @since 3.3.0
  1108. */
  1109. function wp_welcome_panel() {
  1110. ?>
  1111. <div class="welcome-panel-content">
  1112. <h3><?php _e( 'Welcome to WordPress!' ); ?></h3>
  1113. <p class="about-description"><?php _e( 'We&#8217;ve assembled some links to get you started:' ); ?></p>
  1114. <div class="welcome-panel-column-container">
  1115. <div class="welcome-panel-column">
  1116. <h4><?php _e( 'Get Started' ); ?></h4>
  1117. <a class="button button-primary button-hero load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Customize Your Site' ); ?></a>
  1118. <a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
  1119. <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
  1120. <p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), admin_url( 'themes.php' ) ); ?></p>
  1121. <?php endif; ?>
  1122. </div>
  1123. <div class="welcome-panel-column">
  1124. <h4><?php _e( 'Next Steps' ); ?></h4>
  1125. <ul>
  1126. <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
  1127. <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
  1128. <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
  1129. <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
  1130. <li><?php printf( '<a href="%s" class="welcome-icon welcome-edit-page">' . __( 'Edit your front page' ) . '</a>', get_edit_post_link( get_option( 'page_on_front' ) ) ); ?></li>
  1131. <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add additional pages' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
  1132. <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
  1133. <?php else : ?>
  1134. <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
  1135. <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add an About page' ) . '</a>', admin_url( 'post-new.php?post_type=page' ) ); ?></li>
  1136. <?php endif; ?>
  1137. <li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
  1138. </ul>
  1139. </div>
  1140. <div class="welcome-panel-column welcome-panel-last">
  1141. <h4><?php _e( 'More Actions' ); ?></h4>
  1142. <ul>
  1143. <?php if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) : ?>
  1144. <li><div class="welcome-icon welcome-widgets-menus"><?php
  1145. if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
  1146. printf( __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
  1147. admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) );
  1148. } elseif ( current_theme_supports( 'widgets' ) ) {
  1149. echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
  1150. } else {
  1151. echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
  1152. }
  1153. ?></div></li>
  1154. <?php endif; ?>
  1155. <?php if ( current_user_can( 'manage_options' ) ) : ?>
  1156. <li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
  1157. <?php endif; ?>
  1158. <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'http://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li>
  1159. </ul>
  1160. </div>
  1161. </div>
  1162. </div>
  1163. <?php
  1164. }