wp/wp-includes/update.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * A simple set of functions to check our version 1.0 update service.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Check WordPress version against the newest version.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * The WordPress version, PHP version, and Locale is sent. Checks against the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * WordPress server at api.wordpress.org server. Will only check if WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * isn't installing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @since 2.3.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 * @global string $wp_version Used to check against the newest WordPress version.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
 * @global wpdb   $wpdb
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
 * @global string $wp_local_package
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    22
 * @param bool  $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
function wp_version_check( $extra_stats = array(), $force_check = false ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    25
	if ( wp_installing() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		return;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    27
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	global $wpdb, $wp_local_package;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    30
	// include an unmodified $wp_version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    31
	include( ABSPATH . WPINC . '/version.php' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	$php_version = phpversion();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	$current = get_site_transient( 'update_core' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	$translations = wp_get_installed_translations( 'core' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
	// Invalidate the transient when $wp_version changes
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
	if ( is_object( $current ) && $wp_version != $current->version_checked )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
		$current = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	if ( ! is_object($current) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
		$current = new stdClass;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		$current->updates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
		$current->version_checked = $wp_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
	if ( ! empty( $extra_stats ) )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
		$force_check = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	// Wait 60 seconds between multiple version check requests
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	$timeout = 60;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    53
	if ( ! $force_check && $time_not_changed ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    54
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    55
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    58
	 * Filters the locale requested for WordPress core translations.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	 * @param string $locale Current locale.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    64
	$locale = apply_filters( 'core_version_check_locale', get_locale() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	// Update last_checked for current to prevent multiple blocking requests if request hangs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	$current->last_checked = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	set_site_transient( 'update_core', $current );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	if ( method_exists( $wpdb, 'db_version' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		$mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
	else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		$mysql_version = 'N/A';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
	if ( is_multisite() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
		$user_count = get_user_count();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		$num_blogs = get_blog_count();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
		$wp_install = network_site_url();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		$multisite_enabled = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		$user_count = count_users();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		$user_count = $user_count['total_users'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
		$multisite_enabled = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		$num_blogs = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		$wp_install = home_url( '/' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	$query = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
		'version'            => $wp_version,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
		'php'                => $php_version,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
		'locale'             => $locale,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
		'mysql'              => $mysql_version,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
		'local_package'      => isset( $wp_local_package ) ? $wp_local_package : '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
		'blogs'              => $num_blogs,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
		'users'              => $user_count,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
		'multisite_enabled'  => $multisite_enabled,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
		'initial_db_version' => get_site_option( 'initial_db_version' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
	 * Filter the query arguments sent as part of the core version check.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
	 * WARNING: Changing this data may result in your site not receiving security updates.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
	 * Please exercise extreme caution.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
	 * @since 4.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   108
	 * @param array $query {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
	 *     Version check query arguments. 
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   110
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
	 *     @type string $version            WordPress version number.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   112
	 *     @type string $php                PHP version number.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   113
	 *     @type string $locale             The locale to retrieve updates for.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   114
	 *     @type string $mysql              MySQL version number.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   115
	 *     @type string $local_package      The value of the $wp_local_package global, when set.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   116
	 *     @type int    $blogs              Number of sites on this WordPress installation.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   117
	 *     @type int    $users              Number of users on this WordPress installation.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   118
	 *     @type int    $multisite_enabled  Whether this WordPress installation uses Multisite.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   119
	 *     @type int    $initial_db_version Database version of WordPress at time of installation.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   120
	 * }
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   121
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   122
	$query = apply_filters( 'core_version_check_query_args', $query );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	$post_body = array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
		'translations' => wp_json_encode( $translations ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
	if ( is_array( $extra_stats ) )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		$post_body = array_merge( $post_body, $extra_stats );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	$url = $http_url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		$url = set_url_scheme( $url, 'https' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   135
	$doing_cron = wp_doing_cron();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   136
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
	$options = array(
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
		'timeout' => $doing_cron ? 30 : 3,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		'headers' => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
			'wp_install' => $wp_install,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
			'wp_blog' => home_url( '/' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		'body' => $post_body,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	$response = wp_remote_post( $url, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	if ( $ssl && is_wp_error( $response ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
		trigger_error(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
			sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
				/* translators: %s: support forums URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   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>.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   153
				__( 'https://wordpress.org/support/' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   154
			) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   155
			headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   156
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		$response = wp_remote_post( $http_url, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   160
	if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   161
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	$body = trim( wp_remote_retrieve_body( $response ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	$body = json_decode( $body, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   167
	if ( ! is_array( $body ) || ! isset( $body['offers'] ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   168
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   169
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
	$offers = $body['offers'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	foreach ( $offers as &$offer ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		foreach ( $offer as $offer_key => $value ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
			if ( 'packages' == $offer_key )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
				$offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
					array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
			elseif ( 'download' == $offer_key )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
				$offer['download'] = esc_url( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
				$offer[ $offer_key ] = esc_html( $value );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
		$offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
			'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email', 'support_email', 'new_files' ), '' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	$updates = new stdClass();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
	$updates->updates = $offers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	$updates->last_checked = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
	$updates->version_checked = $wp_version;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	if ( isset( $body['translations'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		$updates->translations = $body['translations'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
	set_site_transient( 'update_core', $updates );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
	if ( ! empty( $body['ttl'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
		$ttl = (int) $body['ttl'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
		if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
			// Queue an event to re-run the update check in $ttl seconds.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
			wp_schedule_single_event( time() + $ttl, 'wp_version_check' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   205
	// Trigger background updates if running non-interactively, and we weren't called from the update handler.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
	if ( $doing_cron && ! doing_action( 'wp_maybe_auto_update' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
		do_action( 'wp_maybe_auto_update' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
 * Check plugin versions against the latest versions hosted on WordPress.org.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 * The WordPress version, PHP version, and Locale is sent along with a list of
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 * all plugins installed. Checks against the WordPress server at
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 * api.wordpress.org. Will only check if WordPress isn't installing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
 * @since 2.3.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   219
 * @global string $wp_version Used to notify the WordPress version.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
function wp_update_plugins( $extra_stats = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   224
	if ( wp_installing() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   225
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   226
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   228
	// include an unmodified $wp_version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   229
	include( ABSPATH . WPINC . '/version.php' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	// If running blog-side, bail unless we've not checked in the last 12 hours
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	if ( !function_exists( 'get_plugins' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
		require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	$plugins = get_plugins();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
	$translations = wp_get_installed_translations( 'plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	$active  = get_option( 'active_plugins', array() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	$current = get_site_transient( 'update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	if ( ! is_object($current) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
		$current = new stdClass;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
	$new_option = new stdClass;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	$new_option->last_checked = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   246
	$doing_cron = wp_doing_cron();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   247
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	// Check for update on a different schedule, depending on the page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	switch ( current_filter() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		case 'upgrader_process_complete' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			$timeout = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		case 'load-update-core.php' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
			$timeout = MINUTE_IN_SECONDS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		case 'load-plugins.php' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		case 'load-update.php' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
			$timeout = HOUR_IN_SECONDS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		default :
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   261
			if ( $doing_cron ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   262
				$timeout = 2 * HOUR_IN_SECONDS;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
				$timeout = 12 * HOUR_IN_SECONDS;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
	if ( $time_not_changed && ! $extra_stats ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
		$plugin_changed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		foreach ( $plugins as $file => $p ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
			$new_option->checked[ $file ] = $p['Version'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
			if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
				$plugin_changed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		if ( isset ( $current->response ) && is_array( $current->response ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			foreach ( $current->response as $plugin_file => $update_details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
				if ( ! isset($plugins[ $plugin_file ]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
					$plugin_changed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
		// Bail if we've checked recently and if nothing has changed
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   289
		if ( ! $plugin_changed ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   290
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   291
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	// Update last_checked for current to prevent multiple blocking requests if request hangs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
	$current->last_checked = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
	set_site_transient( 'update_plugins', $current );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
	$to_send = compact( 'plugins', 'active' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   300
	$locales = array_values( get_available_languages() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   301
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   303
	 * Filters the locales requested for plugin translations.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	 * @since 3.7.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   306
	 * @since 4.5.0 The default value of the `$locales` parameter changed to include all locales.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   308
	 * @param array $locales Plugin locales. Default is all available locales of the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
	$locales = apply_filters( 'plugins_update_check_locales', $locales );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   311
	$locales = array_unique( $locales );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   313
	if ( $doing_cron ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
		$timeout = 30;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
		// Three seconds, plus one extra second for every 10 plugins
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
		$timeout = 3 + (int) ( count( $plugins ) / 10 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
	$options = array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
		'timeout' => $timeout,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		'body' => array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
			'plugins'      => wp_json_encode( $to_send ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
			'translations' => wp_json_encode( $translations ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
			'locale'       => wp_json_encode( $locales ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
			'all'          => wp_json_encode( true ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
		),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
		'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
	if ( $extra_stats ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
		$options['body']['update_stats'] = wp_json_encode( $extra_stats );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	$url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
		$url = set_url_scheme( $url, 'https' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
	$raw_response = wp_remote_post( $url, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
	if ( $ssl && is_wp_error( $raw_response ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   341
		trigger_error(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   342
			sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   343
				/* translators: %s: support forums URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   344
				__( '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>.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   345
				__( 'https://wordpress.org/support/' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   346
			) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   347
			headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   348
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		$raw_response = wp_remote_post( $http_url, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   352
	if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   353
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	$response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	foreach ( $response['plugins'] as &$plugin ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		$plugin = (object) $plugin;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
		if ( isset( $plugin->compatibility ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   360
			$plugin->compatibility = (object) $plugin->compatibility;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   361
			foreach ( $plugin->compatibility as &$data ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   362
				$data = (object) $data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   363
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
	unset( $plugin, $data );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	foreach ( $response['no_update'] as &$plugin ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
		$plugin = (object) $plugin;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
	unset( $plugin );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
	if ( is_array( $response ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
		$new_option->response = $response['plugins'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		$new_option->translations = $response['translations'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
		// TODO: Perhaps better to store no_update in a separate transient with an expiry?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
		$new_option->no_update = $response['no_update'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
		$new_option->response = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		$new_option->translations = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
		$new_option->no_update = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
	set_site_transient( 'update_plugins', $new_option );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
 * Check theme versions against the latest versions hosted on WordPress.org.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
 * A list of all themes installed in sent to WP. Checks against the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
 * WordPress server at api.wordpress.org. Will only check if WordPress isn't
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
 * installing.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
function wp_update_themes( $extra_stats = array() ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   398
	if ( wp_installing() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   400
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
	// include an unmodified $wp_version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
	include( ABSPATH . WPINC . '/version.php' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	$installed_themes = wp_get_themes();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	$translations = wp_get_installed_translations( 'themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
	$last_update = get_site_transient( 'update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	if ( ! is_object($last_update) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
		$last_update = new stdClass;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
	$themes = $checked = $request = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	// Put slug of current theme into request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	$request['active'] = get_option( 'stylesheet' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
	foreach ( $installed_themes as $theme ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
		$checked[ $theme->get_stylesheet() ] = $theme->get('Version');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
		$themes[ $theme->get_stylesheet() ] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
			'Name'       => $theme->get('Name'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
			'Title'      => $theme->get('Name'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
			'Version'    => $theme->get('Version'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
			'Author'     => $theme->get('Author'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
			'Author URI' => $theme->get('AuthorURI'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
			'Template'   => $theme->get_template(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
			'Stylesheet' => $theme->get_stylesheet(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   431
	$doing_cron = wp_doing_cron();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   432
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
	// Check for update on a different schedule, depending on the page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	switch ( current_filter() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		case 'upgrader_process_complete' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
			$timeout = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
		case 'load-update-core.php' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
			$timeout = MINUTE_IN_SECONDS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
		case 'load-themes.php' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
		case 'load-update.php' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
			$timeout = HOUR_IN_SECONDS;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
		default :
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   446
			if ( $doing_cron ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   447
				$timeout = 2 * HOUR_IN_SECONDS;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
				$timeout = 12 * HOUR_IN_SECONDS;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
	$time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
	if ( $time_not_changed && ! $extra_stats ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		$theme_changed = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
		foreach ( $checked as $slug => $v ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
			if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
				$theme_changed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
		if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			foreach ( $last_update->response as $slug => $update_details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
				if ( ! isset($checked[ $slug ]) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
					$theme_changed = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
		// Bail if we've checked recently and if nothing has changed
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   472
		if ( ! $theme_changed ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   473
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   474
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
	// Update last_checked for current to prevent multiple blocking requests if request hangs
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	$last_update->last_checked = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	set_site_transient( 'update_themes', $last_update );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	$request['themes'] = $themes;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   483
	$locales = array_values( get_available_languages() );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   484
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   486
	 * Filters the locales requested for theme translations.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	 * @since 3.7.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   489
	 * @since 4.5.0 The default value of the `$locales` parameter changed to include all locales.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   491
	 * @param array $locales Theme locales. Default is all available locales of the site.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
	$locales = apply_filters( 'themes_update_check_locales', $locales );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   494
	$locales = array_unique( $locales );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   496
	if ( $doing_cron ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
		$timeout = 30;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   499
		// Three seconds, plus one extra second for every 10 themes
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
		$timeout = 3 + (int) ( count( $themes ) / 10 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	$options = array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
		'timeout' => $timeout,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		'body' => array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
			'themes'       => wp_json_encode( $request ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
			'translations' => wp_json_encode( $translations ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
			'locale'       => wp_json_encode( $locales ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   510
		'user-agent'	=> 'WordPress/' . $wp_version . '; ' . home_url( '/' )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
	if ( $extra_stats ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
		$options['body']['update_stats'] = wp_json_encode( $extra_stats );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	$url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		$url = set_url_scheme( $url, 'https' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
	$raw_response = wp_remote_post( $url, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
	if ( $ssl && is_wp_error( $raw_response ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   523
		trigger_error(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   524
			sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   525
				/* translators: %s: support forums URL */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   526
				__( '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>.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   527
				__( 'https://wordpress.org/support/' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   528
			) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   529
			headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   530
		);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
		$raw_response = wp_remote_post( $http_url, $options );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   534
	if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   535
		return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   536
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	$new_update = new stdClass;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	$new_update->last_checked = time();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	$new_update->checked = $checked;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	$response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
	if ( is_array( $response ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
		$new_update->response     = $response['themes'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		$new_update->translations = $response['translations'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	set_site_transient( 'update_themes', $new_update );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
 * Performs WordPress automatic background updates.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
 * @since 3.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
function wp_maybe_auto_update() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
	include_once( ABSPATH . '/wp-admin/includes/admin.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
	include_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	$upgrader = new WP_Automatic_Updater;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
	$upgrader->run();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
 * Retrieves a list of all language updates available.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
 * @since 3.7.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   569
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   570
 * @return array
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
function wp_get_translation_updates() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	$updates = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
	$transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	foreach ( $transients as $transient => $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
		$transient = get_site_transient( $transient );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
		if ( empty( $transient->translations ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		foreach ( $transient->translations as $translation ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
			$updates[] = (object) $translation;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	return $updates;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
 * Collect counts and UI strings for available updates
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
 * @since 3.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
function wp_get_update_data() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	$counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
	if ( $plugins = current_user_can( 'update_plugins' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
		$update_plugins = get_site_transient( 'update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
		if ( ! empty( $update_plugins->response ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
			$counts['plugins'] = count( $update_plugins->response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	if ( $themes = current_user_can( 'update_themes' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
		$update_themes = get_site_transient( 'update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
		if ( ! empty( $update_themes->response ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
			$counts['themes'] = count( $update_themes->response );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
		$update_wordpress = get_core_updates( array('dismissed' => false) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
		if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
			$counts['wordpress'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
	if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
		$counts['translations'] = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
	$counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
	$titles = array();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   620
	if ( $counts['wordpress'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   621
		/* translators: 1: Number of updates available to WordPress */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
		$titles['wordpress'] = sprintf( __( '%d WordPress Update'), $counts['wordpress'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   623
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   624
	if ( $counts['plugins'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   625
		/* translators: 1: Number of updates available to plugins */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		$titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   627
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   628
	if ( $counts['themes'] ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   629
		/* translators: 1: Number of updates available to themes */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		$titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   631
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   632
	if ( $counts['translations'] ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
		$titles['translations'] = __( 'Translation Updates' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   634
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
	$update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
	$update_data = array( 'counts' => $counts, 'title' => $update_title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   640
	 * Filters the returned array of update data for plugins, themes, and WordPress core.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	 * @since 3.5.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	 * @param array $update_data {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
	 *     Fetched update data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	 *     @type array   $counts       An array of counts for available plugin, theme, and WordPress updates.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	 *     @type string  $update_title Titles of available updates.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	 * }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	 * @param array $titles An array of update counts and UI strings for available updates.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	return apply_filters( 'wp_get_update_data', $update_data, $titles );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   655
/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   656
 * Determines whether core should be updated.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   657
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   658
 * @since 2.8.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   659
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   660
 * @global string $wp_version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   661
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
function _maybe_update_core() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   663
	// include an unmodified $wp_version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   664
	include( ABSPATH . WPINC . '/version.php' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	$current = get_site_transient( 'update_core' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   668
	if ( isset( $current->last_checked, $current->version_checked ) &&
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
		12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) &&
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   670
		$current->version_checked == $wp_version ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
		return;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   672
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
	wp_version_check();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
 * Check the last time plugins were run before checking plugin versions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
 * This might have been backported to WordPress 2.6.1 for performance reasons.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
 * This is used for the wp-admin to check only so often instead of every page
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
 * load.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
function _maybe_update_plugins() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	$current = get_site_transient( 'update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
	if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
	wp_update_plugins();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
 * Check themes versions only after a duration of time.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
 * This is for performance reasons to make sure that on the theme version
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
 * checker is not run on every page load.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
function _maybe_update_themes() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
	$current = get_site_transient( 'update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
		return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	wp_update_themes();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
 * Schedule core, theme, and plugin update checks.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
function wp_schedule_update_checks() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   714
	if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		wp_schedule_event(time(), 'twicedaily', 'wp_version_check');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   717
	if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
		wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   720
	if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
		wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
 * Clear existing update caches for plugins, themes, and core.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
function wp_clean_update_cache() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
	if ( function_exists( 'wp_clean_plugins_cache' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   731
		wp_clean_plugins_cache();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   732
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   733
		delete_site_transient( 'update_plugins' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   735
	wp_clean_themes_cache();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
	delete_site_transient( 'update_core' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   738
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   739
if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
	return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   741
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
add_action( 'admin_init', '_maybe_update_core' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
add_action( 'wp_version_check', 'wp_version_check' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
add_action( 'load-plugins.php', 'wp_update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
add_action( 'load-update.php', 'wp_update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
add_action( 'load-update-core.php', 'wp_update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
add_action( 'admin_init', '_maybe_update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
add_action( 'wp_update_plugins', 'wp_update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
add_action( 'load-themes.php', 'wp_update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
add_action( 'load-update.php', 'wp_update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
add_action( 'load-update-core.php', 'wp_update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
add_action( 'admin_init', '_maybe_update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
add_action( 'wp_update_themes', 'wp_update_themes' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   758
add_action( 'update_option_WPLANG', 'wp_clean_update_cache' , 10, 0 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   762
add_action( 'init', 'wp_schedule_update_checks' );