Themes API from josephscott. see #7519

git-svn-id: http://svn.automattic.com/wordpress/trunk@8891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-15 16:21:15 +00:00
parent fcaf29bc65
commit 8a4cf0eab8

View File

@ -165,6 +165,74 @@ function wp_update_plugins() {
update_option( 'update_plugins', $new_option );
}
/**
* Check theme versions against the latest versions hosted on WordPress.org.
*
* A list of all themes installed in sent to WP. Checks against the
* WordPress server at api.wordpress.org. Will only check if PHP has
* fsockopen enabled and WordPress isn't installing.
*
* @package WordPress
* @since 2.7.0
* @uses $wp_version Used to notidy the WordPress version.
*
* @return mixed Returns null if update is unsupported. Returns false if check is too soon.
*/
function wp_update_themes( ) {
global $wp_version;
if( defined( 'WP_INSTALLING' ) )
return false;
if( !function_exists( 'get_themes' ) )
require_once( ABSPATH . 'wp-includes/theme.php' );
$installed_themes = get_themes( );
$current_theme = get_option( 'update_themes' );
$new_option = '';
$new_option->last_checked = time( );
$time_not_changed = isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked );
if( $time_not_changed )
return false;
$themes = array( );
$themes['current_theme'] = $current_theme;
foreach( (array) $installed_themes as $theme_title => $theme ) {
$themes[$theme['Template']] = array( );
foreach( (array) $theme as $key => $value ) {
$themes[$theme['Template']][$key] = $value;
}
}
$options = array(
'method' => 'POST',
'timeout' => 3,
'body' => 'themes=' . urlencode( serialize( $themes ) )
);
$options['headers'] = array(
'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),
'Content-Length' => strlen( $options['body'] ),
'User-Agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
);
$raw_response = wp_remote_request( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
if( is_wp_error( $raw_response ) )
return false;
if( 200 != $raw_response['response']['code'] )
return false;
$response = unserialize( $raw_response['body'] );
if( $response )
$new_option->response = $response;
update_option( 'update_themes', $new_option );
}
function _maybe_update_plugins() {
$current = get_option( 'update_plugins' );
if ( isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ) )
@ -172,11 +240,26 @@ function _maybe_update_plugins() {
wp_update_plugins();
}
function _maybe_update_themes( ) {
$current = get_option( 'update_themes' );
if( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) )
return;
wp_update_themes( );
}
add_action( 'load-plugins.php', 'wp_update_plugins' );
add_action( 'admin_init', '_maybe_update_plugins' );
add_action( 'wp_update_plugins', 'wp_update_plugins' );
add_action( 'admin_init', '_maybe_update_themes' );
add_action( 'wp_update_themes', 'wp_update_themes' );
if ( !wp_next_scheduled('wp_update_plugins') )
wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
if ( !wp_next_scheduled('wp_update_themes') )
wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
?>