diff --git a/functions.php b/functions.php index d2ef77d..35da8e5 100755 --- a/functions.php +++ b/functions.php @@ -182,3 +182,9 @@ function forward_scripts() { * Load Jetpack compatibility file. */ require get_template_directory() . '/inc/jetpack.php'; + +/** + * Enable automatic theme updates. + */ +require_once('wp-updates-theme.php'); +new WPUpdatesThemeUpdater_1511( 'http://wp-updates.com/api/2/theme', basename( get_template_directory() ) ); \ No newline at end of file diff --git a/style.css b/style.css index 7ed2310..d18ce5c 100644 --- a/style.css +++ b/style.css @@ -1,10 +1,10 @@ /*! Theme Name: Forward -Theme URI: http://drawbackwards.com +Theme URI: http://design.org Author: Drawbackwards Author URI: http://drawbackwards.com Description: Forward by Drawbackwards -Version: 1.0 +Version: 1.0.0 Text Domain: forward Tags: two-columns, right-sidebar, responsive-layout, accessibility-ready, threaded-comments License: GNU General Public License v2 or later diff --git a/wp-updates-theme.php b/wp-updates-theme.php new file mode 100644 index 0000000..d9f5ef4 --- /dev/null +++ b/wp-updates-theme.php @@ -0,0 +1,68 @@ +api_url = $api_url; + $this->theme_slug = $theme_slug; + $this->license_key = $license_key; + + add_filter( 'pre_set_site_transient_update_themes', array(&$this, 'check_for_update') ); + + // This is for testing only! + //set_site_transient('update_themes', null); + } + + function check_for_update( $transient ) { + if (empty($transient->checked)) return $transient; + + $request_args = array( + 'id' => $this->theme_id, + 'slug' => $this->theme_slug, + 'version' => $transient->checked[$this->theme_slug] + ); + if ($this->license_key) $request_args['license'] = $this->license_key; + + $request_string = $this->prepare_request( 'theme_update', $request_args ); + $raw_response = wp_remote_post( $this->api_url, $request_string ); + + $response = null; + if( !is_wp_error($raw_response) && ($raw_response['response']['code'] == 200) ) + $response = unserialize($raw_response['body']); + + if( !empty($response) ) // Feed the update data into WP updater + $transient->response[$this->theme_slug] = $response; + + return $transient; + } + + function prepare_request( $action, $args ) { + global $wp_version; + + return array( + 'body' => array( + 'action' => $action, + 'request' => serialize($args), + 'api-key' => md5(home_url()) + ), + 'user-agent' => 'WordPress/'. $wp_version .'; '. home_url() + ); + } + + } +} \ No newline at end of file