$theme_update_json = 'http://www.111com.net /update.json';//注意你的地址
define( 'theme_update_json', $theme_update_json );
$themefolder = strtolower( wp_get_theme() );
define( 'theme_folder', $themefolder );
$theme_update_json_path = TEMPLATEPATH . '/update.json';
define( 'theme_update_json_path', $theme_update_json_path );
function Bing_get_update_json(){
$fp = @file_get_contents( theme_update_json, 'r' );
if( !$fp ) return;
file_put_contents( theme_update_json_path, $fp );
}
add_action( 'theme_' . theme_folder . '_update', 'Bing_get_update_json' );
function Bing_theme_version_compare(){
global $update_json;
if( !file_exists( theme_update_json_path ) ) return false;
$theme_data = wp_get_theme();
$update_json = @file_get_contents( theme_update_json_path, 'r' );
$update_json = json_decode( $update_json, true );
if( version_compare( $update_json['Version'], $theme_data['Version'], '>' ) ) return true;
return false;
}
function Bing_update_schedule_event(){
global $pagenow;
if( $pagenow == 'themes.php' && isset( $_GET['activated'] ) && !wp_next_scheduled( 'theme_' . theme_folder . '_update' ) ) wp_schedule_event( current_time( 'timestamp' ), 'daily', 'theme_' . theme_folder . '_update' );
}
add_action( 'load-themes.php', 'Bing_update_schedule_event' );
function Bing_notices_update(){
if( !Bing_theme_version_compare() ) return;
global $update_json;
echo ' ' . $update_json['text'] . ' ';
}
add_action( 'admin_notices', 'Bing_notices_update' );
|