Skip to content
Browse files

closes #6

  • Loading branch information...
1 parent 3689424 commit 29a4053fd9f98e475a9a1a6369091b0421d70cc8 @beck beck committed Feb 10, 2012
Showing with 19 additions and 14 deletions.
  1. +0 −2 readme.markdown
  2. +19 −12 updater.php
View
2 readme.markdown
@@ -104,8 +104,6 @@ Code is a mashup of Wordpress source. I'm looking at:
* [`get_themes()`](http://core.trac.wordpress.org/browser/trunk/wp-includes/theme.php?rev=17978#L249)
* [`get_theme_data()`](http://core.trac.wordpress.org/browser/trunk/wp-includes/theme.php?rev=17978#L163)
-Unfortunately `Theme URI` is not available via default [`get_theme_data()`](http://codex.wordpress.org/Function_Reference/get_theme_data), which is probably for the best because I don't want to conflict with standard [wordpress conventions](http://codex.wordpress.org/Theme_Development#Theme_Stylesheet).
-
### 2 - Get the github tags
View
31 updater.php
@@ -10,24 +10,30 @@
require_once('assets.php');
+// register the custom stylesheet header
+add_action( 'extra_theme_headers', 'github_extra_theme_headers' );
+function github_extra_theme_headers( $headers ) {
+ $headers['Github Theme URI'] = 'Github Theme URI';
+ return $headers;
+}
+
add_filter('site_transient_update_themes', 'transient_update_themes_filter');
function transient_update_themes_filter($data){
$installed_themes = get_themes( );
foreach ( (array) $installed_themes as $theme_title => $theme ) {
- // Get Theme's URI
+ // get the Github URI header, skip if not set
if(isset($theme['Stylesheet Files'][0]) && is_readable($theme['Stylesheet Files'][0])){
- $theme_file = $theme['Stylesheet Dir'] . '/style.css';
- $default_headers = array('UpdateURI' => 'Github Theme URI');
- $theme_data = get_file_data( $theme_file, $default_headers, 'theme' );
- if(empty($theme_data['UpdateURI'])){
+ $stylesheet = $theme['Stylesheet Dir'] . '/style.css';
+ $theme_data = get_theme_data($stylesheet);
+ if(empty($theme_data['Github Theme URI'])){
continue;
}
- $theme['UpdateURI'] = $theme_data['UpdateURI'];
- $theme_key = $theme['Stylesheet'];
}
-
+
+ $theme['Github Theme URI'] = $theme_data['Github Theme URI'];
+ $theme_key = $theme['Stylesheet'];
// Add Github Theme Updater to return $data and hook into admin
remove_action( "after_theme_row_" . $theme['Stylesheet'], 'wp_theme_update_row');
@@ -36,7 +42,7 @@ function transient_update_themes_filter($data){
// Grab Github Tags
preg_match(
'/http(s)?:\/\/github.com\/(?<username>[\w-]+)\/(?<repo>[\w-]+)$/',
- $theme['UpdateURI'],
+ $theme['Github Theme URI'],
$matches);
if(!isset($matches['username']) or !isset($matches['repo'])){
$data->response[$theme_key]['error'] = 'Incorrect github project url. Format should be (no trailing slash): <code style="background:#FFFBE4;">https://github.com/&lt;username&gt;/&lt;repo&gt;</code>';
@@ -83,7 +89,8 @@ function transient_update_themes_filter($data){
// check for rollback
if(isset($_GET['rollback'])){
- $data->response[$theme_key]['package'] = $theme['UpdateURI'] . '/zipball/' . urlencode($_GET['rollback']);
+ $data->response[$theme_key]['package'] =
+ $theme['Github Theme URI'] . '/zipball/' . urlencode($_GET['rollback']);
continue;
}
@@ -98,10 +105,10 @@ function transient_update_themes_filter($data){
// new update available, add to $data
- $download_link = $theme['UpdateURI'] . '/zipball/' . $newest_tag;
+ $download_link = $theme['Github Theme URI'] . '/zipball/' . $newest_tag;
$update = array();
$update['new_version'] = $newest_tag;
- $update['url'] = $theme['UpdateURI'];
+ $update['url'] = $theme['Github Theme URI'];
$update['package'] = $download_link;
$data->response[$theme_key] = $update;

0 comments on commit 29a4053

Please sign in to comment.
Something went wrong with that request. Please try again.