Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion includes/class-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ) {
Expand Down
10 changes: 8 additions & 2 deletions includes/class-updater-github.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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';

}

/**
Expand Down
24 changes: 23 additions & 1 deletion includes/class-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
*
Expand Down