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