PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/dashboard.php

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