update.php 25 KB

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