dashboard.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  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. }
  33. // PHP Version.
  34. $response = wp_check_php_version();
  35. if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] && current_user_can( 'update_php' ) ) {
  36. add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' );
  37. wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' );
  38. }
  39. // Right Now
  40. if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
  41. wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
  42. }
  43. if ( is_network_admin() ) {
  44. wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
  45. }
  46. // Activity Widget
  47. if ( is_blog_admin() ) {
  48. wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
  49. }
  50. // QuickPress Widget
  51. if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
  52. $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) );
  53. wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
  54. }
  55. // WordPress Events and News
  56. wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );
  57. if ( is_network_admin() ) {
  58. /**
  59. * Fires after core widgets for the Network Admin dashboard have been registered.
  60. *
  61. * @since 3.1.0
  62. */
  63. do_action( 'wp_network_dashboard_setup' );
  64. /**
  65. * Filters the list of widgets to load for the Network Admin dashboard.
  66. *
  67. * @since 3.1.0
  68. *
  69. * @param string[] $dashboard_widgets An array of dashboard widget IDs.
  70. */
  71. $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
  72. } elseif ( is_user_admin() ) {
  73. /**
  74. * Fires after core widgets for the User Admin dashboard have been registered.
  75. *
  76. * @since 3.1.0
  77. */
  78. do_action( 'wp_user_dashboard_setup' );
  79. /**
  80. * Filters the list of widgets to load for the User Admin dashboard.
  81. *
  82. * @since 3.1.0
  83. *
  84. * @param string[] $dashboard_widgets An array of dashboard widget IDs.
  85. */
  86. $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
  87. } else {
  88. /**
  89. * Fires after core widgets for the admin dashboard have been registered.
  90. *
  91. * @since 2.5.0
  92. */
  93. do_action( 'wp_dashboard_setup' );
  94. /**
  95. * Filters the list of widgets to load for the admin dashboard.
  96. *
  97. * @since 2.5.0
  98. *
  99. * @param string[] $dashboard_widgets An array of dashboard widget IDs.
  100. */
  101. $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
  102. }
  103. foreach ( $dashboard_widgets as $widget_id ) {
  104. $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>';
  105. wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] );
  106. }
  107. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
  108. check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
  109. ob_start(); // hack - but the same hack wp-admin/widgets.php uses
  110. wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
  111. ob_end_clean();
  112. wp_redirect( remove_query_arg( 'edit' ) );
  113. exit;
  114. }
  115. /** This action is documented in wp-admin/includes/meta-boxes.php */
  116. do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
  117. /** This action is documented in wp-admin/includes/meta-boxes.php */
  118. do_action( 'do_meta_boxes', $screen->id, 'side', '' );
  119. }
  120. /**
  121. * Adds a new dashboard widget.
  122. *
  123. * @since 2.7.0
  124. *
  125. * @global array $wp_dashboard_control_callbacks
  126. *
  127. * @param string $widget_id Widget ID (used in the 'id' attribute for the widget).
  128. * @param string $widget_name Title of the widget.
  129. * @param callable $callback Function that fills the widget with the desired content.
  130. * The function should echo its output.
  131. * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
  132. * @param array $callback_args Optional. Data that should be set as the $args property of the widget array
  133. * (which is the second parameter passed to your callback). Default null.
  134. */
  135. function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
  136. $screen = get_current_screen();
  137. global $wp_dashboard_control_callbacks;
  138. $private_callback_args = array( '__widget_basename' => $widget_name );
  139. if ( is_null( $callback_args ) ) {
  140. $callback_args = $private_callback_args;
  141. } elseif ( is_array( $callback_args ) ) {
  142. $callback_args = array_merge( $callback_args, $private_callback_args );
  143. }
  144. if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
  145. $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback;
  146. if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
  147. list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
  148. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
  149. $callback = '_wp_dashboard_control_callback';
  150. } else {
  151. list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
  152. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
  153. }
  154. }
  155. $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
  156. $location = 'normal';
  157. if ( in_array( $widget_id, $side_widgets ) ) {
  158. $location = 'side';
  159. }
  160. $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
  161. $priority = 'core';
  162. if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
  163. $priority = 'high';
  164. }
  165. add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
  166. }
  167. /**
  168. * Outputs controls for the current dashboard widget.
  169. *
  170. * @access private
  171. * @since 2.7.0
  172. *
  173. * @param mixed $dashboard
  174. * @param array $meta_box
  175. */
  176. function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
  177. echo '<form method="post" class="dashboard-widget-control-form wp-clearfix">';
  178. wp_dashboard_trigger_widget_control( $meta_box['id'] );
  179. wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
  180. echo '<input type="hidden" name="widget_id" value="' . esc_attr( $meta_box['id'] ) . '" />';
  181. submit_button( __( 'Submit' ) );
  182. echo '</form>';
  183. }
  184. /**
  185. * Displays the dashboard.
  186. *
  187. * @since 2.5.0
  188. */
  189. function wp_dashboard() {
  190. $screen = get_current_screen();
  191. $columns = absint( $screen->get_columns() );
  192. $columns_css = '';
  193. if ( $columns ) {
  194. $columns_css = " columns-$columns";
  195. }
  196. ?>
  197. <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
  198. <div id="postbox-container-1" class="postbox-container">
  199. <?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
  200. </div>
  201. <div id="postbox-container-2" class="postbox-container">
  202. <?php do_meta_boxes( $screen->id, 'side', '' ); ?>
  203. </div>
  204. <div id="postbox-container-3" class="postbox-container">
  205. <?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
  206. </div>
  207. <div id="postbox-container-4" class="postbox-container">
  208. <?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
  209. </div>
  210. </div>
  211. <?php
  212. wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
  213. wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
  214. }
  215. //
  216. // Dashboard Widgets
  217. //
  218. /**
  219. * Dashboard widget that displays some basic stats about the site.
  220. *
  221. * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
  222. *
  223. * @since 2.7.0
  224. */
  225. function wp_dashboard_right_now() {
  226. ?>
  227. <div class="main">
  228. <ul>
  229. <?php
  230. // Posts and Pages
  231. foreach ( array( 'post', 'page' ) as $post_type ) {
  232. $num_posts = wp_count_posts( $post_type );
  233. if ( $num_posts && $num_posts->publish ) {
  234. if ( 'post' == $post_type ) {
  235. /* translators: %s: Number of posts. */
  236. $text = _n( '%s Post', '%s Posts', $num_posts->publish );
  237. } else {
  238. /* translators: %s: Number of pages. */
  239. $text = _n( '%s Page', '%s Pages', $num_posts->publish );
  240. }
  241. $text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
  242. $post_type_object = get_post_type_object( $post_type );
  243. if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
  244. printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
  245. } else {
  246. printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
  247. }
  248. }
  249. }
  250. // Comments
  251. $num_comm = wp_count_comments();
  252. if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
  253. /* translators: %s: Number of comments. */
  254. $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
  255. ?>
  256. <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
  257. <?php
  258. $moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated );
  259. /* translators: %s: Number of comments. */
  260. $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );
  261. ?>
  262. <li class="comment-mod-count
  263. <?php
  264. if ( ! $num_comm->moderated ) {
  265. echo ' hidden';
  266. }
  267. ?>
  268. "><a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a></li>
  269. <?php
  270. }
  271. /**
  272. * Filters the array of extra elements to list in the 'At a Glance'
  273. * dashboard widget.
  274. *
  275. * Prior to 3.8.0, the widget was named 'Right Now'. Each element
  276. * is wrapped in list-item tags on output.
  277. *
  278. * @since 3.8.0
  279. *
  280. * @param string[] $items Array of extra 'At a Glance' widget items.
  281. */
  282. $elements = apply_filters( 'dashboard_glance_items', array() );
  283. if ( $elements ) {
  284. echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
  285. }
  286. ?>
  287. </ul>
  288. <?php
  289. update_right_now_message();
  290. // Check if search engines are asked not to index this site.
  291. if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '0' == get_option( 'blog_public' ) ) {
  292. /**
  293. * Filters the link title attribute for the 'Search Engines Discouraged'
  294. * message displayed in the 'At a Glance' dashboard widget.
  295. *
  296. * Prior to 3.8.0, the widget was named 'Right Now'.
  297. *
  298. * @since 3.0.0
  299. * @since 4.5.0 The default for `$title` was updated to an empty string.
  300. *
  301. * @param string $title Default attribute text.
  302. */
  303. $title = apply_filters( 'privacy_on_link_title', '' );
  304. /**
  305. * Filters the link label for the 'Search Engines Discouraged' message
  306. * displayed in the 'At a Glance' dashboard widget.
  307. *
  308. * Prior to 3.8.0, the widget was named 'Right Now'.
  309. *
  310. * @since 3.0.0
  311. *
  312. * @param string $content Default text.
  313. */
  314. $content = apply_filters( 'privacy_on_link_text', __( 'Search Engines Discouraged' ) );
  315. $title_attr = '' === $title ? '' : " title='$title'";
  316. echo "<p><a href='options-reading.php'$title_attr>$content</a></p>";
  317. }
  318. ?>
  319. </div>
  320. <?php
  321. /*
  322. * activity_box_end has a core action, but only prints content when multisite.
  323. * Using an output buffer is the only way to really check if anything's displayed here.
  324. */
  325. ob_start();
  326. /**
  327. * Fires at the end of the 'At a Glance' dashboard widget.
  328. *
  329. * Prior to 3.8.0, the widget was named 'Right Now'.
  330. *
  331. * @since 2.5.0
  332. */
  333. do_action( 'rightnow_end' );
  334. /**
  335. * Fires at the end of the 'At a Glance' dashboard widget.
  336. *
  337. * Prior to 3.8.0, the widget was named 'Right Now'.
  338. *
  339. * @since 2.0.0
  340. */
  341. do_action( 'activity_box_end' );
  342. $actions = ob_get_clean();
  343. if ( ! empty( $actions ) ) :
  344. ?>
  345. <div class="sub">
  346. <?php echo $actions; ?>
  347. </div>
  348. <?php
  349. endif;
  350. }
  351. /**
  352. * @since 3.1.0
  353. */
  354. function wp_network_dashboard_right_now() {
  355. $actions = array();
  356. if ( current_user_can( 'create_sites' ) ) {
  357. $actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>';
  358. }
  359. if ( current_user_can( 'create_users' ) ) {
  360. $actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>';
  361. }
  362. $c_users = get_user_count();
  363. $c_blogs = get_blog_count();
  364. /* translators: %s: Number of users on the network. */
  365. $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
  366. /* translators: %s: Number of sites on the network. */
  367. $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
  368. /* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network. */
  369. $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
  370. if ( $actions ) {
  371. echo '<ul class="subsubsub">';
  372. foreach ( $actions as $class => $action ) {
  373. $actions[ $class ] = "\t<li class='$class'>$action";
  374. }
  375. echo implode( " |</li>\n", $actions ) . "</li>\n";
  376. echo '</ul>';
  377. }
  378. ?>
  379. <br class="clear" />
  380. <p class="youhave"><?php echo $sentence; ?></p>
  381. <?php
  382. /**
  383. * Fires in the Network Admin 'Right Now' dashboard widget
  384. * just before the user and site search form fields.
  385. *
  386. * @since MU (3.0.0)
  387. */
  388. do_action( 'wpmuadminresult' );
  389. ?>
  390. <form action="<?php echo network_admin_url( 'users.php' ); ?>" method="get">
  391. <p>
  392. <label class="screen-reader-text" for="search-users"><?php _e( 'Search Users' ); ?></label>
  393. <input type="search" name="s" value="" size="30" autocomplete="off" id="search-users"/>
  394. <?php submit_button( __( 'Search Users' ), '', false, false, array( 'id' => 'submit_users' ) ); ?>
  395. </p>
  396. </form>
  397. <form action="<?php echo network_admin_url( 'sites.php' ); ?>" method="get">
  398. <p>
  399. <label class="screen-reader-text" for="search-sites"><?php _e( 'Search Sites' ); ?></label>
  400. <input type="search" name="s" value="" size="30" autocomplete="off" id="search-sites"/>
  401. <?php submit_button( __( 'Search Sites' ), '', false, false, array( 'id' => 'submit_sites' ) ); ?>
  402. </p>
  403. </form>
  404. <?php
  405. /**
  406. * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
  407. *
  408. * @since MU (3.0.0)
  409. */
  410. do_action( 'mu_rightnow_end' );
  411. /**
  412. * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
  413. *
  414. * @since MU (3.0.0)
  415. */
  416. do_action( 'mu_activity_box_end' );
  417. }
  418. /**
  419. * The Quick Draft widget display and creation of drafts.
  420. *
  421. * @since 3.8.0
  422. *
  423. * @global int $post_ID
  424. *
  425. * @param string $error_msg Optional. Error message. Default false.
  426. */
  427. function wp_dashboard_quick_press( $error_msg = false ) {
  428. global $post_ID;
  429. if ( ! current_user_can( 'edit_posts' ) ) {
  430. return;
  431. }
  432. /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
  433. $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
  434. if ( $last_post_id ) {
  435. $post = get_post( $last_post_id );
  436. if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
  437. $post = get_default_post_to_edit( 'post', true );
  438. update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
  439. } else {
  440. $post->post_title = ''; // Remove the auto draft title
  441. }
  442. } else {
  443. $post = get_default_post_to_edit( 'post', true );
  444. $user_id = get_current_user_id();
  445. // Don't create an option if this is a super admin who does not belong to this site.
  446. if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) {
  447. update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
  448. }
  449. }
  450. $post_ID = (int) $post->ID;
  451. ?>
  452. <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
  453. <?php if ( $error_msg ) : ?>
  454. <div class="error"><?php echo $error_msg; ?></div>
  455. <?php endif; ?>
  456. <div class="input-text-wrap" id="title-wrap">
  457. <label for="title">
  458. <?php
  459. /** This filter is documented in wp-admin/edit-form-advanced.php */
  460. echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
  461. ?>
  462. </label>
  463. <input type="text" name="post_title" id="title" autocomplete="off" />
  464. </div>
  465. <div class="textarea-wrap" id="description-wrap">
  466. <label for="content"><?php _e( 'Content' ); ?></label>
  467. <textarea name="content" id="content" placeholder="<?php esc_attr_e( 'What&#8217;s on your mind?' ); ?>" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea>
  468. </div>
  469. <p class="submit">
  470. <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
  471. <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
  472. <input type="hidden" name="post_type" value="post" />
  473. <?php wp_nonce_field( 'add-post' ); ?>
  474. <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
  475. <br class="clear" />
  476. </p>
  477. </form>
  478. <?php
  479. wp_dashboard_recent_drafts();
  480. }
  481. /**
  482. * Show recent drafts of the user on the dashboard.
  483. *
  484. * @since 2.7.0
  485. *
  486. * @param WP_Post[] $drafts Optional. Array of posts to display. Default false.
  487. */
  488. function wp_dashboard_recent_drafts( $drafts = false ) {
  489. if ( ! $drafts ) {
  490. $query_args = array(
  491. 'post_type' => 'post',
  492. 'post_status' => 'draft',
  493. 'author' => get_current_user_id(),
  494. 'posts_per_page' => 4,
  495. 'orderby' => 'modified',
  496. 'order' => 'DESC',
  497. );
  498. /**
  499. * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
  500. *
  501. * @since 4.4.0
  502. *
  503. * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
  504. */
  505. $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );
  506. $drafts = get_posts( $query_args );
  507. if ( ! $drafts ) {
  508. return;
  509. }
  510. }
  511. echo '<div class="drafts">';
  512. if ( count( $drafts ) > 3 ) {
  513. printf(
  514. '<p class="view-all"><a href="%s">%s</a></p>' . "\n",
  515. esc_url( admin_url( 'edit.php?post_status=draft' ) ),
  516. __( 'View all drafts' )
  517. );
  518. }
  519. echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>";
  520. /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
  521. $draft_length = intval( _x( '10', 'draft_length' ) );
  522. $drafts = array_slice( $drafts, 0, 3 );
  523. foreach ( $drafts as $draft ) {
  524. $url = get_edit_post_link( $draft->ID );
  525. $title = _draft_or_post_title( $draft->ID );
  526. echo "<li>\n";
  527. printf(
  528. '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
  529. esc_url( $url ),
  530. /* translators: %s: Post title. */
  531. esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
  532. esc_html( $title ),
  533. get_the_time( 'c', $draft ),
  534. get_the_time( __( 'F j, Y' ), $draft )
  535. );
  536. $the_content = wp_trim_words( $draft->post_content, $draft_length );
  537. if ( $the_content ) {
  538. echo '<p>' . $the_content . '</p>';
  539. }
  540. echo "</li>\n";
  541. }
  542. echo "</ul>\n</div>";
  543. }
  544. /**
  545. * Outputs a row for the Recent Comments widget.
  546. *
  547. * @access private
  548. * @since 2.7.0
  549. *
  550. * @global WP_Comment $comment Global comment object.
  551. *
  552. * @param WP_Comment $comment The current comment.
  553. * @param bool $show_date Optional. Whether to display the date.
  554. */
  555. function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
  556. $GLOBALS['comment'] = clone $comment;
  557. if ( $comment->comment_post_ID > 0 ) {
  558. $comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
  559. $comment_post_url = get_the_permalink( $comment->comment_post_ID );
  560. $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
  561. } else {
  562. $comment_post_link = '';
  563. }
  564. $actions_string = '';
  565. if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
  566. // Pre-order it: Approve | Reply | Edit | Spam | Trash.
  567. $actions = array(
  568. 'approve' => '',
  569. 'unapprove' => '',
  570. 'reply' => '',
  571. 'edit' => '',
  572. 'spam' => '',
  573. 'trash' => '',
  574. 'delete' => '',
  575. 'view' => '',
  576. );
  577. $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
  578. $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
  579. $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  580. $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  581. $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  582. $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  583. $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  584. $actions['approve'] = sprintf(
  585. '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
  586. $approve_url,
  587. "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
  588. esc_attr__( 'Approve this comment' ),
  589. __( 'Approve' )
  590. );
  591. $actions['unapprove'] = sprintf(
  592. '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
  593. $unapprove_url,
  594. "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
  595. esc_attr__( 'Unapprove this comment' ),
  596. __( 'Unapprove' )
  597. );
  598. $actions['edit'] = sprintf(
  599. '<a href="%s" aria-label="%s">%s</a>',
  600. "comment.php?action=editcomment&amp;c={$comment->comment_ID}",
  601. esc_attr__( 'Edit this comment' ),
  602. __( 'Edit' )
  603. );
  604. $actions['reply'] = sprintf(
  605. '<button type="button" onclick="window.commentReply && commentReply.open(\'%s\',\'%s\');" class="vim-r button-link hide-if-no-js" aria-label="%s">%s</button>',
  606. $comment->comment_ID,
  607. $comment->comment_post_ID,
  608. esc_attr__( 'Reply to this comment' ),
  609. __( 'Reply' )
  610. );
  611. $actions['spam'] = sprintf(
  612. '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
  613. $spam_url,
  614. "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
  615. esc_attr__( 'Mark this comment as spam' ),
  616. /* translators: "Mark as spam" link. */
  617. _x( 'Spam', 'verb' )
  618. );
  619. if ( ! EMPTY_TRASH_DAYS ) {
  620. $actions['delete'] = sprintf(
  621. '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
  622. $delete_url,
  623. "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
  624. esc_attr__( 'Delete this comment permanently' ),
  625. __( 'Delete Permanently' )
  626. );
  627. } else {
  628. $actions['trash'] = sprintf(
  629. '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
  630. $trash_url,
  631. "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
  632. esc_attr__( 'Move this comment to the Trash' ),
  633. _x( 'Trash', 'verb' )
  634. );
  635. }
  636. $actions['view'] = sprintf(
  637. '<a class="comment-link" href="%s" aria-label="%s">%s</a>',
  638. esc_url( get_comment_link( $comment ) ),
  639. esc_attr__( 'View this comment' ),
  640. __( 'View' )
  641. );
  642. /**
  643. * Filters the action links displayed for each comment in the 'Recent Comments'
  644. * dashboard widget.
  645. *
  646. * @since 2.6.0
  647. *
  648. * @param string[] $actions An array of comment actions. Default actions include:
  649. * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
  650. * 'Delete', and 'Trash'.
  651. * @param WP_Comment $comment The comment object.
  652. */
  653. $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
  654. $i = 0;
  655. foreach ( $actions as $action => $link ) {
  656. ++$i;
  657. ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  658. // Reply and quickedit need a hide-if-no-js span
  659. if ( 'reply' == $action || 'quickedit' == $action ) {
  660. $action .= ' hide-if-no-js';
  661. }
  662. if ( 'view' === $action && '1' !== $comment->comment_approved ) {
  663. $action .= ' hidden';
  664. }
  665. $actions_string .= "<span class='$action'>$sep$link</span>";
  666. }
  667. }
  668. ?>
  669. <li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>
  670. <?php echo get_avatar( $comment, 50, 'mystery' ); ?>
  671. <?php if ( ! $comment->comment_type || 'comment' == $comment->comment_type ) : ?>
  672. <div class="dashboard-comment-wrap has-row-actions">
  673. <p class="comment-meta">
  674. <?php
  675. // Comments might not have a post they relate to, e.g. programmatically created ones.
  676. if ( $comment_post_link ) {
  677. printf(
  678. /* translators: 1: Comment author, 2: Post link, 3: Notification if the comment is pending. */
  679. __( 'From %1$s on %2$s %3$s' ),
  680. '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
  681. $comment_post_link,
  682. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  683. );
  684. } else {
  685. printf(
  686. /* translators: 1: Comment author, 2: Notification if the comment is pending. */
  687. __( 'From %1$s %2$s' ),
  688. '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
  689. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  690. );
  691. }
  692. ?>
  693. </p>
  694. <?php
  695. else :
  696. switch ( $comment->comment_type ) {
  697. case 'pingback':
  698. $type = __( 'Pingback' );
  699. break;
  700. case 'trackback':
  701. $type = __( 'Trackback' );
  702. break;
  703. default:
  704. $type = ucwords( $comment->comment_type );
  705. }
  706. $type = esc_html( $type );
  707. ?>
  708. <div class="dashboard-comment-wrap has-row-actions">
  709. <p class="comment-meta">
  710. <?php
  711. // Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
  712. if ( $comment_post_link ) {
  713. printf(
  714. /* translators: 1: Type of comment, 2: Post link, 3: Notification if the comment is pending. */
  715. _x( '%1$s on %2$s %3$s', 'dashboard' ),
  716. "<strong>$type</strong>",
  717. $comment_post_link,
  718. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  719. );
  720. } else {
  721. printf(
  722. /* translators: 1: Type of comment, 2: Notification if the comment is pending. */
  723. _x( '%1$s %2$s', 'dashboard' ),
  724. "<strong>$type</strong>",
  725. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  726. );
  727. }
  728. ?>
  729. </p>
  730. <p class="comment-author"><?php comment_author_link( $comment ); ?></p>
  731. <?php endif; // comment_type ?>
  732. <blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote>
  733. <?php if ( $actions_string ) : ?>
  734. <p class="row-actions"><?php echo $actions_string; ?></p>
  735. <?php endif; ?>
  736. </div>
  737. </li>
  738. <?php
  739. $GLOBALS['comment'] = null;
  740. }
  741. /**
  742. * Callback function for Activity widget.
  743. *
  744. * @since 3.8.0
  745. */
  746. function wp_dashboard_site_activity() {
  747. echo '<div id="activity-widget">';
  748. $future_posts = wp_dashboard_recent_posts(
  749. array(
  750. 'max' => 5,
  751. 'status' => 'future',
  752. 'order' => 'ASC',
  753. 'title' => __( 'Publishing Soon' ),
  754. 'id' => 'future-posts',
  755. )
  756. );
  757. $recent_posts = wp_dashboard_recent_posts(
  758. array(
  759. 'max' => 5,
  760. 'status' => 'publish',
  761. 'order' => 'DESC',
  762. 'title' => __( 'Recently Published' ),
  763. 'id' => 'published-posts',
  764. )
  765. );
  766. $recent_comments = wp_dashboard_recent_comments();
  767. if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
  768. echo '<div class="no-activity">';
  769. echo '<p class="smiley" aria-hidden="true"></p>';
  770. echo '<p>' . __( 'No activity yet!' ) . '</p>';
  771. echo '</div>';
  772. }
  773. echo '</div>';
  774. }
  775. /**
  776. * Generates Publishing Soon and Recently Published sections.
  777. *
  778. * @since 3.8.0
  779. *
  780. * @param array $args {
  781. * An array of query and display arguments.
  782. *
  783. * @type int $max Number of posts to display.
  784. * @type string $status Post status.
  785. * @type string $order Designates ascending ('ASC') or descending ('DESC') order.
  786. * @type string $title Section title.
  787. * @type string $id The container id.
  788. * }
  789. * @return bool False if no posts were found. True otherwise.
  790. */
  791. function wp_dashboard_recent_posts( $args ) {
  792. $query_args = array(
  793. 'post_type' => 'post',
  794. 'post_status' => $args['status'],
  795. 'orderby' => 'date',
  796. 'order' => $args['order'],
  797. 'posts_per_page' => intval( $args['max'] ),
  798. 'no_found_rows' => true,
  799. 'cache_results' => false,
  800. 'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
  801. );
  802. /**
  803. * Filters the query arguments used for the Recent Posts widget.
  804. *
  805. * @since 4.2.0
  806. *
  807. * @param array $query_args The arguments passed to WP_Query to produce the list of posts.
  808. */
  809. $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args );
  810. $posts = new WP_Query( $query_args );
  811. if ( $posts->have_posts() ) {
  812. echo '<div id="' . $args['id'] . '" class="activity-block">';
  813. echo '<h3>' . $args['title'] . '</h3>';
  814. echo '<ul>';
  815. $today = current_time( 'Y-m-d' );
  816. $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
  817. $year = current_time( 'Y' );
  818. while ( $posts->have_posts() ) {
  819. $posts->the_post();
  820. $time = get_the_time( 'U' );
  821. if ( gmdate( 'Y-m-d', $time ) == $today ) {
  822. $relative = __( 'Today' );
  823. } elseif ( gmdate( 'Y-m-d', $time ) == $tomorrow ) {
  824. $relative = __( 'Tomorrow' );
  825. } elseif ( gmdate( 'Y', $time ) !== $year ) {
  826. /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://secure.php.net/date */
  827. $relative = date_i18n( __( 'M jS Y' ), $time );
  828. } else {
  829. /* translators: Date and time format for recent posts on the dashboard, see https://secure.php.net/date */
  830. $relative = date_i18n( __( 'M jS' ), $time );
  831. }
  832. // Use the post edit link for those who can edit, the permalink otherwise.
  833. $recent_post_link = current_user_can( 'edit_post', get_the_ID() ) ? get_edit_post_link() : get_permalink();
  834. $draft_or_post_title = _draft_or_post_title();
  835. printf(
  836. '<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
  837. /* translators: 1: Relative date, 2: Time. */
  838. sprintf( _x( '%1$s, %2$s', 'dashboard' ), $relative, get_the_time() ),
  839. $recent_post_link,
  840. /* translators: %s: Post title. */
  841. esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $draft_or_post_title ) ),
  842. $draft_or_post_title
  843. );
  844. }
  845. echo '</ul>';
  846. echo '</div>';
  847. } else {
  848. return false;
  849. }
  850. wp_reset_postdata();
  851. return true;
  852. }
  853. /**
  854. * Show Comments section.
  855. *
  856. * @since 3.8.0
  857. *
  858. * @param int $total_items Optional. Number of comments to query. Default 5.
  859. * @return bool False if no comments were found. True otherwise.
  860. */
  861. function wp_dashboard_recent_comments( $total_items = 5 ) {
  862. // Select all comment types and filter out spam later for better query performance.
  863. $comments = array();
  864. $comments_query = array(
  865. 'number' => $total_items * 5,
  866. 'offset' => 0,
  867. );
  868. if ( ! current_user_can( 'edit_posts' ) ) {
  869. $comments_query['status'] = 'approve';
  870. }
  871. while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
  872. if ( ! is_array( $possible ) ) {
  873. break;
  874. }
  875. foreach ( $possible as $comment ) {
  876. if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
  877. continue;
  878. }
  879. $comments[] = $comment;
  880. if ( count( $comments ) == $total_items ) {
  881. break 2;
  882. }
  883. }
  884. $comments_query['offset'] += $comments_query['number'];
  885. $comments_query['number'] = $total_items * 10;
  886. }
  887. if ( $comments ) {
  888. echo '<div id="latest-comments" class="activity-block">';
  889. echo '<h3>' . __( 'Recent Comments' ) . '</h3>';
  890. echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
  891. foreach ( $comments as $comment ) {
  892. _wp_dashboard_recent_comments_row( $comment );
  893. }
  894. echo '</ul>';
  895. if ( current_user_can( 'edit_posts' ) ) {
  896. echo '<h3 class="screen-reader-text">' . __( 'View more comments' ) . '</h3>';
  897. _get_list_table( 'WP_Comments_List_Table' )->views();
  898. }
  899. wp_comment_reply( -1, false, 'dashboard', false );
  900. wp_comment_trashnotice();
  901. echo '</div>';
  902. } else {
  903. return false;
  904. }
  905. return true;
  906. }
  907. /**
  908. * Display generic dashboard RSS widget feed.
  909. *
  910. * @since 2.5.0
  911. *
  912. * @param string $widget_id
  913. */
  914. function wp_dashboard_rss_output( $widget_id ) {
  915. $widgets = get_option( 'dashboard_widget_options' );
  916. echo '<div class="rss-widget">';
  917. wp_widget_rss_output( $widgets[ $widget_id ] );
  918. echo '</div>';
  919. }
  920. /**
  921. * Checks to see if all of the feed url in $check_urls are cached.
  922. *
  923. * If $check_urls is empty, look for the rss feed url found in the dashboard
  924. * widget options of $widget_id. If cached, call $callback, a function that
  925. * echoes out output for this widget. If not cache, echo a "Loading..." stub
  926. * which is later replaced by Ajax call (see top of /wp-admin/index.php)
  927. *
  928. * @since 2.5.0
  929. * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
  930. * by adding it to the function signature.
  931. *
  932. * @param string $widget_id The widget ID.
  933. * @param callable $callback The callback funtion used to display each feed.
  934. * @param array $check_urls RSS feeds
  935. * @param mixed ...$args Optional additional parameters to pass to the callback function when it's called.
  936. * @return bool False on failure. True on success.
  937. */
  938. function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
  939. $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p><div class="hide-if-js notice notice-error inline"><p>' . __( 'This widget requires JavaScript.' ) . '</p></div>';
  940. $doing_ajax = wp_doing_ajax();
  941. if ( empty( $check_urls ) ) {
  942. $widgets = get_option( 'dashboard_widget_options' );
  943. if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
  944. echo $loading;
  945. return false;
  946. }
  947. $check_urls = array( $widgets[ $widget_id ]['url'] );
  948. }
  949. $locale = get_user_locale();
  950. $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
  951. $output = get_transient( $cache_key );
  952. if ( false !== $output ) {
  953. echo $output;
  954. return true;
  955. }
  956. if ( ! $doing_ajax ) {
  957. echo $loading;
  958. return false;
  959. }
  960. if ( $callback && is_callable( $callback ) ) {
  961. array_unshift( $args, $widget_id, $check_urls );
  962. ob_start();
  963. call_user_func_array( $callback, $args );
  964. set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
  965. }
  966. return true;
  967. }
  968. //
  969. // Dashboard Widgets Controls
  970. //
  971. /**
  972. * Calls widget control callback.
  973. *
  974. * @since 2.5.0
  975. *
  976. * @global array $wp_dashboard_control_callbacks
  977. *
  978. * @param int $widget_control_id Registered Widget ID.
  979. */
  980. function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
  981. global $wp_dashboard_control_callbacks;
  982. 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 ] ) ) {
  983. call_user_func(
  984. $wp_dashboard_control_callbacks[ $widget_control_id ],
  985. '',
  986. array(
  987. 'id' => $widget_control_id,
  988. 'callback' => $wp_dashboard_control_callbacks[ $widget_control_id ],
  989. )
  990. );
  991. }
  992. }
  993. /**
  994. * The RSS dashboard widget control.
  995. *
  996. * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
  997. * from RSS-type widgets.
  998. *
  999. * @since 2.5.0
  1000. *
  1001. * @param string $widget_id
  1002. * @param array $form_inputs
  1003. */
  1004. function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
  1005. $widget_options = get_option( 'dashboard_widget_options' );
  1006. if ( ! $widget_options ) {
  1007. $widget_options = array();
  1008. }
  1009. if ( ! isset( $widget_options[ $widget_id ] ) ) {
  1010. $widget_options[ $widget_id ] = array();
  1011. }
  1012. $number = 1; // Hack to use wp_widget_rss_form()
  1013. $widget_options[ $widget_id ]['number'] = $number;
  1014. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
  1015. $_POST['widget-rss'][ $number ] = wp_unslash( $_POST['widget-rss'][ $number ] );
  1016. $widget_options[ $widget_id ] = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
  1017. $widget_options[ $widget_id ]['number'] = $number;
  1018. // Title is optional. If black, fill it if possible.
  1019. if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
  1020. $rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
  1021. if ( is_wp_error( $rss ) ) {
  1022. $widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
  1023. } else {
  1024. $widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
  1025. $rss->__destruct();
  1026. unset( $rss );
  1027. }
  1028. }
  1029. update_option( 'dashboard_widget_options', $widget_options );
  1030. $locale = get_user_locale();
  1031. $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
  1032. delete_transient( $cache_key );
  1033. }
  1034. wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
  1035. }
  1036. /**
  1037. * Renders the Events and News dashboard widget.
  1038. *
  1039. * @since 4.8.0
  1040. */
  1041. function wp_dashboard_events_news() {
  1042. wp_print_community_events_markup();
  1043. ?>
  1044. <div class="wordpress-news hide-if-no-js">
  1045. <?php wp_dashboard_primary(); ?>
  1046. </div>
  1047. <p class="community-events-footer">
  1048. <?php
  1049. printf(
  1050. '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
  1051. 'https://make.wordpress.org/community/meetups-landing-page',
  1052. __( 'Meetups' ),
  1053. /* translators: Accessibility text. */
  1054. __( '(opens in a new tab)' )
  1055. );
  1056. ?>
  1057. |
  1058. <?php
  1059. printf(
  1060. '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
  1061. 'https://central.wordcamp.org/schedule/',
  1062. __( 'WordCamps' ),
  1063. /* translators: Accessibility text. */
  1064. __( '(opens in a new tab)' )
  1065. );
  1066. ?>
  1067. |
  1068. <?php
  1069. printf(
  1070. '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
  1071. /* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */
  1072. esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ),
  1073. __( 'News' ),
  1074. /* translators: Accessibility text. */
  1075. __( '(opens in a new tab)' )
  1076. );
  1077. ?>
  1078. </p>
  1079. <?php
  1080. }
  1081. /**
  1082. * Prints the markup for the Community Events section of the Events and News Dashboard widget.
  1083. *
  1084. * @since 4.8.0
  1085. */
  1086. function wp_print_community_events_markup() {
  1087. ?>
  1088. <div class="community-events-errors notice notice-error inline hide-if-js">
  1089. <p class="hide-if-js">
  1090. <?php _e( 'This widget requires JavaScript.' ); ?>
  1091. </p>
  1092. <p class="community-events-error-occurred" aria-hidden="true">
  1093. <?php _e( 'An error occurred. Please try again.' ); ?>
  1094. </p>
  1095. <p class="community-events-could-not-locate" aria-hidden="true"></p>
  1096. </div>
  1097. <div class="community-events-loading hide-if-no-js">
  1098. <?php _e( 'Loading&hellip;' ); ?>
  1099. </div>
  1100. <?php
  1101. /*
  1102. * Hide the main element when the page first loads, because the content
  1103. * won't be ready until wp.communityEvents.renderEventsTemplate() has run.
  1104. */
  1105. ?>
  1106. <div id="community-events" class="community-events" aria-hidden="true">
  1107. <div class="activity-block">
  1108. <p>
  1109. <span id="community-events-location-message"></span>
  1110. <button class="button-link community-events-toggle-location" aria-label="<?php esc_attr_e( 'Edit city' ); ?>" aria-expanded="false">
  1111. <span class="dashicons dashicons-edit"></span>
  1112. </button>
  1113. </p>
  1114. <form class="community-events-form" aria-hidden="true" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
  1115. <label for="community-events-location">
  1116. <?php _e( 'City:' ); ?>
  1117. </label>
  1118. <?php
  1119. /* translators: Replace with a city related to your locale.
  1120. * Test that it matches the expected location and has upcoming
  1121. * events before including it. If no cities related to your
  1122. * locale have events, then use a city related to your locale
  1123. * that would be recognizable to most users. Use only the city
  1124. * name itself, without any region or country. Use the endonym
  1125. * (native locale name) instead of the English name if possible.
  1126. */
  1127. ?>
  1128. <input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />
  1129. <?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?>
  1130. <button class="community-events-cancel button-link" type="button" aria-expanded="false">
  1131. <?php _e( 'Cancel' ); ?>
  1132. </button>
  1133. <span class="spinner"></span>
  1134. </form>
  1135. </div>
  1136. <ul class="community-events-results activity-block last"></ul>
  1137. </div>
  1138. <?php
  1139. }
  1140. /**
  1141. * Renders the events templates for the Event and News widget.
  1142. *
  1143. * @since 4.8.0
  1144. */
  1145. function wp_print_community_events_templates() {
  1146. ?>
  1147. <script id="tmpl-community-events-attend-event-near" type="text/template">
  1148. <?php
  1149. printf(
  1150. /* translators: %s: The name of a city. */
  1151. __( 'Attend an upcoming event near %s.' ),
  1152. '<strong>{{ data.location.description }}</strong>'
  1153. );
  1154. ?>
  1155. </script>
  1156. <script id="tmpl-community-events-could-not-locate" type="text/template">
  1157. <?php
  1158. printf(
  1159. /* translators: %s is the name of the city we couldn't locate.
  1160. * Replace the examples with cities in your locale, but test
  1161. * that they match the expected location before including them.
  1162. * Use endonyms (native locale names) whenever possible.
  1163. */
  1164. __( 'We couldn&#8217;t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
  1165. '<em>{{data.unknownCity}}</em>'
  1166. );
  1167. ?>
  1168. </script>
  1169. <script id="tmpl-community-events-event-list" type="text/template">
  1170. <# _.each( data.events, function( event ) { #>
  1171. <li class="event event-{{ event.type }} wp-clearfix">
  1172. <div class="event-info">
  1173. <div class="dashicons event-icon" aria-hidden="true"></div>
  1174. <div class="event-info-inner">
  1175. <a class="event-title" href="{{ event.url }}">{{ event.title }}</a>
  1176. <span class="event-city">{{ event.location.location }}</span>
  1177. </div>
  1178. </div>
  1179. <div class="event-date-time">
  1180. <span class="event-date">{{ event.formatted_date }}</span>
  1181. <# if ( 'meetup' === event.type ) { #>
  1182. <span class="event-time">{{ event.formatted_time }}</span>
  1183. <# } #>
  1184. </div>
  1185. </li>
  1186. <# } ) #>
  1187. </script>
  1188. <script id="tmpl-community-events-no-upcoming-events" type="text/template">
  1189. <li class="event-none">
  1190. <# if ( data.location.description ) { #>
  1191. <?php
  1192. printf(
  1193. /* translators: 1: The city the user searched for, 2: Meetup organization documentation URL. */
  1194. __( 'There aren&#8217;t any events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize one</a>?' ),
  1195. '{{ data.location.description }}',
  1196. __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
  1197. );
  1198. ?>
  1199. <# } else { #>
  1200. <?php
  1201. printf(
  1202. /* translators: %s: Meetup organization documentation URL. */
  1203. __( 'There aren&#8217;t any events scheduled near you at the moment. Would you like to <a href="%s">organize one</a>?' ),
  1204. __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
  1205. );
  1206. ?>
  1207. <# } #>
  1208. </li>
  1209. </script>
  1210. <?php
  1211. }
  1212. /**
  1213. * 'WordPress Events and News' dashboard widget.
  1214. *
  1215. * @since 2.7.0
  1216. * @since 4.8.0 Removed popular plugins feed.
  1217. */
  1218. function wp_dashboard_primary() {
  1219. $feeds = array(
  1220. 'news' => array(
  1221. /**
  1222. * Filters the primary link URL for the 'WordPress Events and News' dashboard widget.
  1223. *
  1224. * @since 2.5.0
  1225. *
  1226. * @param string $link The widget's primary link URL.
  1227. */
  1228. 'link' => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ),
  1229. /**
  1230. * Filters the primary feed URL for the 'WordPress Events and News' dashboard widget.
  1231. *
  1232. * @since 2.3.0
  1233. *
  1234. * @param string $url The widget's primary feed URL.
  1235. */
  1236. 'url' => apply_filters( 'dashboard_primary_feed', __( 'https://wordpress.org/news/feed/' ) ),
  1237. /**
  1238. * Filters the primary link title for the 'WordPress Events and News' dashboard widget.
  1239. *
  1240. * @since 2.3.0
  1241. *
  1242. * @param string $title Title attribute for the widget's primary link.
  1243. */
  1244. 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
  1245. 'items' => 1,
  1246. 'show_summary' => 0,
  1247. 'show_author' => 0,
  1248. 'show_date' => 0,
  1249. ),
  1250. 'planet' => array(
  1251. /**
  1252. * Filters the secondary link URL for the 'WordPress Events and News' dashboard widget.
  1253. *
  1254. * @since 2.3.0
  1255. *
  1256. * @param string $link The widget's secondary link URL.
  1257. */
  1258. 'link' => apply_filters( 'dashboard_secondary_link', __( 'https://planet.wordpress.org/' ) ),
  1259. /**
  1260. * Filters the secondary feed URL for the 'WordPress Events and News' dashboard widget.
  1261. *
  1262. * @since 2.3.0
  1263. *
  1264. * @param string $url The widget's secondary feed URL.
  1265. */
  1266. 'url' => apply_filters( 'dashboard_secondary_feed', __( 'https://planet.wordpress.org/feed/' ) ),
  1267. /**
  1268. * Filters the secondary link title for the 'WordPress Events and News' dashboard widget.
  1269. *
  1270. * @since 2.3.0
  1271. *
  1272. * @param string $title Title attribute for the widget's secondary link.
  1273. */
  1274. 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
  1275. /**
  1276. * Filters the number of secondary link items for the 'WordPress Events and News' dashboard widget.
  1277. *
  1278. * @since 4.4.0
  1279. *
  1280. * @param string $items How many items to show in the secondary feed.
  1281. */
  1282. 'items' => apply_filters( 'dashboard_secondary_items', 3 ),
  1283. 'show_summary' => 0,
  1284. 'show_author' => 0,
  1285. 'show_date' => 0,
  1286. ),
  1287. );
  1288. wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
  1289. }
  1290. /**
  1291. * Display the WordPress events and news feeds.
  1292. *
  1293. * @since 3.8.0
  1294. * @since 4.8.0 Removed popular plugins feed.
  1295. *
  1296. * @param string $widget_id Widget ID.
  1297. * @param array $feeds Array of RSS feeds.
  1298. */
  1299. function wp_dashboard_primary_output( $widget_id, $feeds ) {
  1300. foreach ( $feeds as $type => $args ) {
  1301. $args['type'] = $type;
  1302. echo '<div class="rss-widget">';
  1303. wp_widget_rss_output( $args['url'], $args );
  1304. echo '</div>';
  1305. }
  1306. }
  1307. /**
  1308. * Display file upload quota on dashboard.
  1309. *
  1310. * Runs on the {@see 'activity_box_end'} hook in wp_dashboard_right_now().
  1311. *
  1312. * @since 3.0.0
  1313. *
  1314. * @return bool|null True if not multisite, user can't upload files, or the space check option is disabled.
  1315. */
  1316. function wp_dashboard_quota() {
  1317. if ( ! is_multisite() || ! current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) {
  1318. return true;
  1319. }
  1320. $quota = get_space_allowed();
  1321. $used = get_space_used();
  1322. if ( $used > $quota ) {
  1323. $percentused = '100';
  1324. } else {
  1325. $percentused = ( $used / $quota ) * 100;
  1326. }
  1327. $used_class = ( $percentused >= 70 ) ? ' warning' : '';
  1328. $used = round( $used, 2 );
  1329. $percentused = number_format( $percentused );
  1330. ?>
  1331. <h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3>
  1332. <div class="mu-storage">
  1333. <ul>
  1334. <li class="storage-count">
  1335. <?php
  1336. $text = sprintf(
  1337. /* translators: %s: Number of megabytes. */
  1338. __( '%s MB Space Allowed' ),
  1339. number_format_i18n( $quota )
  1340. );
  1341. printf(
  1342. '<a href="%1$s">%2$s <span class="screen-reader-text">(%3$s)</span></a>',
  1343. esc_url( admin_url( 'upload.php' ) ),
  1344. $text,
  1345. __( 'Manage Uploads' )
  1346. );
  1347. ?>
  1348. </li><li class="storage-count <?php echo $used_class; ?>">
  1349. <?php
  1350. $text = sprintf(
  1351. /* translators: 1: Number of megabytes, 2: Percentage. */
  1352. __( '%1$s MB (%2$s%%) Space Used' ),
  1353. number_format_i18n( $used, 2 ),
  1354. $percentused
  1355. );
  1356. printf(
  1357. '<a href="%1$s" class="musublink">%2$s <span class="screen-reader-text">(%3$s)</span></a>',
  1358. esc_url( admin_url( 'upload.php' ) ),
  1359. $text,
  1360. __( 'Manage Uploads' )
  1361. );
  1362. ?>
  1363. </li>
  1364. </ul>
  1365. </div>
  1366. <?php
  1367. }
  1368. // Display Browser Nag Meta Box
  1369. function wp_dashboard_browser_nag() {
  1370. $notice = '';
  1371. $response = wp_check_browser_version();
  1372. if ( $response ) {
  1373. if ( $response['insecure'] ) {
  1374. $msg = sprintf(
  1375. /* translators: %s: Browser name and link. */
  1376. __( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ),
  1377. sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
  1378. );
  1379. } else {
  1380. $msg = sprintf(
  1381. /* translators: %s: Browser name and link. */
  1382. __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ),
  1383. sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
  1384. );
  1385. }
  1386. $browser_nag_class = '';
  1387. if ( ! empty( $response['img_src'] ) ) {
  1388. $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) ) ? $response['img_src_ssl'] : $response['img_src'];
  1389. $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr( $response['update_url'] ) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
  1390. $browser_nag_class = ' has-browser-icon';
  1391. }
  1392. $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
  1393. $browsehappy = 'https://browsehappy.com/';
  1394. $locale = get_user_locale();
  1395. if ( 'en_US' !== $locale ) {
  1396. $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
  1397. }
  1398. $notice .= '<p>' . sprintf(
  1399. /* translators: 1: Browser update URL, 2: Browser name, 3: Browse Happy URL. */
  1400. __( '<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>' ),
  1401. esc_attr( $response['update_url'] ),
  1402. esc_html( $response['name'] ),
  1403. esc_url( $browsehappy )
  1404. ) . '</p>';
  1405. $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss" aria-label="' . esc_attr__( 'Dismiss the browser warning panel' ) . '">' . __( 'Dismiss' ) . '</a></p>';
  1406. $notice .= '<div class="clear"></div>';
  1407. }
  1408. /**
  1409. * Filters the notice output for the 'Browse Happy' nag meta box.
  1410. *
  1411. * @since 3.2.0
  1412. *
  1413. * @param string $notice The notice content.
  1414. * @param array $response An array containing web browser information. See `wp_check_browser_version()`.
  1415. */
  1416. echo apply_filters( 'browse-happy-notice', $notice, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  1417. }
  1418. /**
  1419. * @since 3.2.0
  1420. *
  1421. * @param array $classes
  1422. * @return array
  1423. */
  1424. function dashboard_browser_nag_class( $classes ) {
  1425. $response = wp_check_browser_version();
  1426. if ( $response && $response['insecure'] ) {
  1427. $classes[] = 'browser-insecure';
  1428. }
  1429. return $classes;
  1430. }
  1431. /**
  1432. * Check if the user needs a browser update
  1433. *
  1434. * @since 3.2.0
  1435. *
  1436. * @return array|bool False on failure, array of browser data on success.
  1437. */
  1438. function wp_check_browser_version() {
  1439. if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
  1440. return false;
  1441. }
  1442. $key = md5( $_SERVER['HTTP_USER_AGENT'] );
  1443. $response = get_site_transient( 'browser_' . $key );
  1444. if ( false === $response ) {
  1445. // include an unmodified $wp_version
  1446. include( ABSPATH . WPINC . '/version.php' );
  1447. $url = 'http://api.wordpress.org/core/browse-happy/1.1/';
  1448. $options = array(
  1449. 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
  1450. 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
  1451. );
  1452. if ( wp_http_supports( array( 'ssl' ) ) ) {
  1453. $url = set_url_scheme( $url, 'https' );
  1454. }
  1455. $response = wp_remote_post( $url, $options );
  1456. if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
  1457. return false;
  1458. }
  1459. /**
  1460. * Response should be an array with:
  1461. * 'platform' - string - A user-friendly platform name, if it can be determined
  1462. * 'name' - string - A user-friendly browser name
  1463. * 'version' - string - The version of the browser the user is using
  1464. * 'current_version' - string - The most recent version of the browser
  1465. * 'upgrade' - boolean - Whether the browser needs an upgrade
  1466. * 'insecure' - boolean - Whether the browser is deemed insecure
  1467. * 'update_url' - string - The url to visit to upgrade
  1468. * 'img_src' - string - An image representing the browser
  1469. * 'img_src_ssl' - string - An image (over SSL) representing the browser
  1470. */
  1471. $response = json_decode( wp_remote_retrieve_body( $response ), true );
  1472. if ( ! is_array( $response ) ) {
  1473. return false;
  1474. }
  1475. set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
  1476. }
  1477. return $response;
  1478. }
  1479. /**
  1480. * Displays the PHP update nag.
  1481. *
  1482. * @since 5.1.0
  1483. */
  1484. function wp_dashboard_php_nag() {
  1485. $response = wp_check_php_version();
  1486. if ( ! $response ) {
  1487. return;
  1488. }
  1489. if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
  1490. $msg = __( 'WordPress has detected that your site is running on an insecure version of PHP.' );
  1491. } else {
  1492. $msg = __( 'WordPress has detected that your site is running on an outdated version of PHP.' );
  1493. }
  1494. ?>
  1495. <p><?php echo $msg; ?></p>
  1496. <h3><?php _e( 'What is PHP and how does it affect my site?' ); ?></h3>
  1497. <p><?php _e( 'PHP is the programming language we use to build and maintain WordPress. Newer versions of PHP are both faster and more secure, so updating will have a positive effect on your site&#8217;s performance.' ); ?></p>
  1498. <p class="button-container">
  1499. <?php
  1500. printf(
  1501. '<a class="button button-primary" href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
  1502. esc_url( wp_get_update_php_url() ),
  1503. __( 'Learn more about updating PHP' ),
  1504. /* translators: Accessibility text. */
  1505. __( '(opens in a new tab)' )
  1506. );
  1507. ?>
  1508. </p>
  1509. <?php
  1510. wp_update_php_annotation();
  1511. wp_direct_php_update_button();
  1512. }
  1513. /**
  1514. * Adds an additional class to the PHP nag if the current version is insecure.
  1515. *
  1516. * @since 5.1.0
  1517. *
  1518. * @param array $classes Metabox classes.
  1519. * @return array Modified metabox classes.
  1520. */
  1521. function dashboard_php_nag_class( $classes ) {
  1522. $response = wp_check_php_version();
  1523. if ( $response && isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
  1524. $classes[] = 'php-insecure';
  1525. }
  1526. return $classes;
  1527. }
  1528. /**
  1529. * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
  1530. */
  1531. function wp_dashboard_empty() {}
  1532. /**
  1533. * Displays a welcome panel to introduce users to WordPress.
  1534. *
  1535. * @since 3.3.0
  1536. */
  1537. function wp_welcome_panel() {
  1538. ?>
  1539. <div class="welcome-panel-content">
  1540. <h2><?php _e( 'Welcome to WordPress!' ); ?></h2>
  1541. <p class="about-description"><?php _e( 'We&#8217;ve assembled some links to get you started:' ); ?></p>
  1542. <div class="welcome-panel-column-container">
  1543. <div class="welcome-panel-column">
  1544. <?php if ( current_user_can( 'customize' ) ) : ?>
  1545. <h3><?php _e( 'Get Started' ); ?></h3>
  1546. <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>
  1547. <?php endif; ?>
  1548. <a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
  1549. <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
  1550. <?php $themes_link = current_user_can( 'customize' ) ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
  1551. <p class="hide-if-no-customize">
  1552. <?php
  1553. /* translators: %s: URL to Themes panel in Customizer or Themes screen. */
  1554. printf( __( 'or, <a href="%s">change your theme completely</a>' ), $themes_link );
  1555. ?>
  1556. </p>
  1557. <?php endif; ?>
  1558. </div>
  1559. <div class="welcome-panel-column">
  1560. <h3><?php _e( 'Next Steps' ); ?></h3>
  1561. <ul>
  1562. <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
  1563. <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>
  1564. <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>
  1565. <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
  1566. <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>
  1567. <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>
  1568. <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
  1569. <?php else : ?>
  1570. <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
  1571. <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>
  1572. <li><?php printf( '<a href="%s" class="welcome-icon welcome-setup-home">' . __( 'Set up your homepage' ) . '</a>', current_user_can( 'customize' ) ? add_query_arg( 'autofocus[section]', 'static_front_page', admin_url( 'customize.php' ) ) : admin_url( 'options-reading.php' ) ); ?></li>
  1573. <?php endif; ?>
  1574. <li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
  1575. </ul>
  1576. </div>
  1577. <div class="welcome-panel-column welcome-panel-last">
  1578. <h3><?php _e( 'More Actions' ); ?></h3>
  1579. <ul>
  1580. <?php
  1581. if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) :
  1582. if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
  1583. $widgets_menus_link = sprintf(
  1584. /* translators: 1: URL to Widgets screen, 2: URL to Menus screen. */
  1585. __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
  1586. admin_url( 'widgets.php' ),
  1587. admin_url( 'nav-menus.php' )
  1588. );
  1589. } elseif ( current_theme_supports( 'widgets' ) ) {
  1590. $widgets_menus_link = '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
  1591. } else {
  1592. $widgets_menus_link = '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
  1593. }
  1594. ?>
  1595. <li><div class="welcome-icon welcome-widgets-menus"><?php echo $widgets_menus_link; ?></div></li>
  1596. <?php endif; ?>
  1597. <?php if ( current_user_can( 'manage_options' ) ) : ?>
  1598. <li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
  1599. <?php endif; ?>
  1600. <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'https://wordpress.org/support/article/first-steps-with-wordpress-b/' ) ); ?></li>
  1601. </ul>
  1602. </div>
  1603. </div>
  1604. </div>
  1605. <?php
  1606. }