wp/wp-admin/includes/update.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    13  *
    13  *
    14  * @return object|array|false The response from the API on success, false on failure.
    14  * @return object|array|false The response from the API on success, false on failure.
    15  */
    15  */
    16 function get_preferred_from_update_core() {
    16 function get_preferred_from_update_core() {
    17 	$updates = get_core_updates();
    17 	$updates = get_core_updates();
       
    18 
    18 	if ( ! is_array( $updates ) ) {
    19 	if ( ! is_array( $updates ) ) {
    19 		return false;
    20 		return false;
    20 	}
    21 	}
       
    22 
    21 	if ( empty( $updates ) ) {
    23 	if ( empty( $updates ) ) {
    22 		return (object) array( 'response' => 'latest' );
    24 		return (object) array( 'response' => 'latest' );
    23 	}
    25 	}
       
    26 
    24 	return $updates[0];
    27 	return $updates[0];
    25 }
    28 }
    26 
    29 
    27 /**
    30 /**
    28  * Gets available core updates.
    31  * Gets available core updates.
    32  * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
    35  * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
    33  *                       set $options['available'] to false to skip not-dismissed updates.
    36  *                       set $options['available'] to false to skip not-dismissed updates.
    34  * @return array|false Array of the update objects on success, false on failure.
    37  * @return array|false Array of the update objects on success, false on failure.
    35  */
    38  */
    36 function get_core_updates( $options = array() ) {
    39 function get_core_updates( $options = array() ) {
    37 	$options   = array_merge(
    40 	$options = array_merge(
    38 		array(
    41 		array(
    39 			'available' => true,
    42 			'available' => true,
    40 			'dismissed' => false,
    43 			'dismissed' => false,
    41 		),
    44 		),
    42 		$options
    45 		$options
    43 	);
    46 	);
       
    47 
    44 	$dismissed = get_site_option( 'dismissed_update_core' );
    48 	$dismissed = get_site_option( 'dismissed_update_core' );
    45 
    49 
    46 	if ( ! is_array( $dismissed ) ) {
    50 	if ( ! is_array( $dismissed ) ) {
    47 		$dismissed = array();
    51 		$dismissed = array();
    48 	}
    52 	}
    53 		return false;
    57 		return false;
    54 	}
    58 	}
    55 
    59 
    56 	$updates = $from_api->updates;
    60 	$updates = $from_api->updates;
    57 	$result  = array();
    61 	$result  = array();
       
    62 
    58 	foreach ( $updates as $update ) {
    63 	foreach ( $updates as $update ) {
    59 		if ( 'autoupdate' === $update->response ) {
    64 		if ( 'autoupdate' === $update->response ) {
    60 			continue;
    65 			continue;
    61 		}
    66 		}
    62 
    67 
    70 				$update->dismissed = false;
    75 				$update->dismissed = false;
    71 				$result[]          = $update;
    76 				$result[]          = $update;
    72 			}
    77 			}
    73 		}
    78 		}
    74 	}
    79 	}
       
    80 
    75 	return $result;
    81 	return $result;
    76 }
    82 }
    77 
    83 
    78 /**
    84 /**
    79  * Gets the best available (and enabled) Auto-Update for WordPress core.
    85  * Gets the best available (and enabled) Auto-Update for WordPress core.
    84  *
    90  *
    85  * @return object|false The core update offering on success, false on failure.
    91  * @return object|false The core update offering on success, false on failure.
    86  */
    92  */
    87 function find_core_auto_update() {
    93 function find_core_auto_update() {
    88 	$updates = get_site_transient( 'update_core' );
    94 	$updates = get_site_transient( 'update_core' );
       
    95 
    89 	if ( ! $updates || empty( $updates->updates ) ) {
    96 	if ( ! $updates || empty( $updates->updates ) ) {
    90 		return false;
    97 		return false;
    91 	}
    98 	}
    92 
    99 
    93 	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
   100 	require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    94 
   101 
    95 	$auto_update = false;
   102 	$auto_update = false;
    96 	$upgrader    = new WP_Automatic_Updater;
   103 	$upgrader    = new WP_Automatic_Updater();
       
   104 
    97 	foreach ( $updates->updates as $update ) {
   105 	foreach ( $updates->updates as $update ) {
    98 		if ( 'autoupdate' !== $update->response ) {
   106 		if ( 'autoupdate' !== $update->response ) {
    99 			continue;
   107 			continue;
   100 		}
   108 		}
   101 
   109 
   105 
   113 
   106 		if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
   114 		if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
   107 			$auto_update = $update;
   115 			$auto_update = $update;
   108 		}
   116 		}
   109 	}
   117 	}
       
   118 
   110 	return $auto_update;
   119 	return $auto_update;
   111 }
   120 }
   112 
   121 
   113 /**
   122 /**
   114  * Gets and caches the checksums for the given version of WordPress.
   123  * Gets and caches the checksums for the given version of WordPress.
   122 function get_core_checksums( $version, $locale ) {
   131 function get_core_checksums( $version, $locale ) {
   123 	$http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), '', '&' );
   132 	$http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), '', '&' );
   124 	$url      = $http_url;
   133 	$url      = $http_url;
   125 
   134 
   126 	$ssl = wp_http_supports( array( 'ssl' ) );
   135 	$ssl = wp_http_supports( array( 'ssl' ) );
       
   136 
   127 	if ( $ssl ) {
   137 	if ( $ssl ) {
   128 		$url = set_url_scheme( $url, 'https' );
   138 		$url = set_url_scheme( $url, 'https' );
   129 	}
   139 	}
   130 
   140 
   131 	$options = array(
   141 	$options = array(
   132 		'timeout' => wp_doing_cron() ? 30 : 3,
   142 		'timeout' => wp_doing_cron() ? 30 : 3,
   133 	);
   143 	);
   134 
   144 
   135 	$response = wp_remote_get( $url, $options );
   145 	$response = wp_remote_get( $url, $options );
       
   146 
   136 	if ( $ssl && is_wp_error( $response ) ) {
   147 	if ( $ssl && is_wp_error( $response ) ) {
   137 		trigger_error(
   148 		wp_trigger_error(
       
   149 			__FUNCTION__,
   138 			sprintf(
   150 			sprintf(
   139 				/* translators: %s: Support forums URL. */
   151 				/* translators: %s: Support forums URL. */
   140 				__( '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>.' ),
   152 				__( '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>.' ),
   141 				__( 'https://wordpress.org/support/forums/' )
   153 				__( 'https://wordpress.org/support/forums/' )
   142 			) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
   154 			) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
   143 			headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
   155 			headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
   144 		);
   156 		);
       
   157 
   145 		$response = wp_remote_get( $http_url, $options );
   158 		$response = wp_remote_get( $http_url, $options );
   146 	}
   159 	}
   147 
   160 
   148 	if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
   161 	if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
   149 		return false;
   162 		return false;
   150 	}
   163 	}
   151 
   164 
   152 	$body = trim( wp_remote_retrieve_body( $response ) );
   165 	$body = trim( wp_remote_retrieve_body( $response ) );
   153 	$body = json_decode( $body, true );
   166 	$body = json_decode( $body, true );
   168  * @return bool
   181  * @return bool
   169  */
   182  */
   170 function dismiss_core_update( $update ) {
   183 function dismiss_core_update( $update ) {
   171 	$dismissed = get_site_option( 'dismissed_update_core' );
   184 	$dismissed = get_site_option( 'dismissed_update_core' );
   172 	$dismissed[ $update->current . '|' . $update->locale ] = true;
   185 	$dismissed[ $update->current . '|' . $update->locale ] = true;
       
   186 
   173 	return update_site_option( 'dismissed_update_core', $dismissed );
   187 	return update_site_option( 'dismissed_update_core', $dismissed );
   174 }
   188 }
   175 
   189 
   176 /**
   190 /**
   177  * Undismisses core update.
   191  * Undismisses core update.
   189 	if ( ! isset( $dismissed[ $key ] ) ) {
   203 	if ( ! isset( $dismissed[ $key ] ) ) {
   190 		return false;
   204 		return false;
   191 	}
   205 	}
   192 
   206 
   193 	unset( $dismissed[ $key ] );
   207 	unset( $dismissed[ $key ] );
       
   208 
   194 	return update_site_option( 'dismissed_update_core', $dismissed );
   209 	return update_site_option( 'dismissed_update_core', $dismissed );
   195 }
   210 }
   196 
   211 
   197 /**
   212 /**
   198  * Finds the available update for WordPress core.
   213  * Finds the available update for WordPress core.
   209 	if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
   224 	if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
   210 		return false;
   225 		return false;
   211 	}
   226 	}
   212 
   227 
   213 	$updates = $from_api->updates;
   228 	$updates = $from_api->updates;
       
   229 
   214 	foreach ( $updates as $update ) {
   230 	foreach ( $updates as $update ) {
   215 		if ( $update->current == $version && $update->locale == $locale ) {
   231 		if ( $update->current === $version && $update->locale === $locale ) {
   216 			return $update;
   232 			return $update;
   217 		}
   233 		}
   218 	}
   234 	}
       
   235 
   219 	return false;
   236 	return false;
   220 }
   237 }
   221 
   238 
   222 /**
   239 /**
       
   240  * Returns core update footer message.
       
   241  *
   223  * @since 2.3.0
   242  * @since 2.3.0
   224  *
   243  *
   225  * @param string $msg
   244  * @param string $msg
   226  * @return string
   245  * @return string
   227  */
   246  */
   230 		/* translators: %s: WordPress version. */
   249 		/* translators: %s: WordPress version. */
   231 		return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
   250 		return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
   232 	}
   251 	}
   233 
   252 
   234 	$cur = get_preferred_from_update_core();
   253 	$cur = get_preferred_from_update_core();
       
   254 
   235 	if ( ! is_object( $cur ) ) {
   255 	if ( ! is_object( $cur ) ) {
   236 		$cur = new stdClass;
   256 		$cur = new stdClass();
   237 	}
   257 	}
   238 
   258 
   239 	if ( ! isset( $cur->current ) ) {
   259 	if ( ! isset( $cur->current ) ) {
   240 		$cur->current = '';
   260 		$cur->current = '';
   241 	}
   261 	}
   273 			return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
   293 			return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
   274 	}
   294 	}
   275 }
   295 }
   276 
   296 
   277 /**
   297 /**
       
   298  * Returns core update notification message.
       
   299  *
   278  * @since 2.3.0
   300  * @since 2.3.0
   279  *
   301  *
   280  * @global string $pagenow The filename of the current screen.
   302  * @global string $pagenow The filename of the current screen.
   281  * @return void|false
   303  * @return void|false
   282  */
   304  */
   297 		return false;
   319 		return false;
   298 	}
   320 	}
   299 
   321 
   300 	$version_url = sprintf(
   322 	$version_url = sprintf(
   301 		/* translators: %s: WordPress version. */
   323 		/* translators: %s: WordPress version. */
   302 		esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
   324 		esc_url( __( 'https://wordpress.org/documentation/wordpress-version/version-%s/' ) ),
   303 		sanitize_title( $cur->current )
   325 		sanitize_title( $cur->current )
   304 	);
   326 	);
   305 
   327 
   306 	if ( current_user_can( 'update_core' ) ) {
   328 	if ( current_user_can( 'update_core' ) ) {
   307 		$msg = sprintf(
   329 		$msg = sprintf(
   319 			$version_url,
   341 			$version_url,
   320 			$cur->current
   342 			$cur->current
   321 		);
   343 		);
   322 	}
   344 	}
   323 
   345 
   324 	echo "<div class='update-nag notice notice-warning inline'>$msg</div>";
   346 	wp_admin_notice(
       
   347 		$msg,
       
   348 		array(
       
   349 			'type'               => 'warning',
       
   350 			'additional_classes' => array( 'update-nag', 'inline' ),
       
   351 			'paragraph_wrap'     => false,
       
   352 		)
       
   353 	);
   325 }
   354 }
   326 
   355 
   327 /**
   356 /**
   328  * Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
   357  * Displays WordPress version and active theme in the 'At a Glance' dashboard widget.
   329  *
   358  *
   330  * @since 2.5.0
   359  * @since 2.5.0
   331  */
   360  */
   332 function update_right_now_message() {
   361 function update_right_now_message() {
   333 	$theme_name = wp_get_theme();
   362 	$theme_name = wp_get_theme();
       
   363 
   334 	if ( current_user_can( 'switch_themes' ) ) {
   364 	if ( current_user_can( 'switch_themes' ) ) {
   335 		$theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
   365 		$theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
   336 	}
   366 	}
   337 
   367 
   338 	$msg = '';
   368 	$msg = '';
   368 
   398 
   369 	echo "<p id='wp-version-message'>$msg</p>";
   399 	echo "<p id='wp-version-message'>$msg</p>";
   370 }
   400 }
   371 
   401 
   372 /**
   402 /**
       
   403  * Retrieves plugins with updates available.
       
   404  *
   373  * @since 2.9.0
   405  * @since 2.9.0
   374  *
   406  *
   375  * @return array
   407  * @return array
   376  */
   408  */
   377 function get_plugin_updates() {
   409 function get_plugin_updates() {
   378 	$all_plugins     = get_plugins();
   410 	$all_plugins     = get_plugins();
   379 	$upgrade_plugins = array();
   411 	$upgrade_plugins = array();
   380 	$current         = get_site_transient( 'update_plugins' );
   412 	$current         = get_site_transient( 'update_plugins' );
       
   413 
   381 	foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
   414 	foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
   382 		if ( isset( $current->response[ $plugin_file ] ) ) {
   415 		if ( isset( $current->response[ $plugin_file ] ) ) {
   383 			$upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
   416 			$upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
   384 			$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
   417 			$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
   385 		}
   418 		}
   387 
   420 
   388 	return $upgrade_plugins;
   421 	return $upgrade_plugins;
   389 }
   422 }
   390 
   423 
   391 /**
   424 /**
       
   425  * Adds a callback to display update information for plugins with updates available.
       
   426  *
   392  * @since 2.9.0
   427  * @since 2.9.0
   393  */
   428  */
   394 function wp_plugin_update_rows() {
   429 function wp_plugin_update_rows() {
   395 	if ( ! current_user_can( 'update_plugins' ) ) {
   430 	if ( ! current_user_can( 'update_plugins' ) ) {
   396 		return;
   431 		return;
   397 	}
   432 	}
   398 
   433 
   399 	$plugins = get_site_transient( 'update_plugins' );
   434 	$plugins = get_site_transient( 'update_plugins' );
       
   435 
   400 	if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
   436 	if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
   401 		$plugins = array_keys( $plugins->response );
   437 		$plugins = array_keys( $plugins->response );
       
   438 
   402 		foreach ( $plugins as $plugin_file ) {
   439 		foreach ( $plugins as $plugin_file ) {
   403 			add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 );
   440 			add_action( "after_plugin_row_{$plugin_file}", 'wp_plugin_update_row', 10, 2 );
   404 		}
   441 		}
   405 	}
   442 	}
   406 }
   443 }
   414  * @param array  $plugin_data Plugin information.
   451  * @param array  $plugin_data Plugin information.
   415  * @return void|false
   452  * @return void|false
   416  */
   453  */
   417 function wp_plugin_update_row( $file, $plugin_data ) {
   454 function wp_plugin_update_row( $file, $plugin_data ) {
   418 	$current = get_site_transient( 'update_plugins' );
   455 	$current = get_site_transient( 'update_plugins' );
       
   456 
   419 	if ( ! isset( $current->response[ $file ] ) ) {
   457 	if ( ! isset( $current->response[ $file ] ) ) {
   420 		return false;
   458 		return false;
   421 	}
   459 	}
   422 
   460 
   423 	$response = $current->response[ $file ];
   461 	$response = $current->response[ $file ];
   583 		echo '</p></div></td></tr>';
   621 		echo '</p></div></td></tr>';
   584 	}
   622 	}
   585 }
   623 }
   586 
   624 
   587 /**
   625 /**
       
   626  * Retrieves themes with updates available.
       
   627  *
   588  * @since 2.9.0
   628  * @since 2.9.0
   589  *
   629  *
   590  * @return array
   630  * @return array
   591  */
   631  */
   592 function get_theme_updates() {
   632 function get_theme_updates() {
   595 	if ( ! isset( $current->response ) ) {
   635 	if ( ! isset( $current->response ) ) {
   596 		return array();
   636 		return array();
   597 	}
   637 	}
   598 
   638 
   599 	$update_themes = array();
   639 	$update_themes = array();
       
   640 
   600 	foreach ( $current->response as $stylesheet => $data ) {
   641 	foreach ( $current->response as $stylesheet => $data ) {
   601 		$update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
   642 		$update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
   602 		$update_themes[ $stylesheet ]->update = $data;
   643 		$update_themes[ $stylesheet ]->update = $data;
   603 	}
   644 	}
   604 
   645 
   605 	return $update_themes;
   646 	return $update_themes;
   606 }
   647 }
   607 
   648 
   608 /**
   649 /**
       
   650  * Adds a callback to display update information for themes with updates available.
       
   651  *
   609  * @since 3.1.0
   652  * @since 3.1.0
   610  */
   653  */
   611 function wp_theme_update_rows() {
   654 function wp_theme_update_rows() {
   612 	if ( ! current_user_can( 'update_themes' ) ) {
   655 	if ( ! current_user_can( 'update_themes' ) ) {
   613 		return;
   656 		return;
   614 	}
   657 	}
   615 
   658 
   616 	$themes = get_site_transient( 'update_themes' );
   659 	$themes = get_site_transient( 'update_themes' );
       
   660 
   617 	if ( isset( $themes->response ) && is_array( $themes->response ) ) {
   661 	if ( isset( $themes->response ) && is_array( $themes->response ) ) {
   618 		$themes = array_keys( $themes->response );
   662 		$themes = array_keys( $themes->response );
   619 
   663 
   620 		foreach ( $themes as $theme ) {
   664 		foreach ( $themes as $theme ) {
   621 			add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
   665 			add_action( "after_theme_row_{$theme}", 'wp_theme_update_row', 10, 2 );
   799 
   843 
   800 	echo '</p></div></td></tr>';
   844 	echo '</p></div></td></tr>';
   801 }
   845 }
   802 
   846 
   803 /**
   847 /**
       
   848  * Displays maintenance nag HTML message.
       
   849  *
   804  * @since 2.7.0
   850  * @since 2.7.0
   805  *
   851  *
   806  * @global int $upgrading
   852  * @global int $upgrading
       
   853  *
   807  * @return void|false
   854  * @return void|false
   808  */
   855  */
   809 function maintenance_nag() {
   856 function maintenance_nag() {
   810 	// Include an unmodified $wp_version.
   857 	// Include an unmodified $wp_version.
   811 	require ABSPATH . WPINC . '/version.php';
   858 	require ABSPATH . WPINC . '/version.php';
   812 	global $upgrading;
   859 	global $upgrading;
       
   860 
   813 	$nag = isset( $upgrading );
   861 	$nag = isset( $upgrading );
       
   862 
   814 	if ( ! $nag ) {
   863 	if ( ! $nag ) {
   815 		$failed = get_site_option( 'auto_core_update_failed' );
   864 		$failed = get_site_option( 'auto_core_update_failed' );
   816 		/*
   865 		/*
   817 		 * If an update failed critically, we may have copied over version.php but not other files.
   866 		 * If an update failed critically, we may have copied over version.php but not other files.
   818 		 * In that case, if the installation claims we're running the version we attempted, nag.
   867 		 * In that case, if the installation claims we're running the version we attempted, nag.
   841 		);
   890 		);
   842 	} else {
   891 	} else {
   843 		$msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
   892 		$msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
   844 	}
   893 	}
   845 
   894 
   846 	echo "<div class='update-nag notice notice-warning inline'>$msg</div>";
   895 	wp_admin_notice(
       
   896 		$msg,
       
   897 		array(
       
   898 			'type'               => 'warning',
       
   899 			'additional_classes' => array( 'update-nag', 'inline' ),
       
   900 			'paragraph_wrap'     => false,
       
   901 		)
       
   902 	);
   847 }
   903 }
   848 
   904 
   849 /**
   905 /**
   850  * Prints the JavaScript templates for update admin notices.
   906  * Prints the JavaScript templates for update admin notices.
       
   907  *
       
   908  * @since 4.6.0
   851  *
   909  *
   852  * Template takes one argument with four values:
   910  * Template takes one argument with four values:
   853  *
   911  *
   854  *     param {object} data {
   912  *     param {object} data {
   855  *         Arguments for admin notice.
   913  *         Arguments for admin notice.
   857  *         @type string id        ID of the notice.
   915  *         @type string id        ID of the notice.
   858  *         @type string className Class names for the notice.
   916  *         @type string className Class names for the notice.
   859  *         @type string message   The notice's message.
   917  *         @type string message   The notice's message.
   860  *         @type string type      The type of update the notice is for. Either 'plugin' or 'theme'.
   918  *         @type string type      The type of update the notice is for. Either 'plugin' or 'theme'.
   861  *     }
   919  *     }
   862  *
       
   863  * @since 4.6.0
       
   864  */
   920  */
   865 function wp_print_admin_notice_templates() {
   921 function wp_print_admin_notice_templates() {
   866 	?>
   922 	?>
   867 	<script id="tmpl-wp-updates-admin-notice" type="text/html">
   923 	<script id="tmpl-wp-updates-admin-notice" type="text/html">
   868 		<div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
   924 		<div <# if ( data.id ) { #>id="{{ data.id }}"<# } #> class="notice {{ data.className }}"><p>{{{ data.message }}}</p></div>
   869 	</script>
   925 	</script>
   870 	<script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
   926 	<script id="tmpl-wp-bulk-updates-admin-notice" type="text/html">
   871 		<div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errors ) { #>notice-error<# } else { #>notice-success<# } #>">
   927 		<div id="{{ data.id }}" class="{{ data.className }} notice <# if ( data.errorMessage ) { #>notice-error<# } else { #>notice-success<# } #>">
   872 			<p>
   928 			<p>
   873 				<# if ( data.successes ) { #>
   929 				<# if ( data.successMessage ) { #>
   874 					<# if ( 1 === data.successes ) { #>
   930 					{{{ data.successMessage }}}
   875 						<# if ( 'plugin' === data.type ) { #>
   931 				<# } #>
       
   932 				<# if ( data.errorMessage ) { #>
       
   933 					<button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
       
   934 						{{{ data.errorMessage }}}
       
   935 						<span class="screen-reader-text">
   876 							<?php
   936 							<?php
   877 							/* translators: %s: Number of plugins. */
   937 							/* translators: Hidden accessibility text. */
   878 							printf( __( '%s plugin successfully updated.' ), '{{ data.successes }}' );
   938 							_e( 'Show more details' );
   879 							?>
   939 							?>
   880 						<# } else { #>
   940 						</span>
   881 							<?php
       
   882 							/* translators: %s: Number of themes. */
       
   883 							printf( __( '%s theme successfully updated.' ), '{{ data.successes }}' );
       
   884 							?>
       
   885 						<# } #>
       
   886 					<# } else { #>
       
   887 						<# if ( 'plugin' === data.type ) { #>
       
   888 							<?php
       
   889 							/* translators: %s: Number of plugins. */
       
   890 							printf( __( '%s plugins successfully updated.' ), '{{ data.successes }}' );
       
   891 							?>
       
   892 						<# } else { #>
       
   893 							<?php
       
   894 							/* translators: %s: Number of themes. */
       
   895 							printf( __( '%s themes successfully updated.' ), '{{ data.successes }}' );
       
   896 							?>
       
   897 						<# } #>
       
   898 					<# } #>
       
   899 				<# } #>
       
   900 				<# if ( data.errors ) { #>
       
   901 					<button class="button-link bulk-action-errors-collapsed" aria-expanded="false">
       
   902 						<# if ( 1 === data.errors ) { #>
       
   903 							<?php
       
   904 							/* translators: %s: Number of failed updates. */
       
   905 							printf( __( '%s update failed.' ), '{{ data.errors }}' );
       
   906 							?>
       
   907 						<# } else { #>
       
   908 							<?php
       
   909 							/* translators: %s: Number of failed updates. */
       
   910 							printf( __( '%s updates failed.' ), '{{ data.errors }}' );
       
   911 							?>
       
   912 						<# } #>
       
   913 						<span class="screen-reader-text"><?php _e( 'Show more details' ); ?></span>
       
   914 						<span class="toggle-indicator" aria-hidden="true"></span>
   941 						<span class="toggle-indicator" aria-hidden="true"></span>
   915 					</button>
   942 					</button>
   916 				<# } #>
   943 				<# } #>
   917 			</p>
   944 			</p>
   918 			<# if ( data.errors ) { #>
   945 			<# if ( data.errorMessages ) { #>
   919 				<ul class="bulk-action-errors hidden">
   946 				<ul class="bulk-action-errors hidden">
   920 					<# _.each( data.errorMessages, function( errorMessage ) { #>
   947 					<# _.each( data.errorMessages, function( errorMessage ) { #>
   921 						<li>{{ errorMessage }}</li>
   948 						<li>{{ errorMessage }}</li>
   922 					<# } ); #>
   949 					<# } ); #>
   923 				</ul>
   950 				</ul>
   928 }
   955 }
   929 
   956 
   930 /**
   957 /**
   931  * Prints the JavaScript templates for update and deletion rows in list tables.
   958  * Prints the JavaScript templates for update and deletion rows in list tables.
   932  *
   959  *
       
   960  * @since 4.6.0
       
   961  *
   933  * The update template takes one argument with four values:
   962  * The update template takes one argument with four values:
   934  *
   963  *
   935  *     param {object} data {
   964  *     param {object} data {
   936  *         Arguments for the update row
   965  *         Arguments for the update row
   937  *
   966  *
   949  *         @type string slug    Plugin slug.
   978  *         @type string slug    Plugin slug.
   950  *         @type string plugin  Plugin base name.
   979  *         @type string plugin  Plugin base name.
   951  *         @type string name    Plugin name.
   980  *         @type string name    Plugin name.
   952  *         @type string colspan The number of table columns this row spans.
   981  *         @type string colspan The number of table columns this row spans.
   953  *     }
   982  *     }
   954  *
       
   955  * @since 4.6.0
       
   956  */
   983  */
   957 function wp_print_update_row_templates() {
   984 function wp_print_update_row_templates() {
   958 	?>
   985 	?>
   959 	<script id="tmpl-item-update-row" type="text/template">
   986 	<script id="tmpl-item-update-row" type="text/template">
   960 		<tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
   987 		<tr class="plugin-update-tr update" id="{{ data.slug }}-update" data-slug="{{ data.slug }}" <# if ( data.plugin ) { #>data-plugin="{{ data.plugin }}"<# } #>>
  1001 
  1028 
  1002 	$url = wp_login_url();
  1029 	$url = wp_login_url();
  1003 	$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
  1030 	$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
  1004 	$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
  1031 	$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
  1005 
  1032 
  1006 	?>
  1033 	$message = sprintf(
  1007 	<div class="notice notice-info">
  1034 		/* translators: %s: Recovery Mode exit link. */
  1008 		<p>
  1035 		__( '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>' ),
  1009 			<?php
  1036 		esc_url( $url )
  1010 			printf(
  1037 	);
  1011 				/* translators: %s: Recovery Mode exit link. */
  1038 	wp_admin_notice( $message, array( 'type' => 'info' ) );
  1012 				__( '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>' ),
       
  1013 				esc_url( $url )
       
  1014 			);
       
  1015 			?>
       
  1016 		</p>
       
  1017 	</div>
       
  1018 	<?php
       
  1019 }
  1039 }
  1020 
  1040 
  1021 /**
  1041 /**
  1022  * Checks whether auto-updates are enabled.
  1042  * Checks whether auto-updates are enabled.
  1023  *
  1043  *
  1024  * @since 5.5.0
  1044  * @since 5.5.0
  1025  *
  1045  *
  1026  * @param string $type The type of update being checked: 'theme' or 'plugin'.
  1046  * @param string $type The type of update being checked: Either 'theme' or 'plugin'.
  1027  * @return bool True if auto-updates are enabled for `$type`, false otherwise.
  1047  * @return bool True if auto-updates are enabled for `$type`, false otherwise.
  1028  */
  1048  */
  1029 function wp_is_auto_update_enabled_for_type( $type ) {
  1049 function wp_is_auto_update_enabled_for_type( $type ) {
  1030 	if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
  1050 	if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
  1031 		require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
  1051 		require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
  1061 /**
  1081 /**
  1062  * Checks whether auto-updates are forced for an item.
  1082  * Checks whether auto-updates are forced for an item.
  1063  *
  1083  *
  1064  * @since 5.6.0
  1084  * @since 5.6.0
  1065  *
  1085  *
  1066  * @param string    $type   The type of update being checked: 'theme' or 'plugin'.
  1086  * @param string    $type   The type of update being checked: Either 'theme' or 'plugin'.
  1067  * @param bool|null $update Whether to update. The value of null is internally used
  1087  * @param bool|null $update Whether to update. The value of null is internally used
  1068  *                          to detect whether nothing has hooked into this filter.
  1088  *                          to detect whether nothing has hooked into this filter.
  1069  * @param object    $item   The update offer.
  1089  * @param object    $item   The update offer.
  1070  * @return bool True if auto-updates are forced for `$item`, false otherwise.
  1090  * @return bool True if auto-updates are forced for `$item`, false otherwise.
  1071  */
  1091  */