wp/wp-admin/includes/update.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    11  *
    11  *
    12  * @return object|array|false The response from the API on success, false on failure.
    12  * @return object|array|false The response from the API on success, false on failure.
    13  */
    13  */
    14 function get_preferred_from_update_core() {
    14 function get_preferred_from_update_core() {
    15 	$updates = get_core_updates();
    15 	$updates = get_core_updates();
    16 	if ( ! is_array( $updates ) )
    16 	if ( ! is_array( $updates ) ) {
    17 		return false;
    17 		return false;
    18 	if ( empty( $updates ) )
    18 	}
       
    19 	if ( empty( $updates ) ) {
    19 		return (object) array( 'response' => 'latest' );
    20 		return (object) array( 'response' => 'latest' );
       
    21 	}
    20 	return $updates[0];
    22 	return $updates[0];
    21 }
    23 }
    22 
    24 
    23 /**
    25 /**
    24  * Get available core updates.
    26  * Get available core updates.
    25  *
    27  *
    26  * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
    28  * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
    27  * 	                     set $options['available'] to false to skip not-dismissed updates.
    29  *                       set $options['available'] to false to skip not-dismissed updates.
    28  * @return array|false Array of the update objects on success, false on failure.
    30  * @return array|false Array of the update objects on success, false on failure.
    29  */
    31  */
    30 function get_core_updates( $options = array() ) {
    32 function get_core_updates( $options = array() ) {
    31 	$options = array_merge( array( 'available' => true, 'dismissed' => false ), $options );
    33 	$options   = array_merge(
       
    34 		array(
       
    35 			'available' => true,
       
    36 			'dismissed' => false,
       
    37 		),
       
    38 		$options
       
    39 	);
    32 	$dismissed = get_site_option( 'dismissed_update_core' );
    40 	$dismissed = get_site_option( 'dismissed_update_core' );
    33 
    41 
    34 	if ( ! is_array( $dismissed ) )
    42 	if ( ! is_array( $dismissed ) ) {
    35 		$dismissed = array();
    43 		$dismissed = array();
       
    44 	}
    36 
    45 
    37 	$from_api = get_site_transient( 'update_core' );
    46 	$from_api = get_site_transient( 'update_core' );
    38 
    47 
    39 	if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
    48 	if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
    40 		return false;
    49 		return false;
       
    50 	}
    41 
    51 
    42 	$updates = $from_api->updates;
    52 	$updates = $from_api->updates;
    43 	$result = array();
    53 	$result  = array();
    44 	foreach ( $updates as $update ) {
    54 	foreach ( $updates as $update ) {
    45 		if ( $update->response == 'autoupdate' )
    55 		if ( $update->response == 'autoupdate' ) {
    46 			continue;
    56 			continue;
       
    57 		}
    47 
    58 
    48 		if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
    59 		if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) {
    49 			if ( $options['dismissed'] ) {
    60 			if ( $options['dismissed'] ) {
    50 				$update->dismissed = true;
    61 				$update->dismissed = true;
    51 				$result[] = $update;
    62 				$result[]          = $update;
    52 			}
    63 			}
    53 		} else {
    64 		} else {
    54 			if ( $options['available'] ) {
    65 			if ( $options['available'] ) {
    55 				$update->dismissed = false;
    66 				$update->dismissed = false;
    56 				$result[] = $update;
    67 				$result[]          = $update;
    57 			}
    68 			}
    58 		}
    69 		}
    59 	}
    70 	}
    60 	return $result;
    71 	return $result;
    61 }
    72 }
    69  *
    80  *
    70  * @return array|false False on failure, otherwise the core update offering.
    81  * @return array|false False on failure, otherwise the core update offering.
    71  */
    82  */
    72 function find_core_auto_update() {
    83 function find_core_auto_update() {
    73 	$updates = get_site_transient( 'update_core' );
    84 	$updates = get_site_transient( 'update_core' );
    74 	if ( ! $updates || empty( $updates->updates ) )
    85 	if ( ! $updates || empty( $updates->updates ) ) {
    75 		return false;
    86 		return false;
       
    87 	}
    76 
    88 
    77 	include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    89 	include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    78 
    90 
    79 	$auto_update = false;
    91 	$auto_update = false;
    80 	$upgrader = new WP_Automatic_Updater;
    92 	$upgrader    = new WP_Automatic_Updater;
    81 	foreach ( $updates->updates as $update ) {
    93 	foreach ( $updates->updates as $update ) {
    82 		if ( 'autoupdate' != $update->response )
    94 		if ( 'autoupdate' != $update->response ) {
    83 			continue;
    95 			continue;
    84 
    96 		}
    85 		if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) )
    97 
       
    98 		if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) {
    86 			continue;
    99 			continue;
    87 
   100 		}
    88 		if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) )
   101 
       
   102 		if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) {
    89 			$auto_update = $update;
   103 			$auto_update = $update;
       
   104 		}
    90 	}
   105 	}
    91 	return $auto_update;
   106 	return $auto_update;
    92 }
   107 }
    93 
   108 
    94 /**
   109 /**
   101  * @return bool|array False on failure. An array of checksums on success.
   116  * @return bool|array False on failure. An array of checksums on success.
   102  */
   117  */
   103 function get_core_checksums( $version, $locale ) {
   118 function get_core_checksums( $version, $locale ) {
   104 	$url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
   119 	$url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' );
   105 
   120 
   106 	if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
   121 	if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
   107 		$url = set_url_scheme( $url, 'https' );
   122 		$url = set_url_scheme( $url, 'https' );
       
   123 	}
   108 
   124 
   109 	$options = array(
   125 	$options = array(
   110 		'timeout' => wp_doing_cron() ? 30 : 3,
   126 		'timeout' => wp_doing_cron() ? 30 : 3,
   111 	);
   127 	);
   112 
   128 
   121 			headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
   137 			headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
   122 		);
   138 		);
   123 		$response = wp_remote_get( $http_url, $options );
   139 		$response = wp_remote_get( $http_url, $options );
   124 	}
   140 	}
   125 
   141 
   126 	if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
   142 	if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
   127 		return false;
   143 		return false;
       
   144 	}
   128 
   145 
   129 	$body = trim( wp_remote_retrieve_body( $response ) );
   146 	$body = trim( wp_remote_retrieve_body( $response ) );
   130 	$body = json_decode( $body, true );
   147 	$body = json_decode( $body, true );
   131 
   148 
   132 	if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) )
   149 	if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) {
   133 		return false;
   150 		return false;
       
   151 	}
   134 
   152 
   135 	return $body['checksums'];
   153 	return $body['checksums'];
   136 }
   154 }
   137 
   155 
   138 /**
   156 /**
   139  *
       
   140  * @param object $update
   157  * @param object $update
   141  * @return bool
   158  * @return bool
   142  */
   159  */
   143 function dismiss_core_update( $update ) {
   160 function dismiss_core_update( $update ) {
   144 	$dismissed = get_site_option( 'dismissed_update_core' );
   161 	$dismissed = get_site_option( 'dismissed_update_core' );
   145 	$dismissed[ $update->current . '|' . $update->locale ] = true;
   162 	$dismissed[ $update->current . '|' . $update->locale ] = true;
   146 	return update_site_option( 'dismissed_update_core', $dismissed );
   163 	return update_site_option( 'dismissed_update_core', $dismissed );
   147 }
   164 }
   148 
   165 
   149 /**
   166 /**
   150  *
       
   151  * @param string $version
   167  * @param string $version
   152  * @param string $locale
   168  * @param string $locale
   153  * @return bool
   169  * @return bool
   154  */
   170  */
   155 function undismiss_core_update( $version, $locale ) {
   171 function undismiss_core_update( $version, $locale ) {
   156 	$dismissed = get_site_option( 'dismissed_update_core' );
   172 	$dismissed = get_site_option( 'dismissed_update_core' );
   157 	$key = $version . '|' . $locale;
   173 	$key       = $version . '|' . $locale;
   158 
   174 
   159 	if ( ! isset( $dismissed[$key] ) )
   175 	if ( ! isset( $dismissed[ $key ] ) ) {
   160 		return false;
   176 		return false;
   161 
   177 	}
   162 	unset( $dismissed[$key] );
   178 
       
   179 	unset( $dismissed[ $key ] );
   163 	return update_site_option( 'dismissed_update_core', $dismissed );
   180 	return update_site_option( 'dismissed_update_core', $dismissed );
   164 }
   181 }
   165 
   182 
   166 /**
   183 /**
   167  *
       
   168  * @param string $version
   184  * @param string $version
   169  * @param string $locale
   185  * @param string $locale
   170  * @return object|false
   186  * @return object|false
   171  */
   187  */
   172 function find_core_update( $version, $locale ) {
   188 function find_core_update( $version, $locale ) {
   173 	$from_api = get_site_transient( 'update_core' );
   189 	$from_api = get_site_transient( 'update_core' );
   174 
   190 
   175 	if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) )
   191 	if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) {
   176 		return false;
   192 		return false;
       
   193 	}
   177 
   194 
   178 	$updates = $from_api->updates;
   195 	$updates = $from_api->updates;
   179 	foreach ( $updates as $update ) {
   196 	foreach ( $updates as $update ) {
   180 		if ( $update->current == $version && $update->locale == $locale )
   197 		if ( $update->current == $version && $update->locale == $locale ) {
   181 			return $update;
   198 			return $update;
       
   199 		}
   182 	}
   200 	}
   183 	return false;
   201 	return false;
   184 }
   202 }
   185 
   203 
   186 /**
   204 /**
   187  *
       
   188  * @param string $msg
   205  * @param string $msg
   189  * @return string
   206  * @return string
   190  */
   207  */
   191 function core_update_footer( $msg = '' ) {
   208 function core_update_footer( $msg = '' ) {
   192 	if ( !current_user_can('update_core') )
   209 	if ( ! current_user_can( 'update_core' ) ) {
   193 		return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
   210 		return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
       
   211 	}
   194 
   212 
   195 	$cur = get_preferred_from_update_core();
   213 	$cur = get_preferred_from_update_core();
   196 	if ( ! is_object( $cur ) )
   214 	if ( ! is_object( $cur ) ) {
   197 		$cur = new stdClass;
   215 		$cur = new stdClass;
   198 
   216 	}
   199 	if ( ! isset( $cur->current ) )
   217 
       
   218 	if ( ! isset( $cur->current ) ) {
   200 		$cur->current = '';
   219 		$cur->current = '';
   201 
   220 	}
   202 	if ( ! isset( $cur->url ) )
   221 
       
   222 	if ( ! isset( $cur->url ) ) {
   203 		$cur->url = '';
   223 		$cur->url = '';
   204 
   224 	}
   205 	if ( ! isset( $cur->response ) )
   225 
       
   226 	if ( ! isset( $cur->response ) ) {
   206 		$cur->response = '';
   227 		$cur->response = '';
       
   228 	}
   207 
   229 
   208 	switch ( $cur->response ) {
   230 	switch ( $cur->response ) {
   209 	case 'development' :
   231 		case 'development':
   210 		/* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */
   232 			/* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */
   211 		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' ) );
   233 			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' ) );
   212 
   234 
   213 	case 'upgrade' :
   235 		case 'upgrade':
   214 		return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>';
   236 			return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>';
   215 
   237 
   216 	case 'latest' :
   238 		case 'latest':
   217 	default :
   239 		default:
   218 		return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
   240 			return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) );
   219 	}
   241 	}
   220 }
   242 }
   221 
   243 
   222 /**
   244 /**
   223  *
       
   224  * @global string $pagenow
   245  * @global string $pagenow
   225  * @return false|void
   246  * @return false|void
   226  */
   247  */
   227 function update_nag() {
   248 function update_nag() {
   228 	if ( is_multisite() && !current_user_can('update_core') )
   249 	if ( is_multisite() && ! current_user_can( 'update_core' ) ) {
   229 		return false;
   250 		return false;
       
   251 	}
   230 
   252 
   231 	global $pagenow;
   253 	global $pagenow;
   232 
   254 
   233 	if ( 'update-core.php' == $pagenow )
   255 	if ( 'update-core.php' == $pagenow ) {
   234 		return;
   256 		return;
       
   257 	}
   235 
   258 
   236 	$cur = get_preferred_from_update_core();
   259 	$cur = get_preferred_from_update_core();
   237 
   260 
   238 	if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
   261 	if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) {
   239 		return false;
   262 		return false;
       
   263 	}
       
   264 
       
   265 	$version_url = sprintf(
       
   266 		/* translators: %s: WordPress version */
       
   267 		esc_url( __( 'https://wordpress.org/support/wordpress-version/version-%s/' ) ),
       
   268 		sanitize_title( $cur->current )
       
   269 	);
   240 
   270 
   241 	if ( current_user_can( 'update_core' ) ) {
   271 	if ( current_user_can( 'update_core' ) ) {
   242 		$msg = sprintf(
   272 		$msg = sprintf(
   243 			/* translators: 1: Codex URL to release notes, 2: new WordPress version, 3: URL to network admin, 4: accessibility text */
   273 			/* translators: 1: URL to WordPress release notes, 2: new WordPress version, 3: URL to network admin, 4: accessibility text */
   244 			__( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
   274 			__( '<a href="%1$s">WordPress %2$s</a> is available! <a href="%3$s" aria-label="%4$s">Please update now</a>.' ),
   245 			sprintf(
   275 			$version_url,
   246 				/* translators: %s: WordPress version */
       
   247 				esc_url( __( 'https://codex.wordpress.org/Version_%s' ) ),
       
   248 				$cur->current
       
   249 			),
       
   250 			$cur->current,
   276 			$cur->current,
   251 			network_admin_url( 'update-core.php' ),
   277 			network_admin_url( 'update-core.php' ),
   252 			esc_attr__( 'Please update WordPress now' )
   278 			esc_attr__( 'Please update WordPress now' )
   253 		);
   279 		);
   254 	} else {
   280 	} else {
   255 		$msg = sprintf(
   281 		$msg = sprintf(
   256 			/* translators: 1: Codex URL to release notes, 2: new WordPress version */
   282 			/* translators: 1: URL to WordPress release notes, 2: new WordPress version */
   257 			__( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
   283 			__( '<a href="%1$s">WordPress %2$s</a> is available! Please notify the site administrator.' ),
   258 			sprintf(
   284 			$version_url,
   259 				/* translators: %s: WordPress version */
       
   260 				esc_url( __( 'https://codex.wordpress.org/Version_%s' ) ),
       
   261 				$cur->current
       
   262 			),
       
   263 			$cur->current
   285 			$cur->current
   264 		);
   286 		);
   265 	}
   287 	}
   266 	echo "<div class='update-nag'>$msg</div>";
   288 	echo "<div class='update-nag'>$msg</div>";
   267 }
   289 }
   273 		$theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
   295 		$theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme_name );
   274 	}
   296 	}
   275 
   297 
   276 	$msg = '';
   298 	$msg = '';
   277 
   299 
   278 	if ( current_user_can('update_core') ) {
   300 	if ( current_user_can( 'update_core' ) ) {
   279 		$cur = get_preferred_from_update_core();
   301 		$cur = get_preferred_from_update_core();
   280 
   302 
   281 		if ( isset( $cur->response ) && $cur->response == 'upgrade' )
   303 		if ( isset( $cur->response ) && $cur->response == 'upgrade' ) {
   282 			$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> ';
   304 			$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> ';
       
   305 		}
   283 	}
   306 	}
   284 
   307 
   285 	/* translators: 1: version number, 2: theme name */
   308 	/* translators: 1: version number, 2: theme name */
   286 	$content = __( 'WordPress %1$s running %2$s theme.' );
   309 	$content = __( 'WordPress %1$s running %2$s theme.' );
   287 
   310 
   305  * @since 2.9.0
   328  * @since 2.9.0
   306  *
   329  *
   307  * @return array
   330  * @return array
   308  */
   331  */
   309 function get_plugin_updates() {
   332 function get_plugin_updates() {
   310 	$all_plugins = get_plugins();
   333 	$all_plugins     = get_plugins();
   311 	$upgrade_plugins = array();
   334 	$upgrade_plugins = array();
   312 	$current = get_site_transient( 'update_plugins' );
   335 	$current         = get_site_transient( 'update_plugins' );
   313 	foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {
   336 	foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) {
   314 		if ( isset( $current->response[ $plugin_file ] ) ) {
   337 		if ( isset( $current->response[ $plugin_file ] ) ) {
   315 			$upgrade_plugins[ $plugin_file ] = (object) $plugin_data;
   338 			$upgrade_plugins[ $plugin_file ]         = (object) $plugin_data;
   316 			$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
   339 			$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ];
   317 		}
   340 		}
   318 	}
   341 	}
   319 
   342 
   320 	return $upgrade_plugins;
   343 	return $upgrade_plugins;
   322 
   345 
   323 /**
   346 /**
   324  * @since 2.9.0
   347  * @since 2.9.0
   325  */
   348  */
   326 function wp_plugin_update_rows() {
   349 function wp_plugin_update_rows() {
   327 	if ( !current_user_can('update_plugins' ) )
   350 	if ( ! current_user_can( 'update_plugins' ) ) {
   328 		return;
   351 		return;
       
   352 	}
   329 
   353 
   330 	$plugins = get_site_transient( 'update_plugins' );
   354 	$plugins = get_site_transient( 'update_plugins' );
   331 	if ( isset($plugins->response) && is_array($plugins->response) ) {
   355 	if ( isset( $plugins->response ) && is_array( $plugins->response ) ) {
   332 		$plugins = array_keys( $plugins->response );
   356 		$plugins = array_keys( $plugins->response );
   333 		foreach ( $plugins as $plugin_file ) {
   357 		foreach ( $plugins as $plugin_file ) {
   334 			add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 );
   358 			add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 );
   335 		}
   359 		}
   336 	}
   360 	}
   350 	}
   374 	}
   351 
   375 
   352 	$response = $current->response[ $file ];
   376 	$response = $current->response[ $file ];
   353 
   377 
   354 	$plugins_allowedtags = array(
   378 	$plugins_allowedtags = array(
   355 		'a'       => array( 'href' => array(), 'title' => array() ),
   379 		'a'       => array(
       
   380 			'href'  => array(),
       
   381 			'title' => array(),
       
   382 		),
   356 		'abbr'    => array( 'title' => array() ),
   383 		'abbr'    => array( 'title' => array() ),
   357 		'acronym' => array( 'title' => array() ),
   384 		'acronym' => array( 'title' => array() ),
   358 		'code'    => array(),
   385 		'code'    => array(),
   359 		'em'      => array(),
   386 		'em'      => array(),
   360 		'strong'  => array(),
   387 		'strong'  => array(),
   361 	);
   388 	);
   362 
   389 
   363 	$plugin_name   = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
   390 	$plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
   364 	$details_url   = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
   391 	$details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
   365 
   392 
   366 	/** @var WP_Plugins_List_Table $wp_list_table */
   393 	/** @var WP_Plugins_List_Table $wp_list_table */
   367 	$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
   394 	$wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
   368 
   395 
   369 	if ( is_network_admin() || ! is_multisite() ) {
   396 	if ( is_network_admin() || ! is_multisite() ) {
   371 			$active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
   398 			$active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
   372 		} else {
   399 		} else {
   373 			$active_class = is_plugin_active( $file ) ? ' active' : '';
   400 			$active_class = is_plugin_active( $file ) ? ' active' : '';
   374 		}
   401 		}
   375 
   402 
   376 		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>';
   403 		$requires_php   = isset( $response->requires_php ) ? $response->requires_php : null;
       
   404 		$compatible_php = is_php_version_compatible( $requires_php );
       
   405 		$notice_type    = $compatible_php ? 'notice-warning' : 'notice-error';
       
   406 
       
   407 		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_type . ' notice-alt"><p>';
   377 
   408 
   378 		if ( ! current_user_can( 'update_plugins' ) ) {
   409 		if ( ! current_user_can( 'update_plugins' ) ) {
   379 			/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
   410 			/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
   380 			printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
   411 			printf(
       
   412 				__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
   381 				$plugin_name,
   413 				$plugin_name,
   382 				esc_url( $details_url ),
   414 				esc_url( $details_url ),
   383 				sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
   415 				sprintf(
       
   416 					'class="thickbox open-plugin-details-modal" aria-label="%s"',
   384 					/* translators: 1: plugin name, 2: version number */
   417 					/* translators: 1: plugin name, 2: version number */
   385 					esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
   418 					esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
   386 				),
   419 				),
   387 				$response->new_version
   420 				esc_attr( $response->new_version )
   388 			);
   421 			);
   389 		} elseif ( empty( $response->package ) ) {
   422 		} elseif ( empty( $response->package ) ) {
   390 			/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
   423 			/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */
   391 			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>' ),
   424 			printf(
       
   425 				__( '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>' ),
   392 				$plugin_name,
   426 				$plugin_name,
   393 				esc_url( $details_url ),
   427 				esc_url( $details_url ),
   394 				sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
   428 				sprintf(
       
   429 					'class="thickbox open-plugin-details-modal" aria-label="%s"',
   395 					/* translators: 1: plugin name, 2: version number */
   430 					/* translators: 1: plugin name, 2: version number */
   396 					esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
   431 					esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
   397 				),
   432 				),
   398 				$response->new_version
   433 				esc_attr( $response->new_version )
   399 			);
   434 			);
   400 		} else {
   435 		} else {
   401 			/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
   436 			if ( $compatible_php ) {
   402 			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>.' ),
   437 				/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
   403 				$plugin_name,
   438 				printf(
   404 				esc_url( $details_url ),
   439 					__( '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 				sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
   440 					$plugin_name,
   406 					/* translators: 1: plugin name, 2: version number */
   441 					esc_url( $details_url ),
   407 					esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
   442 					sprintf(
   408 				),
   443 						'class="thickbox open-plugin-details-modal" aria-label="%s"',
   409 				$response->new_version,
   444 						/* translators: 1: plugin name, 2: version number */
   410 				wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
   445 						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
   411 				sprintf( 'class="update-link" aria-label="%s"',
   446 					),
   412 					/* translators: %s: plugin name */
   447 					esc_attr( $response->new_version ),
   413 					esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
   448 					wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ),
   414 				)
   449 					sprintf(
   415 			);
   450 						'class="update-link" aria-label="%s"',
       
   451 						/* translators: %s: plugin name */
       
   452 						esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) )
       
   453 					)
       
   454 				);
       
   455 			} else {
       
   456 				/* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number 5: Update PHP page URL */
       
   457 				printf(
       
   458 					__( '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>.' ),
       
   459 					$plugin_name,
       
   460 					esc_url( $details_url ),
       
   461 					sprintf(
       
   462 						'class="thickbox open-plugin-details-modal" aria-label="%s"',
       
   463 						/* translators: 1: plugin name, 2: version number */
       
   464 						esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) )
       
   465 					),
       
   466 					esc_attr( $response->new_version ),
       
   467 					esc_url( wp_get_update_php_url() )
       
   468 				);
       
   469 				wp_update_php_annotation( '<br><em>', '</em>' );
       
   470 			}
   416 		}
   471 		}
   417 
   472 
   418 		/**
   473 		/**
   419 		 * Fires at the end of the update message container in each
   474 		 * Fires at the end of the update message container in each
   420 		 * row of the plugins list table.
   475 		 * row of the plugins list table.
   455 		echo '</p></div></td></tr>';
   510 		echo '</p></div></td></tr>';
   456 	}
   511 	}
   457 }
   512 }
   458 
   513 
   459 /**
   514 /**
   460  *
       
   461  * @return array
   515  * @return array
   462  */
   516  */
   463 function get_theme_updates() {
   517 function get_theme_updates() {
   464 	$current = get_site_transient('update_themes');
   518 	$current = get_site_transient( 'update_themes' );
   465 
   519 
   466 	if ( ! isset( $current->response ) )
   520 	if ( ! isset( $current->response ) ) {
   467 		return array();
   521 		return array();
       
   522 	}
   468 
   523 
   469 	$update_themes = array();
   524 	$update_themes = array();
   470 	foreach ( $current->response as $stylesheet => $data ) {
   525 	foreach ( $current->response as $stylesheet => $data ) {
   471 		$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
   526 		$update_themes[ $stylesheet ]         = wp_get_theme( $stylesheet );
   472 		$update_themes[ $stylesheet ]->update = $data;
   527 		$update_themes[ $stylesheet ]->update = $data;
   473 	}
   528 	}
   474 
   529 
   475 	return $update_themes;
   530 	return $update_themes;
   476 }
   531 }
   477 
   532 
   478 /**
   533 /**
   479  * @since 3.1.0
   534  * @since 3.1.0
   480  */
   535  */
   481 function wp_theme_update_rows() {
   536 function wp_theme_update_rows() {
   482 	if ( !current_user_can('update_themes' ) )
   537 	if ( ! current_user_can( 'update_themes' ) ) {
   483 		return;
   538 		return;
       
   539 	}
   484 
   540 
   485 	$themes = get_site_transient( 'update_themes' );
   541 	$themes = get_site_transient( 'update_themes' );
   486 	if ( isset($themes->response) && is_array($themes->response) ) {
   542 	if ( isset( $themes->response ) && is_array( $themes->response ) ) {
   487 		$themes = array_keys( $themes->response );
   543 		$themes = array_keys( $themes->response );
   488 
   544 
   489 		foreach ( $themes as $theme ) {
   545 		foreach ( $themes as $theme ) {
   490 			add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 );
   546 			add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 );
   491 		}
   547 		}
   506 		return false;
   562 		return false;
   507 	}
   563 	}
   508 
   564 
   509 	$response = $current->response[ $theme_key ];
   565 	$response = $current->response[ $theme_key ];
   510 
   566 
   511 	$details_url = add_query_arg( array(
   567 	$details_url = add_query_arg(
   512 		'TB_iframe' => 'true',
   568 		array(
   513 		'width'     => 1024,
   569 			'TB_iframe' => 'true',
   514 		'height'    => 800,
   570 			'width'     => 1024,
   515 	), $current->response[ $theme_key ]['url'] );
   571 			'height'    => 800,
       
   572 		),
       
   573 		$current->response[ $theme_key ]['url']
       
   574 	);
   516 
   575 
   517 	/** @var WP_MS_Themes_List_Table $wp_list_table */
   576 	/** @var WP_MS_Themes_List_Table $wp_list_table */
   518 	$wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
   577 	$wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
   519 
   578 
   520 	$active = $theme->is_allowed( 'network' ) ? ' active' : '';
   579 	$active = $theme->is_allowed( 'network' ) ? ' active' : '';
   521 
   580 
   522 	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>';
   581 	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>';
   523 	if ( ! current_user_can( 'update_themes' ) ) {
   582 	if ( ! current_user_can( 'update_themes' ) ) {
   524 		/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
   583 		/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
   525 		printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.'),
   584 		printf(
       
   585 			__( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ),
   526 			$theme['Name'],
   586 			$theme['Name'],
   527 			esc_url( $details_url ),
   587 			esc_url( $details_url ),
   528 			sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
   588 			sprintf(
       
   589 				'class="thickbox open-plugin-details-modal" aria-label="%s"',
   529 				/* translators: 1: theme name, 2: version number */
   590 				/* translators: 1: theme name, 2: version number */
   530 				esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
   591 				esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
   531 			),
   592 			),
   532 			$response['new_version']
   593 			$response['new_version']
   533 		);
   594 		);
   534 	} elseif ( empty( $response['package'] ) ) {
   595 	} elseif ( empty( $response['package'] ) ) {
   535 		/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
   596 		/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */
   536 		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>' ),
   597 		printf(
       
   598 			__( '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>' ),
   537 			$theme['Name'],
   599 			$theme['Name'],
   538 			esc_url( $details_url ),
   600 			esc_url( $details_url ),
   539 			sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
   601 			sprintf(
       
   602 				'class="thickbox open-plugin-details-modal" aria-label="%s"',
   540 				/* translators: 1: theme name, 2: version number */
   603 				/* translators: 1: theme name, 2: version number */
   541 				esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
   604 				esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
   542 			),
   605 			),
   543 			$response['new_version']
   606 			$response['new_version']
   544 		);
   607 		);
   545 	} else {
   608 	} else {
   546 		/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
   609 		/* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */
   547 		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>.' ),
   610 		printf(
       
   611 			__( '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>.' ),
   548 			$theme['Name'],
   612 			$theme['Name'],
   549 			esc_url( $details_url ),
   613 			esc_url( $details_url ),
   550 			sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"',
   614 			sprintf(
       
   615 				'class="thickbox open-plugin-details-modal" aria-label="%s"',
   551 				/* translators: 1: theme name, 2: version number */
   616 				/* translators: 1: theme name, 2: version number */
   552 				esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
   617 				esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) )
   553 			),
   618 			),
   554 			$response['new_version'],
   619 			$response['new_version'],
   555 			wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
   620 			wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ),
   556 			sprintf( 'class="update-link" aria-label="%s"',
   621 			sprintf(
       
   622 				'class="update-link" aria-label="%s"',
   557 				/* translators: %s: theme name */
   623 				/* translators: %s: theme name */
   558 				esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
   624 				esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) )
   559 			)
   625 			)
   560 		);
   626 		);
   561 	}
   627 	}
   582 
   648 
   583 	echo '</p></div></td></tr>';
   649 	echo '</p></div></td></tr>';
   584 }
   650 }
   585 
   651 
   586 /**
   652 /**
   587  *
       
   588  * @global int $upgrading
   653  * @global int $upgrading
   589  * @return false|void
   654  * @return false|void
   590  */
   655  */
   591 function maintenance_nag() {
   656 function maintenance_nag() {
   592 	include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
   657 	include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
   603 		 * OK if they are now running the latest.
   668 		 * OK if they are now running the latest.
   604 		 *
   669 		 *
   605 		 * This flag is cleared whenever a successful update occurs using Core_Upgrader.
   670 		 * This flag is cleared whenever a successful update occurs using Core_Upgrader.
   606 		 */
   671 		 */
   607 		$comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
   672 		$comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
   608 		if ( version_compare( $failed['attempted'], $wp_version, $comparison ) )
   673 		if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) {
   609 			$nag = true;
   674 			$nag = true;
   610 	}
   675 		}
   611 
   676 	}
   612 	if ( ! $nag )
   677 
   613 		return false;
   678 	if ( ! $nag ) {
   614 
   679 		return false;
   615 	if ( current_user_can('update_core') )
   680 	}
   616 		$msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' );
   681 
   617 	else
   682 	if ( current_user_can( 'update_core' ) ) {
   618 		$msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.');
   683 		$msg = sprintf( __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ), 'update-core.php' );
       
   684 	} else {
       
   685 		$msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' );
       
   686 	}
   619 
   687 
   620 	echo "<div class='update-nag'>$msg</div>";
   688 	echo "<div class='update-nag'>$msg</div>";
   621 }
   689 }
   622 
   690 
   623 /**
   691 /**
   760 			</td>
   828 			</td>
   761 		</tr>
   829 		</tr>
   762 	</script>
   830 	</script>
   763 	<?php
   831 	<?php
   764 }
   832 }
       
   833 
       
   834 /**
       
   835  * Displays a notice when the user is in recovery mode.
       
   836  *
       
   837  * @since 5.2.0
       
   838  */
       
   839 function wp_recovery_mode_nag() {
       
   840 	if ( ! wp_is_recovery_mode() ) {
       
   841 		return;
       
   842 	}
       
   843 
       
   844 	$url = wp_login_url();
       
   845 	$url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
       
   846 	$url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
       
   847 
       
   848 	?>
       
   849 	<div class="notice notice-info">
       
   850 		<p>
       
   851 			<?php
       
   852 			printf(
       
   853 				/* translators: %s: Recovery Mode exit link */
       
   854 				__( '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>' ),
       
   855 				esc_url( $url )
       
   856 			);
       
   857 			?>
       
   858 		</p>
       
   859 	</div>
       
   860 	<?php
       
   861 }