| | 168 | /** |
| | 169 | * Check theme versions against the latest versions hosted on WordPress.org. |
| | 170 | * |
| | 171 | * A list of all themes installed in sent to WP. Checks against the |
| | 172 | * WordPress server at api.wordpress.org. Will only check if PHP has |
| | 173 | * fsockopen enabled and WordPress isn't installing. |
| | 174 | * |
| | 175 | * @package WordPress |
| | 176 | * @since 2.7.0 |
| | 177 | * @uses $wp_version Used to notidy the WordPress version. |
| | 178 | * |
| | 179 | * @return mixed Returns null if update is unsupported. Returns false if check is too soon. |
| | 180 | */ |
| | 181 | function wp_update_themes( ) { |
| | 182 | global $wp_version; |
| | 183 | |
| | 184 | if( defined( 'WP_INSTALLING' ) ) |
| | 185 | return false; |
| | 186 | |
| | 187 | if( !function_exists( 'get_themes' ) ) |
| | 188 | require_once( ABSPATH . 'wp-includes/theme.php' ); |
| | 189 | |
| | 190 | $installed_themes = get_themes( ); |
| | 191 | $current_theme = get_option( 'update_themes' ); |
| | 192 | |
| | 193 | $new_option = ''; |
| | 194 | $new_option->last_checked = time( ); |
| | 195 | $time_not_changed = isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ); |
| | 196 | |
| | 197 | if( $time_not_changed ) |
| | 198 | return false; |
| | 199 | |
| | 200 | $themes = array( ); |
| | 201 | $themes['current_theme'] = $current_theme; |
| | 202 | foreach( (array) $installed_themes as $theme_title => $theme ) { |
| | 203 | $themes[$theme['Template']] = array( ); |
| | 204 | |
| | 205 | foreach( (array) $theme as $key => $value ) { |
| | 206 | $themes[$theme['Template']][$key] = $value; |
| | 207 | } |
| | 208 | } |
| | 209 | |
| | 210 | $options = array( |
| | 211 | 'method' => 'POST', |
| | 212 | 'timeout' => 3, |
| | 213 | 'body' => 'themes=' . urlencode( serialize( $themes ) ) |
| | 214 | ); |
| | 215 | $options['headers'] = array( |
| | 216 | 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ), |
| | 217 | 'Content-Length' => strlen( $options['body'] ), |
| | 218 | 'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) |
| | 219 | ); |
| | 220 | |
| | 221 | $raw_response = wp_remote_request( 'http://api.wordpress.org/themes/update-check/1.0/', $options ); |
| | 222 | |
| | 223 | if( is_wp_error( $raw_response ) ) |
| | 224 | return false; |
| | 225 | |
| | 226 | if( 200 != $raw_response['response']['code'] ) |
| | 227 | return false; |
| | 228 | |
| | 229 | $response = unserialize( $raw_response['body'] ); |
| | 230 | if( $response ) |
| | 231 | $new_option->response = $response; |
| | 232 | |
| | 233 | update_option( 'update_themes', $new_option ); |
| | 234 | } |
| | 235 | |