diff --git a/includes/class-controller.php b/includes/class-controller.php index 565cebe..2da42d4 100755 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -144,6 +144,8 @@ public function clear_cache_if_debugging() { public function extra_plugin_headers( $headers ) { $headers[] = 'Git URI'; $headers[] = 'Git Branch'; + $headers[] = 'GitHub Plugin URI'; + $headers[] = 'GitHub Branch'; return $headers; } @@ -207,7 +209,7 @@ public function load_plugins( $plugins ) { foreach ( get_plugins() as $slug => $args ) { $args = array_merge( array( 'slug' => $slug ), $args ); - + $plugin = $this->get_plugin_updater_object( $args ); if ( false === $plugin ) { diff --git a/includes/class-updater-github.php b/includes/class-updater-github.php index ff3270a..87f5f5d 100755 --- a/includes/class-updater-github.php +++ b/includes/class-updater-github.php @@ -18,7 +18,9 @@ public function __construct( $args ){ parent::__construct( $args ); // Todo: Properly set branch from plugin header - $this->branch = $this->get_default_branch(); + $this->default_branch = $this->get_local_branch() ? $this->get_local_branch() : $this->get_default_branch(); + $this->branch = $this->default_branch; + $this->zip_url = $this->get_zip_url(); } /** @@ -114,9 +116,13 @@ protected function get_api_url( $endpoint ) { protected function get_zip_url() { - return 'https://github.com/' . $this->owner . '/' . $this->repository . + if ( ! empty( $this->branch ) ) + return 'https://github.com/' . $this->owner . '/' . $this->repository . '/archive/' . $this->branch . '.zip'; + return 'https://github.com/' . $this->owner . '/' . $this->repository . + '/archive/master.zip'; + } /** diff --git a/includes/class-updater.php b/includes/class-updater.php index 5b7ac1b..d9b0994 100755 --- a/includes/class-updater.php +++ b/includes/class-updater.php @@ -116,10 +116,12 @@ public static function parse_plugin_uri( $plugin ) { if ( !empty( $plugin['Git URI'] ) ) { $url = parse_url( $plugin['Git URI'] ); - }elseif ( apply_filters( 'gpu_use_plugin_uri_header', false ) ) { + } else { $url = parse_url( $plugin['PluginURI'] ); } + if ( empty( $url ) ) return; + return $url; } @@ -150,6 +152,26 @@ protected function get_local_version() { return false; } + /** + * Retrieves the local branch from the file header of the plugin + * + * @author Andy Fragen + * @link https://github.com/afragen/github-updater + * + * @return string|boolean default branch of installed plugin, false if not determined. + */ + protected function get_local_branch() { + $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $this->slug ); + + if ( ! empty( $data['Git Branch'] ) ) + return $data['Git Branch']; + + if ( ! empty( $data['GitHub Branch'] ) ) + return $data['GitHub Branch']; + + return false; + } + /** * Retrieve the remote version from the file header of the plugin *