Skip to content

Commit

Permalink
Updater class update
Browse files Browse the repository at this point in the history
  • Loading branch information
tommusrhodus committed Mar 23, 2024
1 parent 392227d commit a3afb5a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 75 deletions.
37 changes: 8 additions & 29 deletions .utilities/class-wpsp-blocks-self-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function get_instance() {
* Initialize WordPress hooks
*/
public function hooks() {
add_filter( 'update_plugins_opsoasis.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
add_filter( 'update_plugins_opsoasis-develop.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
}

/**
Expand All @@ -49,23 +49,11 @@ public function self_update( $update, array $plugin_data, string $plugin_file )
return $update;
}

// Check this is a plugin we actually manage.
$wpsp_blocks = array_map(
function( $block ) {
return "{$block}/{$block}.php";
},
apply_filters( 'wpsp_installed_blocks', array() )
);

if ( ! in_array( $plugin_file, $wpsp_blocks, true ) ) {
return $update;
}

$plugin_filename_parts = explode( '/', $plugin_file );

// Ask opsoasis.mystagingwebsite.com if there's an update.
$response = wp_remote_get(
'https://opsoasis.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
'https://opsoasis-develop.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
array(
'body' => array(
'plugin' => $plugin_filename_parts[0],
Expand All @@ -82,20 +70,11 @@ function( $block ) {
$updated_version = wp_remote_retrieve_body( $response );
$updated_array = json_decode( $updated_version, true );

// Get the zip file.
$zip = wp_remote_get( $updated_array['package_url'] );

// If the zip file was found, return the update.
if ( 200 === wp_remote_retrieve_response_code( $zip ) ) {
return array(
'slug' => $updated_array['slug'],
'version' => $updated_array['version'],
'url' => $updated_array['package_url'],
'package' => wp_remote_retrieve_body( $zip ),
);
}

// If we're here, nothing was found on github.
return $update;
return array(
'slug' => $updated_array['slug'],
'version' => $updated_array['version'],
'url' => $updated_array['package_url'],
'package' => $updated_array['package_url'],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function get_instance() {
* Initialize WordPress hooks
*/
public function hooks() {
add_filter( 'update_plugins_opsoasis.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
add_filter( 'update_plugins_opsoasis-develop.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
}

/**
Expand All @@ -49,23 +49,11 @@ public function self_update( $update, array $plugin_data, string $plugin_file )
return $update;
}

// Check this is a plugin we actually manage.
$wpsp_blocks = array_map(
function( $block ) {
return "{$block}/{$block}.php";
},
apply_filters( 'wpsp_installed_blocks', array() )
);

if ( ! in_array( $plugin_file, $wpsp_blocks, true ) ) {
return $update;
}

$plugin_filename_parts = explode( '/', $plugin_file );

// Ask opsoasis.mystagingwebsite.com if there's an update.
$response = wp_remote_get(
'https://opsoasis.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
'https://opsoasis-develop.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
array(
'body' => array(
'plugin' => $plugin_filename_parts[0],
Expand All @@ -82,20 +70,11 @@ function( $block ) {
$updated_version = wp_remote_retrieve_body( $response );
$updated_array = json_decode( $updated_version, true );

// Get the zip file.
$zip = wp_remote_get( $updated_array['package_url'] );

// If the zip file was found, return the update.
if ( 200 === wp_remote_retrieve_response_code( $zip ) ) {
return array(
'slug' => $updated_array['slug'],
'version' => $updated_array['version'],
'url' => $updated_array['package_url'],
'package' => wp_remote_retrieve_body( $zip ),
);
}

// If we're here, nothing was found on github.
return $update;
return array(
'slug' => $updated_array['slug'],
'version' => $updated_array['version'],
'url' => $updated_array['package_url'],
'package' => $updated_array['package_url'],
);
}
}
25 changes: 8 additions & 17 deletions hello-world/classes/class-wpsp-blocks-self-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function get_instance() {
* Initialize WordPress hooks
*/
public function hooks() {
add_filter( 'update_plugins_opsoasis.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
add_filter( 'update_plugins_opsoasis-develop.mystagingwebsite.com', array( $this, 'self_update' ), 10, 3 );
}

/**
Expand All @@ -53,7 +53,7 @@ public function self_update( $update, array $plugin_data, string $plugin_file )

// Ask opsoasis.mystagingwebsite.com if there's an update.
$response = wp_remote_get(
'https://opsoasis.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
'https://opsoasis-develop.mystagingwebsite.com/wp-json/opsoasis-blocks-version-manager/v1/update-check',
array(
'body' => array(
'plugin' => $plugin_filename_parts[0],
Expand All @@ -70,20 +70,11 @@ public function self_update( $update, array $plugin_data, string $plugin_file )
$updated_version = wp_remote_retrieve_body( $response );
$updated_array = json_decode( $updated_version, true );

// Get the zip file.
$zip = wp_remote_get( $updated_array['package_url'] );

// If the zip file was found, return the update.
if ( 200 === wp_remote_retrieve_response_code( $zip ) ) {
return array(
'slug' => $updated_array['slug'],
'version' => $updated_array['version'],
'url' => $updated_array['package_url'],
'package' => wp_remote_retrieve_body( $zip ),
);
}

// If we're here, nothing was found on github.
return $update;
return array(
'slug' => $updated_array['slug'],
'version' => $updated_array['version'],
'url' => $updated_array['package_url'],
'package' => $updated_array['package_url'],
);
}
}

0 comments on commit a3afb5a

Please sign in to comment.