| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: wp_update_plugins() debug |
|---|
| 4 | Description: List available HTTP transports and the raw response from wp_update_plugins() |
|---|
| 5 | Version: 1.0 |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | function wp_update_plugins_hack() { |
|---|
| 9 | global $wp_version; |
|---|
| 10 | |
|---|
| 11 | if ( defined('WP_INSTALLING') ) |
|---|
| 12 | return false; |
|---|
| 13 | |
|---|
| 14 | // If running blog-side, bail unless we've not checked in the last 12 hours |
|---|
| 15 | if ( !function_exists( 'get_plugins' ) ) |
|---|
| 16 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|---|
| 17 | |
|---|
| 18 | $plugins = get_plugins(); |
|---|
| 19 | $active = get_option( 'active_plugins' ); |
|---|
| 20 | $current = get_option( 'update_plugins' ); |
|---|
| 21 | if ( ! is_object($current) ) |
|---|
| 22 | $current = new stdClass; |
|---|
| 23 | |
|---|
| 24 | $new_option = ''; |
|---|
| 25 | $new_option->last_checked = time(); |
|---|
| 26 | $time_not_changed = isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ); |
|---|
| 27 | |
|---|
| 28 | $plugin_changed = false; |
|---|
| 29 | foreach ( $plugins as $file => $p ) { |
|---|
| 30 | $new_option->checked[ $file ] = $p['Version']; |
|---|
| 31 | |
|---|
| 32 | if ( !isset( $current->checked[ $file ] ) ) { |
|---|
| 33 | $plugin_changed = true; |
|---|
| 34 | continue; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | if ( strval($current->checked[ $file ]) !== strval($p['Version']) ) |
|---|
| 38 | $plugin_changed = true; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | if ( isset ( $current->response ) && is_array( $current->response ) ) { |
|---|
| 42 | foreach ( $current->response as $plugin_file => $update_details ) { |
|---|
| 43 | if ( ! isset($plugins[ $plugin_file ]) ) { |
|---|
| 44 | $plugin_changed = true; |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | // Bail if we've checked in the last 12 hours and if nothing has changed |
|---|
| 50 | // if ( $time_not_changed && !$plugin_changed ) |
|---|
| 51 | // return false; |
|---|
| 52 | |
|---|
| 53 | // Update last_checked for current to prevent multiple blocking requests if request hangs |
|---|
| 54 | $current->last_checked = time(); |
|---|
| 55 | update_option( 'update_plugins', $current ); |
|---|
| 56 | |
|---|
| 57 | $to_send->plugins = $plugins; |
|---|
| 58 | $to_send->active = $active; |
|---|
| 59 | $send = serialize( $to_send ); |
|---|
| 60 | $body = 'plugins=' . urlencode( $send ); |
|---|
| 61 | |
|---|
| 62 | $options = array('method' => 'POST', 'timeout' => 3, 'body' => $body); |
|---|
| 63 | $options['headers'] = array( |
|---|
| 64 | 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), |
|---|
| 65 | 'Content-Length' => strlen($body), |
|---|
| 66 | 'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url') |
|---|
| 67 | ); |
|---|
| 68 | |
|---|
| 69 | $raw_response = wp_remote_request('http://api.wordpress.org/plugins/update-check/1.0/', $options); |
|---|
| 70 | |
|---|
| 71 | if ( is_wp_error( $raw_response ) ) |
|---|
| 72 | return false; |
|---|
| 73 | |
|---|
| 74 | // if( 200 != $raw_response['response']['code'] ) { |
|---|
| 75 | // return false; |
|---|
| 76 | // } |
|---|
| 77 | |
|---|
| 78 | $response = unserialize( $raw_response['body'] ); |
|---|
| 79 | |
|---|
| 80 | if ( false !== $response ) |
|---|
| 81 | $new_option->response = $response; |
|---|
| 82 | else |
|---|
| 83 | $new_option->response = array(); |
|---|
| 84 | |
|---|
| 85 | update_option( 'update_plugins', $new_option ); |
|---|
| 86 | |
|---|
| 87 | echo "\n" . '$raw_response:' . "\n"; |
|---|
| 88 | print_r($raw_response); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | function list_transports() { |
|---|
| 92 | $transport = ''; |
|---|
| 93 | if ( true === WP_Http_ExtHttp::test() ) |
|---|
| 94 | $transport .= 'ExtHttp'; |
|---|
| 95 | if ( true === WP_Http_Curl::test() ) |
|---|
| 96 | $transport .= ' Curl'; |
|---|
| 97 | if ( true === WP_Http_Streams::test() ) |
|---|
| 98 | $transport .= ' Streams'; |
|---|
| 99 | if ( true === WP_Http_Fopen::test() ) |
|---|
| 100 | $transport .= ' Fopen'; |
|---|
| 101 | if ( true === WP_Http_Fsockopen::test() ) |
|---|
| 102 | $transport .= ' Fsockopen'; |
|---|
| 103 | |
|---|
| 104 | echo "Available transports: $transport"; |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | add_action('admin_footer', 'list_transports'); |
|---|
| 108 | add_action('admin_footer', 'wp_update_plugins_hack'); |
|---|
| 109 | |
|---|
| 110 | ?> |
|---|