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