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