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