Make WordPress Core

Changeset 8891


Ignore:
Timestamp:
09/15/2008 04:21:15 PM (16 years ago)
Author:
ryan
Message:

Themes API from josephscott. see #7519

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/update.php

    r8742 r8891  
    166166}
    167167
     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 */
     181function 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
    168236function _maybe_update_plugins() {
    169237    $current = get_option( 'update_plugins' );
     
    173241}
    174242
     243function _maybe_update_themes( ) {
     244    $current = get_option( 'update_themes' );
     245    if( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) )
     246        return;
     247
     248    wp_update_themes( );
     249}
     250
    175251add_action( 'load-plugins.php', 'wp_update_plugins' );
    176252add_action( 'admin_init', '_maybe_update_plugins' );
    177253add_action( 'wp_update_plugins', 'wp_update_plugins' );
    178254
     255add_action( 'admin_init', '_maybe_update_themes' );
     256add_action( 'wp_update_themes', 'wp_update_themes' );
     257
    179258if ( !wp_next_scheduled('wp_update_plugins') )
    180259    wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
    181260
     261
     262if ( !wp_next_scheduled('wp_update_themes') )
     263    wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
     264
    182265?>
Note: See TracChangeset for help on using the changeset viewer.