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

/wp-admin/includes/dashboard.php

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