update.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. <?php
  2. /**
  3. * WordPress Administration Update API
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /**
  9. * Selects the first update version from the update_core option.
  10. *
  11. * @return object|array|false The response from the API on success, false on failure.
  12. */
  13. function get_preferred_from_update_core() {
  14. $updates = get_core_updates();
  15. if ( ! is_array( $updates ) ) {
  16. return false;
  17. }
  18. if ( empty( $updates ) ) {
  19. return (object) array( 'response' => 'latest' );
  20. }
  21. return $updates[0];
  22. }
  23. /**
  24. * Get available core updates.
  25. *
  26. * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
  27. * set $options['available'] to false to skip not-dismissed updates.
  28. * @return array|false Array of the update objects on success, false on failure.
  29. */
  30. function get_core_updates( $options = array() ) {
  31. $options = array_merge(
  32. array(
  33. 'available' => true,
  34. 'dismissed' => false,
  35. ),
  36. $options
  37. );
  38. $dismissed = get_site_option( 'dismissed_update_core' );
  39. if ( ! is_array( $dismissed ) ) {
  40. $dismissed = array();
  41. }
  42. $from_api = get_site_transient( 'update_core' );
  43. if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
  44. return false;
  45. }
  46. $updates = $from_api->updates;
  47. $result = array();
  48. foreach ( $updates as $update ) {
  49. if ( $update->response == 'autoupdate' ) {
  50. continue;
  51. }
  52. if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
  53. if ( $options['dismissed'] ) {
  54. $update->dismissed = true;
  55. $result[] = $update;
  56. }
  57. } else {
  58. if ( $options['available'] ) {
  59. $update->dismissed = false;
  60. $result[] = $update;
  61. }
  62. }
  63. }
  64. return $result;
  65. }
  66. /**
  67. * Gets the best available (and enabled) Auto-Update for WordPress Core.
  68. *
  69. * If there's 1.2.3 and 1.3 on offer, it'll choose 1.3 if the installation allows it, else, 1.2.3
  70. *
  71. * @since 3.7.0
  72. *
  73. * @return array|false False on failure, otherwise the core update offering.
  74. */
  75. function find_core_auto_update() {
  76. $updates = get_site_transient( 'update_core' );
  77. if ( ! $updates || empty( $updates->updates ) ) {
  78. return false;
  79. }
  80. include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
  81. $auto_update = false;
  82. $upgrader = new WP_Automatic_Updater;
  83. foreach ( $updates->updates as $update ) {
  84. if ( 'autoupdate' != $update->response ) {
  85. continue;
  86. }
  87. if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
  88. continue;
  89. }
  90. if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
  91. $auto_update = $update;
  92. }
  93. }
  94. return $auto_update;
  95. }
  96. /**
  97. * Gets and caches the checksums for the given version of WordPress.
  98. *
  99. * @since 3.7.0
  100. *
  101. * @param string $version Version string to query.
  102. * @param string $locale Locale to query.
  103. * @return bool|array False on failure. An array of checksums on success.
  104. */
  105. function get_core_checksums( $version, $locale ) {
  106. $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
  107. $url = $http_url;
  108. $ssl = wp_http_supports( array( 'ssl' ) );
  109. if ( $ssl ) {
  110. $url = set_url_scheme( $url, 'https' );
  111. }
  112. $options = array(
  113. 'timeout' => wp_doing_cron() ? 30 : 3,
  114. );
  115. $response = wp_remote_get( $url, $options );
  116. if ( $ssl && is_wp_error( $response ) ) {
  117. trigger_error(
  118. sprintf(
  119. /* translators: %s: Support forums URL. */
  120. __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ),
  121. __( 'https://wordpress.org/support/forums/' )
  122. ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
  123. headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
  124. );
  125. $response = wp_remote_get( $http_url, $options );
  126. }
  127. if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
  128. return false;
  129. }
  130. $body = trim( wp_remote_retrieve_body( $response ) );
  131. $body = json_decode( $body, true );
  132. if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
  133. return false;
  134. }
  135. return $body['checksums'];
  136. }
  137. /**
  138. * @param object $update
  139. * @return bool
  140. */
  141. function dismiss_core_update( $update ) {
  142. $dismissed = get_site_option( 'dismissed_update_core' );
  143. $dismissed[ $update->current . '|' . $update->locale ] = true;
  144. return update_site_option( 'dismissed_update_core', $dismissed );
  145. }
  146. /**
  147. * @param string $version
  148. * @param string $locale
  149. * @return bool
  150. */
  151. function undismiss_core_update( $version, $locale ) {
  152. $dismissed = get_site_option( 'dismissed_update_core' );
  153. $key = $version . '|' . $locale;
  154. if ( ! isset( $dismissed[ $key ] ) ) {
  155. return false;
  156. }
  157. unset( $dismissed[ $key ] );
  158. return update_site_option( 'dismissed_update_core', $dismissed );
  159. }
  160. /**
  161. * @param string $version
  162. * @param string $locale
  163. * @return object|false
  164. */
  165. function find_core_update( $version, $locale ) {
  166. $from_api = get_site_transient( 'update_core' );
  167. if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
  168. return false;
  169. }
  170. $updates = $from_api->updates;
  171. foreach ( $updates as $update ) {
  172. if ( $update->current == $version && $update->locale == $locale ) {
  173. return $update;
  174. }
  175. }
  176. return false;
  177. }
  178. /**
  179. * @param string $msg
  180. * @return string
  181. */
  182. function core_update_footer( $msg = '' ) {
  183. if ( ! current_user_can( 'update_core' ) ) {
  184. /* translators: %s: WordPress version. */
  185. return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
  186. }
  187. $cur = get_preferred_from_update_core();
  188. if ( ! is_object( $cur ) ) {
  189. $cur = new stdClass;
  190. }
  191. if ( ! isset( $cur->current ) ) {
  192. $cur->current = '';
  193. }
  194. if ( ! isset( $cur->url ) ) {
  195. $cur->url = '';
  196. }
  197. if ( ! isset( $cur->response ) ) {
  198. $cur->response = '';
  199. }
  200. switch ( $cur->response ) {
  201. case 'development':
  202. return sprintf(
  203. /* translators: 1: WordPress version number, 2: URL to WordPress Updates screen. */
  204. __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ),
  205. get_bloginfo( 'version', 'display' ),
  206. network_admin_url( 'update-core.php' )
  207. );
  208. case 'upgrade':
  209. return sprintf(
  210. '<strong><a href="%s">%s</a></strong>',
  211. network_admin_url( 'update-core.php' ),
  212. /* translators: %s: WordPress version. */
  213. sprintf( __( 'Get Version %s' ), $cur->current )
  214. );
  215. case 'latest':
  216. default:
  217. /* translators: %s: WordPress version. */
  218. return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
  219. }
  220. }
  221. /**
  222. * @global string $pagenow
  223. * @return false|void
  224. */
  225. function update_nag() {
  226. if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
  227. return false;
  228. }
  229. global $pagenow;
  230. if ( 'update-core.php' == $pagenow ) {
  231. return;
  232. }
  233. $cur = get_preferred_from_update_core();
  234. if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) {
  235. return false;
  236. }
  237. $version_url = sprintf(
  238. /* translators: %s: WordPress version. */
  239. esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
  240. sanitize_title( $cur->current )
  241. );
  242. if ( current_user_can( 'update_core' ) ) {
  243. $msg = sprintf(
  244. /* translators: 1: URL to WordPress release notes, 2: New WordPress version, 3: URL to network admin, 4: Accessibility text. */
  245. __( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
  246. $version_url,
  247. $cur->current,
  248. network_admin_url( 'update-core.php' ),
  249. esc_attr__( 'Please update WordPress now' )
  250. );
  251. } else {
  252. $msg = sprintf(
  253. /* translators: 1: URL to WordPress release notes, 2: New WordPress version. */
  254. __( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
  255. $version_url,
  256. $cur->current
  257. );
  258. }
  259. echo "<div class='update-nag'>$msg</div>";
  260. }
  261. // Called directly from dashboard
  262. function update_right_now_message() {
  263. $theme_name = wp_get_theme();
  264. if ( current_user_can( 'switch_themes' ) ) {
  265. $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
  266. }
  267. $msg = '';
  268. if ( current_user_can( 'update_core' ) ) {
  269. $cur = get_preferred_from_update_core();
  270. if ( isset( $cur->response ) && $cur->response == 'upgrade' ) {
  271. $msg .= sprintf(
  272. '<a href="%s" class="button" aria-describedby="wp-version">%s</a> ',
  273. network_admin_url( 'update-core.php' ),
  274. /* translators: %s: WordPress version number, or 'Latest' string. */
  275. sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) )
  276. );
  277. }
  278. }
  279. /* translators: 1: Version number, 2: Theme name. */
  280. $content = __( 'WordPress %1$s running %2$s theme.' );
  281. /**
  282. * Filters the text displayed in the 'At a Glance' dashboard widget.
  283. *
  284. * Prior to 3.8.0, the widget was named 'Right Now'.
  285. *
  286. * @since 4.4.0
  287. *
  288. * @param string $content Default text.
  289. */
  290. $content = apply_filters( 'update_right_now_text', $content );
  291. $msg .= sprintf( '<span id="wp-version">' . $content . '</span>', get_bloginfo( 'version', 'display' ), $theme_name );
  292. echo "<p id='wp-version-message'>$msg</p>";
  293. }
  294. /**
  295. * @since 2.9.0
  296. *
  297. * @return array
  298. */
  299. function get_plugin_updates() {
  300. $all_plugins = get_plugins();
  301. $upgrade_plugins = array();
  302. $current = get_site_transient( 'update_plugins' );
  303. foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
  304. if ( isset( $current->response[ $plugin_file ] ) ) {
  305. $upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
  306. $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
  307. }
  308. }
  309. return $upgrade_plugins;
  310. }
  311. /**
  312. * @since 2.9.0
  313. */
  314. function wp_plugin_update_rows() {
  315. if ( ! current_user_can( 'update_plugins' ) ) {
  316. return;
  317. }
  318. $plugins = get_site_transient( 'update_plugins' );
  319. if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
  320. $plugins = array_keys( $plugins->response );
  321. foreach ( $plugins as $plugin_file ) {
  322. add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 );
  323. }
  324. }
  325. }
  326. /**
  327. * Displays update information for a plugin.
  328. *
  329. * @param string $file Plugin basename.
  330. * @param array $plugin_data Plugin information.
  331. * @return false|void
  332. */
  333. function wp_plugin_update_row( $file, $plugin_data ) {
  334. $current = get_site_transient( 'update_plugins' );
  335. if ( ! isset( $current->response[ $file ] ) ) {
  336. return false;
  337. }
  338. $response = $current->response[ $file ];
  339. $plugins_allowedtags = array(
  340. 'a' => array(
  341. 'href' => array(),
  342. 'title' => array(),
  343. ),
  344. 'abbr' => array( 'title' => array() ),
  345. 'acronym' => array( 'title' => array() ),
  346. 'code' => array(),
  347. 'em' => array(),
  348. 'strong' => array(),
  349. );
  350. $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
  351. $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
  352. /** @var WP_Plugins_List_Table $wp_list_table */
  353. $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
  354. if ( is_network_admin() || ! is_multisite() ) {
  355. if ( is_network_admin() ) {
  356. $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
  357. } else {
  358. $active_class = is_plugin_active( $file ) ? ' active' : '';
  359. }
  360. $requires_php = isset( $response->requires_php ) ? $response->requires_php : null;
  361. $compatible_php = is_php_version_compatible( $requires_php );
  362. $notice_type = $compatible_php ? 'notice-warning' : 'notice-error';
  363. printf(
  364. '<tr class="plugin-update-tr%s" id="%s" data-slug="%s" data-plugin="%s">' .
  365. '<td colspan="%s" class="plugin-update colspanchange">' .
  366. '<div class="update-message notice inline %s notice-alt"><p>',
  367. $active_class,
  368. esc_attr( $response->slug . '-update' ),
  369. esc_attr( $response->slug ),
  370. esc_attr( $file ),
  371. esc_attr( $wp_list_table->get_column_count() ),
  372. $notice_type
  373. );
  374. if ( ! current_user_can( 'update_plugins' ) ) {
  375. printf(
  376. /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
  377. __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
  378. $plugin_name,
  379. esc_url( $details_url ),
  380. sprintf(
  381. 'class="thickbox open-plugin-details-modal" aria-label="%s"',
  382. /* translators: 1: Plugin name, 2: Version number. */
  383. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
  384. ),
  385. esc_attr( $response->new_version )
  386. );
  387. } elseif ( empty( $response->package ) ) {
  388. printf(
  389. /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
  390. __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ),
  391. $plugin_name,
  392. esc_url( $details_url ),
  393. sprintf(
  394. 'class="thickbox open-plugin-details-modal" aria-label="%s"',
  395. /* translators: 1: Plugin name, 2: Version number. */
  396. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
  397. ),
  398. esc_attr( $response->new_version )
  399. );
  400. } else {
  401. if ( $compatible_php ) {
  402. printf(
  403. /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
  404. __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
  405. $plugin_name,
  406. esc_url( $details_url ),
  407. sprintf(
  408. 'class="thickbox open-plugin-details-modal" aria-label="%s"',
  409. /* translators: 1: Plugin name, 2: Version number. */
  410. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
  411. ),
  412. esc_attr( $response->new_version ),
  413. wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
  414. sprintf(
  415. 'class="update-link" aria-label="%s"',
  416. /* translators: %s: Plugin name. */
  417. esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
  418. )
  419. );
  420. } else {
  421. printf(
  422. /* translators: 1: Plugin name, 2: Details URL, 3: Additional link attributes, 4: Version number 5: URL to Update PHP page. */
  423. __( 'There is a new version of %1$s available, but it doesn&#8217;t work with your version of PHP. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s">learn more about updating PHP</a>.' ),
  424. $plugin_name,
  425. esc_url( $details_url ),
  426. sprintf(
  427. 'class="thickbox open-plugin-details-modal" aria-label="%s"',
  428. /* translators: 1: Plugin name, 2: Version number. */
  429. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
  430. ),
  431. esc_attr( $response->new_version ),
  432. esc_url( wp_get_update_php_url() )
  433. );
  434. wp_update_php_annotation( '<br><em>', '</em>' );
  435. }
  436. }
  437. /**
  438. * Fires at the end of the update message container in each
  439. * row of the plugins list table.
  440. *
  441. * The dynamic portion of the hook name, `$file`, refers to the path
  442. * of the plugin's primary file relative to the plugins directory.
  443. *
  444. * @since 2.8.0
  445. *
  446. * @param array $plugin_data {
  447. * An array of plugin metadata.
  448. *
  449. * @type string $name The human-readable name of the plugin.
  450. * @type string $plugin_uri Plugin URI.
  451. * @type string $version Plugin version.
  452. * @type string $description Plugin description.
  453. * @type string $author Plugin author.
  454. * @type string $author_uri Plugin author URI.
  455. * @type string $text_domain Plugin text domain.
  456. * @type string $domain_path Relative path to the plugin's .mo file(s).
  457. * @type bool $network Whether the plugin can only be activated network wide.
  458. * @type string $title The human-readable title of the plugin.
  459. * @type string $author_name Plugin author's name.
  460. * @type bool $update Whether there's an available update. Default null.
  461. * }
  462. * @param array $response {
  463. * An array of metadata about the available plugin update.
  464. *
  465. * @type int $id Plugin ID.
  466. * @type string $slug Plugin slug.
  467. * @type string $new_version New plugin version.
  468. * @type string $url Plugin URL.
  469. * @type string $package Plugin update package URL.
  470. * }
  471. */
  472. do_action( "in_plugin_update_message-{$file}", $plugin_data, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  473. echo '</p></div></td></tr>';
  474. }
  475. }
  476. /**
  477. * @return array
  478. */
  479. function get_theme_updates() {
  480. $current = get_site_transient( 'update_themes' );
  481. if ( ! isset( $current->response ) ) {
  482. return array();
  483. }
  484. $update_themes = array();
  485. foreach ( $current->response as $stylesheet => $data ) {
  486. $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
  487. $update_themes[ $stylesheet ]->update = $data;
  488. }
  489. return $update_themes;
  490. }
  491. /**
  492. * @since 3.1.0
  493. */
  494. function wp_theme_update_rows() {
  495. if ( ! current_user_can( 'update_themes' ) ) {
  496. return;
  497. }
  498. $themes = get_site_transient( 'update_themes' );
  499. if ( isset( $themes->response ) && is_array( $themes->response ) ) {
  500. $themes = array_keys( $themes->response );
  501. foreach ( $themes as $theme ) {
  502. add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
  503. }
  504. }
  505. }
  506. /**
  507. * Displays update information for a theme.
  508. *
  509. * @param string $theme_key Theme stylesheet.
  510. * @param WP_Theme $theme Theme object.
  511. * @return false|void
  512. */
  513. function wp_theme_update_row( $theme_key, $theme ) {
  514. $current = get_site_transient( 'update_themes' );
  515. if ( ! isset( $current->response[ $theme_key ] ) ) {
  516. return false;
  517. }
  518. $response = $current->response[ $theme_key ];
  519. $details_url = add_query_arg(
  520. array(
  521. 'TB_iframe' => 'true',
  522. 'width' => 1024,
  523. 'height' => 800,
  524. ),
  525. $current->response[ $theme_key ]['url']
  526. );
  527. /** @var WP_MS_Themes_List_Table $wp_list_table */
  528. $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
  529. $active = $theme->is_allowed( 'network' ) ? ' active' : '';
  530. printf(
  531. '<tr class="plugin-update-tr%s" id="%s" data-slug="%s">' .
  532. '<td colspan="%s" class="plugin-update colspanchange">' .
  533. '<div class="update-message notice inline notice-warning notice-alt"><p>',
  534. $active,
  535. esc_attr( $theme->get_stylesheet() . '-update' ),
  536. esc_attr( $theme->get_stylesheet() ),
  537. $wp_list_table->get_column_count()
  538. );
  539. if ( ! current_user_can( 'update_themes' ) ) {
  540. printf(
  541. /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
  542. __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
  543. $theme['Name'],
  544. esc_url( $details_url ),
  545. sprintf(
  546. 'class="thickbox open-plugin-details-modal" aria-label="%s"',
  547. /* translators: 1: Theme name, 2: Version number. */
  548. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
  549. ),
  550. $response['new_version']
  551. );
  552. } elseif ( empty( $response['package'] ) ) {
  553. printf(
  554. /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number. */
  555. __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ),
  556. $theme['Name'],
  557. esc_url( $details_url ),
  558. sprintf(
  559. 'class="thickbox open-plugin-details-modal" aria-label="%s"',
  560. /* translators: 1: Theme name, 2: Version number. */
  561. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
  562. ),
  563. $response['new_version']
  564. );
  565. } else {
  566. printf(
  567. /* translators: 1: Theme name, 2: Details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */
  568. __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ),
  569. $theme['Name'],
  570. esc_url( $details_url ),
  571. sprintf(
  572. 'class="thickbox open-plugin-details-modal" aria-label="%s"',
  573. /* translators: 1: Theme name, 2: Version number. */
  574. esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
  575. ),
  576. $response['new_version'],
  577. wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
  578. sprintf(
  579. 'class="update-link" aria-label="%s"',
  580. /* translators: %s: Theme name. */
  581. esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
  582. )
  583. );
  584. }
  585. /**
  586. * Fires at the end of the update message container in each
  587. * row of the themes list table.
  588. *
  589. * The dynamic portion of the hook name, `$theme_key`, refers to
  590. * the theme slug as found in the WordPress.org themes repository.
  591. *
  592. * @since 3.1.0
  593. *
  594. * @param WP_Theme $theme The WP_Theme object.
  595. * @param array $response {
  596. * An array of metadata about the available theme update.
  597. *
  598. * @type string $new_version New theme version.
  599. * @type string $url Theme URL.
  600. * @type string $package Theme update package URL.
  601. * }
  602. */
  603. do_action( "in_theme_update_message-{$theme_key}", $theme, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  604. echo '</p></div></td></tr>';
  605. }
  606. /**
  607. * @global int $upgrading
  608. * @return false|void
  609. */
  610. function maintenance_nag() {
  611. include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
  612. global $upgrading;
  613. $nag = isset( $upgrading );
  614. if ( ! $nag ) {
  615. $failed = get_site_option( 'auto_core_update_failed' );
  616. /*
  617. * If an update failed critically, we may have copied over version.php but not other files.
  618. * In that case, if the installation claims we're running the version we attempted, nag.
  619. * This is serious enough to err on the side of nagging.
  620. *
  621. * If we simply failed to update before we tried to copy any files, then assume things are
  622. * OK if they are now running the latest.
  623. *
  624. * This flag is cleared whenever a successful update occurs using Core_Upgrader.
  625. */
  626. $comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
  627. if ( isset( $failed['attempted'] ) && version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
  628. $nag = true;
  629. }
  630. }
  631. if ( ! $nag ) {
  632. return false;
  633. }
  634. if ( current_user_can( 'update_core' ) ) {
  635. $msg = sprintf(
  636. /* translators: %s: URL to WordPress Updates screen. */
  637. __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ),
  638. 'update-core.php'
  639. );
  640. } else {
  641. $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
  642. }
  643. echo "<div class='update-nag'>$msg</div>";
  644. }
  645. /**
  646. * Prints the JavaScript templates for update admin notices.
  647. *
  648. * Template takes one argument with four values:
  649. *
  650. * param {object} data {
  651. * Arguments for admin notice.
  652. *
  653. * @type string id ID of the notice.
  654. * @type string className Class names for the notice.
  655. * @type string message The notice's message.
  656. * @type string type The type of update the notice is for. Either 'plugin' or 'theme'.
  657. * }
  658. *
  659. * @since 4.6.0
  660. */
  661. function wp_print_admin_notice_templates() {
  662. ?>
  663. <script id="tmpl-wp-updates-admin-notice" type="text/html">
  664. <div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
  665. </script>
  666. <script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
  667. <div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errors ) { #>notice-error<# } else { #>notice-success<# } #>">
  668. <p>
  669. <# if ( data.successes ) { #>
  670. <# if ( 1 === data.successes ) { #>
  671. <# if ( 'plugin' === data.type ) { #>
  672. <?php
  673. /* translators: %s: Number of plugins. */
  674. printf( __( '%s plugin successfully updated.' ), '{{ data.successes }}' );
  675. ?>
  676. <# } else { #>
  677. <?php
  678. /* translators: %s: Number of themes. */
  679. printf( __( '%s theme successfully updated.' ), '{{ data.successes }}' );
  680. ?>
  681. <# } #>
  682. <# } else { #>
  683. <# if ( 'plugin' === data.type ) { #>
  684. <?php
  685. /* translators: %s: Number of plugins. */
  686. printf( __( '%s plugins successfully updated.' ), '{{ data.successes }}' );
  687. ?>
  688. <# } else { #>
  689. <?php
  690. /* translators: %s: Number of themes. */
  691. printf( __( '%s themes successfully updated.' ), '{{ data.successes }}' );
  692. ?>
  693. <# } #>
  694. <# } #>
  695. <# } #>
  696. <# if ( data.errors ) { #>
  697. <button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
  698. <# if ( 1 === data.errors ) { #>
  699. <?php
  700. /* translators: %s: Number of failed updates. */
  701. printf( __( '%s update failed.' ), '{{ data.errors }}' );
  702. ?>
  703. <# } else { #>
  704. <?php
  705. /* translators: %s: Number of failed updates. */
  706. printf( __( '%s updates failed.' ), '{{ data.errors }}' );
  707. ?>
  708. <# } #>
  709. <span class="screen-reader-text"><?php _e( 'Show more details' ); ?></span>
  710. <span class="toggle-indicator" aria-hidden="true"></span>
  711. </button>
  712. <# } #>
  713. </p>
  714. <# if ( data.errors ) { #>
  715. <ul class="bulk-action-errors hidden">
  716. <# _.each( data.errorMessages, function( errorMessage ) { #>
  717. <li>{{ errorMessage }}</li>
  718. <# } ); #>
  719. </ul>
  720. <# } #>
  721. </div>
  722. </script>
  723. <?php
  724. }
  725. /**
  726. * Prints the JavaScript templates for update and deletion rows in list tables.
  727. *
  728. * The update template takes one argument with four values:
  729. *
  730. * param {object} data {
  731. * Arguments for the update row
  732. *
  733. * @type string slug Plugin slug.
  734. * @type string plugin Plugin base name.
  735. * @type string colspan The number of table columns this row spans.
  736. * @type string content The row content.
  737. * }
  738. *
  739. * The delete template takes one argument with four values:
  740. *
  741. * param {object} data {
  742. * Arguments for the update row
  743. *
  744. * @type string slug Plugin slug.
  745. * @type string plugin Plugin base name.
  746. * @type string name Plugin name.
  747. * @type string colspan The number of table columns this row spans.
  748. * }
  749. *
  750. * @since 4.6.0
  751. */
  752. function wp_print_update_row_templates() {
  753. ?>
  754. <script id="tmpl-item-update-row" type="text/template">
  755. <tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
  756. <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
  757. {{{ data.content }}}
  758. </td>
  759. </tr>
  760. </script>
  761. <script id="tmpl-item-deleted-row" type="text/template">
  762. <tr class="plugin-deleted-tr inactive deleted" id="{{ data.slug }}-deleted" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
  763. <td colspan="{{ data.colspan }}" class="plugin-update colspanchange">
  764. <# if ( data.plugin ) { #>
  765. <?php
  766. printf(
  767. /* translators: %s: Plugin name. */
  768. _x( '%s was successfully deleted.', 'plugin' ),
  769. '<strong>{{{ data.name }}}</strong>'
  770. );
  771. ?>
  772. <# } else { #>
  773. <?php
  774. printf(
  775. /* translators: %s: Theme name. */
  776. _x( '%s was successfully deleted.', 'theme' ),
  777. '<strong>{{{ data.name }}}</strong>'
  778. );
  779. ?>
  780. <# } #>
  781. </td>
  782. </tr>
  783. </script>
  784. <?php
  785. }
  786. /**
  787. * Displays a notice when the user is in recovery mode.
  788. *
  789. * @since 5.2.0
  790. */
  791. function wp_recovery_mode_nag() {
  792. if ( ! wp_is_recovery_mode() ) {
  793. return;
  794. }
  795. $url = wp_login_url();
  796. $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
  797. $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
  798. ?>
  799. <div class="notice notice-info">
  800. <p>
  801. <?php
  802. printf(
  803. /* translators: %s: Recovery Mode exit link. */
  804. __( 'You are in recovery mode. This means there may be an error with a theme or plugin. To exit recovery mode, log out or use the Exit button. <a href="%s">Exit Recovery Mode</a>' ),
  805. esc_url( $url )
  806. );
  807. ?>
  808. </p>
  809. </div>
  810. <?php
  811. }