diff --git a/.utilities/class-wpsp-blocks-self-update.php b/.utilities/class-wpsp-blocks-self-update.php new file mode 100644 index 0000000..4a16e88 --- /dev/null +++ b/.utilities/class-wpsp-blocks-self-update.php @@ -0,0 +1,101 @@ + array( + 'plugin' => $plugin_filename_parts[0], + 'version' => $plugin_data['Version'], + ), + ) + ); + + // Bail if this plugin wasn't found on opsoasis.mystagingwebsite.com. + if ( 404 === wp_remote_retrieve_response_code( $response ) || 202 === wp_remote_retrieve_response_code( $response ) ) { + return $update; + } + + $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; + } +}