1 | <?php |
---|
2 | function get_plugins($checked = null) { |
---|
3 | $obj = get_transient('sem_update_plugins'); |
---|
4 | |
---|
5 | if ( !is_object($obj) ) { |
---|
6 | $obj = new stdClass; |
---|
7 | $obj->last_checked = false; |
---|
8 | $obj->checked = array(); |
---|
9 | $obj->response = array(); |
---|
10 | } |
---|
11 | |
---|
12 | if ( in_array(current_filter(), array('load-plugins.php', 'load-tools_page_sem-tools')) ) { |
---|
13 | $timeout = 3600; |
---|
14 | } else { |
---|
15 | $timeout = 43200; |
---|
16 | } |
---|
17 | |
---|
18 | if ( is_array($checked) && $checked && $obj->checked && $obj->checked != $checked ) { |
---|
19 | delete_transient('sem_update_plugins'); |
---|
20 | delete_transient('update_plugins'); |
---|
21 | return false; |
---|
22 | } |
---|
23 | |
---|
24 | if ( ( $obj->last_checked >= time() - $timeout ) || $_POST ) |
---|
25 | return $obj->response; |
---|
26 | |
---|
27 | global $wp_version; |
---|
28 | |
---|
29 | if ( !function_exists('get_plugins') ) |
---|
30 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
---|
31 | |
---|
32 | $obj->last_checked = time(); |
---|
33 | set_transient('sem_update_plugins', $obj); |
---|
34 | |
---|
35 | $url = version_checker_server; |
---|
36 | |
---|
37 | $to_check = get_plugins(); |
---|
38 | $check = array(); |
---|
39 | |
---|
40 | foreach ( $to_check as $file => $plugin ) |
---|
41 | $check[$file] = $plugin['Version']; |
---|
42 | |
---|
43 | $obj->checked = $check; |
---|
44 | set_transient('sem_update_plugins', $obj); |
---|
45 | |
---|
46 | $body = array( |
---|
47 | 'check' => $check, |
---|
48 | 'locale' => apply_filters('core_version_check_locale', get_locale()), |
---|
49 | ); |
---|
50 | |
---|
51 | $options = array( |
---|
52 | 'timeout' => 3, |
---|
53 | 'body' => $body, |
---|
54 | 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'), |
---|
55 | ); |
---|
56 | |
---|
57 | $cache_id = md5(serialize(array($url, $options))); |
---|
58 | $raw_response = wp_cache_get($cache_id, 'sem_api'); |
---|
59 | |
---|
60 | if ( $raw_response === false ) { |
---|
61 | $raw_response = wp_remote_post($url, $options); |
---|
62 | wp_cache_set($cache_id, $raw_response, 'sem_api'); |
---|
63 | } |
---|
64 | |
---|
65 | if ( is_wp_error($raw_response) ) |
---|
66 | set_transient('sem_api_error', $raw_response->get_error_messages()); |
---|
67 | else |
---|
68 | delete_transient('sem_api_error'); |
---|
69 | |
---|
70 | if ( is_wp_error($raw_response) || 200 != $raw_response['response']['code'] ) |
---|
71 | $response = false; |
---|
72 | else |
---|
73 | $response = @unserialize($raw_response['body']); |
---|
74 | |
---|
75 | if ( $response !== false ) { // keep old response in case of error |
---|
76 | $obj->response = $response; |
---|
77 | set_transient('sem_update_plugins', $obj); |
---|
78 | } |
---|
79 | |
---|
80 | return $obj; |
---|
81 | } |
---|
82 | |
---|
83 | ?> |
---|