PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/update.php

https://github.com/envex/Micro-Theme
PHP | 88 lines | 31 code | 13 blank | 44 comment | 7 complexity | 2dd870873ed745a810e8e83bdd295eb0 MD5 | raw file
 1<?php
 2/**
 3 * Theme Update Functions file
 4 * 
 5 * The /inc/update.php file includes
 6 * the Theme's automatic update functions
 7 * 
 8 * @link 		http://codex.wordpress.org/Function_Reference/add_filter 	add_filter()
 9 * @link 		http://codex.wordpress.org/Function_Reference/is_admin 		is_admin()
10 * @link 		http://codex.wordpress.org/Function_Reference/get_transient	get_transient()
11 * 
12 * @package 	Micro
13 * @copyright	Copyright (c) 2011, UpThemes
14 * @license		http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
15 *
16 * @since 		Micro 1.0
17 */
18
19/**
20 * Check For Micro Theme Updates
21 * 
22 * This function uses the UpThemes API to determine
23 * if a Micro Theme update is available, in order
24 * to hook into the WordPress core Theme update
25 * functionality.
26 * 
27 * @link 	http://codex.wordpress.org/Function_Reference/get_theme_data		get_theme_data()
28 * @link 	http://codex.wordpress.org/Function_Reference/get_stylesheet_uri	get_stylesheet_uri()
29 * @link 	http://codex.wordpress.org/Function_Reference/get_bloginfo			get_bloginfo()
30 * @link 	http://codex.wordpress.org/Function_Reference/wp_remote_post		wp_remote_post()
31 * @link 	http://codex.wordpress.org/Function_Reference/is_wp_error			is_wp_error()
32 * 
33 * @link 	http://php.net/manual/en/function.basename.php 						basename()
34 * @link 	http://php.net/manual/en/function.dirname.php 						dirname()
35 * @link 	http://php.net/manual/en/function.empty.php 						empty()
36 * 
37 * @param	object	$checked_data	(required) Transient theme update data
38 * @return	object	Filtered transient theme update data
39 * 
40 * @since	Micro 1.0
41 * 
42 */
43function micro_check_for_update($checked_data) {
44	global $wp_version,$up_options;
45
46	if (empty($checked_data->last_checked) && empty($up_options->api_key))
47		return $checked_data;
48	
49	$api_url = 'http://upthemes.com/api/';
50	$theme_base = basename(dirname(dirname(__FILE__)));
51	
52	$theme_data = get_theme_data(get_stylesheet_uri());
53	
54	$request = array(
55		'slug' => THEME_NAME,
56		'version' => $theme_data['Version']
57	);
58
59	// Start checking for an update
60	$send_for_check = array(
61		'body' => array(
62			'action' => 'theme_update',
63			'request' => serialize($request),
64			'api-key' => $up_options->api_key
65		),
66		'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')
67	);
68
69	$raw_response = wp_remote_post($api_url, $send_for_check);
70	
71	if (!is_wp_error($raw_response) && ($raw_response['response']['code'] == 200))
72		$response = unserialize($raw_response['body']);
73		
74	// Feed the update data into WP updater
75	if (!empty($response)) 
76		$checked_data->response[$theme_base] = $response;
77	
78	return $checked_data;
79}
80// Hook micro_check_for_update() into pre_set_site_transient_update_themes
81add_filter( 'pre_set_site_transient_update_themes', 'micro_check_for_update' );
82
83if (is_admin())
84	$current = get_transient('update_themes');
85
86	
87//set_site_transient('update_themes', null);
88?>