dashboard.php 62 KB

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