From dac305904b4debcf08d393f9c8e56ab8f323b8bf Mon Sep 17 00:00:00 2001 From: caseyreuter <108796446+caseyreuter@users.noreply.github.com> Date: Mon, 14 Aug 2023 13:00:00 +0200 Subject: [PATCH] Pluginupdater (#14) * feat: only check for updates every 5 minutes * fix: version number * refactor: code * refactor: some slight code --- admin/src/PluginUpdater.php | 18 +++++++++--------- admin/src/RepoInstaller.php | 6 +++--- admin/src/RepoManager.php | 2 +- admin/src/SettingsPage.php | 2 +- cerberus-plugins-manager.php | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/admin/src/PluginUpdater.php b/admin/src/PluginUpdater.php index cdf765f..9a320a3 100644 --- a/admin/src/PluginUpdater.php +++ b/admin/src/PluginUpdater.php @@ -20,7 +20,7 @@ class PluginUpdater private $github_response; - public function __construct($file, $repository, $token = "") + public function __construct($file, $repository, $token = '') { $this->file = $file; $this->username = 'Trizelos'; @@ -91,7 +91,7 @@ public function modify_transient($transient): mixed $slug = current(explode('/', $this->basename)); // Create valid slug $plugin = [ // setup our plugin info - 'url' => $this->plugin["PluginURI"], + 'url' => $this->plugin['PluginURI'], 'slug' => $slug, 'package' => $new_files, 'new_version' => $this->github_response['tag_name'] @@ -143,7 +143,7 @@ public function plugin_popup($result, $action, $args): mixed // Set it to an array $plugin = [ - 'name' => $this->plugin["Name"], + 'name' => $this->plugin['Name'], 'slug' => $this->basename, 'requires' => '5.3', // 'tested' => '5.*', @@ -152,14 +152,14 @@ public function plugin_popup($result, $action, $args): mixed // 'downloaded' => '1', // 'added' => '2016-01-05', 'version' => $this->github_response['tag_name'], - 'author' => $this->plugin["AuthorName"], - 'author_profile' => $this->plugin["AuthorURI"], + 'author' => $this->plugin['AuthorName'], + 'author_profile' => $this->plugin['AuthorURI'], 'last_updated' => $this->github_response['published_at'], - 'homepage' => $this->plugin["PluginURI"], - 'short_description' => $this->plugin["Description"], + 'homepage' => $this->plugin['PluginURI'], + 'short_description' => $this->plugin['Description'], 'sections' => [ 'Updates' => $this->github_response['body'], - 'Description' => $this->plugin["Description"], + 'Description' => $this->plugin['Description'], ], 'download_link' => $this->github_response['zipball_url'] ]; @@ -172,7 +172,7 @@ public function download_package($args, $url): mixed if (null !== $args['filename']) { if ($this->authorize_token) { - $args = array_merge($args, ["headers" => ["Authorization" => "token {$this->authorize_token}"]]); + $args = array_merge($args, ['headers' => ['Authorization' => "token {$this->authorize_token}"]]); } } diff --git a/admin/src/RepoInstaller.php b/admin/src/RepoInstaller.php index f43ac12..eed538c 100644 --- a/admin/src/RepoInstaller.php +++ b/admin/src/RepoInstaller.php @@ -17,14 +17,14 @@ public function downloadExtractRepo( string $repository ): void { $response = $this->repoManager->getRepoInfoByRepoName( $repository ); - if ( ! isset( $response["zipball_url"] ) ) { + if ( ! isset( $response['zipball_url'] ) ) { wp_redirect( wp_get_referer() ); return; } - $zip_url = $response["zipball_url"]; - $destination_path = WP_PLUGIN_DIR . '/' . $repository . ".zip"; + $zip_url = $response['zipball_url']; + $destination_path = WP_PLUGIN_DIR . '/' . $repository . '.zip'; if ( ! $this->downloadZipFile( $zip_url, $destination_path ) ) { wp_redirect( wp_get_referer() ); diff --git a/admin/src/RepoManager.php b/admin/src/RepoManager.php index 4536e8f..9cf02ad 100644 --- a/admin/src/RepoManager.php +++ b/admin/src/RepoManager.php @@ -21,7 +21,7 @@ public function getRepoList(): array $repoInfos = $this->getRepoInfoByRepoName($name); if (empty($repoInfos)) { - $repoInfos = ""; + $repoInfos = ''; } $pluginFile = WP_PLUGIN_DIR . '/' . $name . '/' . $name . '.php'; diff --git a/admin/src/SettingsPage.php b/admin/src/SettingsPage.php index b2ff1ab..9fd0a99 100644 --- a/admin/src/SettingsPage.php +++ b/admin/src/SettingsPage.php @@ -111,7 +111,7 @@ public final function settingsPage(): void data-repo="" onclick="document.querySelector('#repo-to-install').value =this.dataset.repo;"> - + diff --git a/cerberus-plugins-manager.php b/cerberus-plugins-manager.php index d695d94..952602d 100644 --- a/cerberus-plugins-manager.php +++ b/cerberus-plugins-manager.php @@ -3,7 +3,7 @@ /** * Plugin Name: Cerberus Plugins Manager * Description: Manages the cerberus plugins - * Version: 1.0.9 + * Version: 1.1.0 * Requires at least: 5.7 * Author: Casey */ @@ -11,7 +11,7 @@ use Cerberus\AdminPluginsManager\PluginUpdater; use Cerberus\AdminPluginsManager\SettingsPage; -require_once "vendor/autoload.php"; +require_once 'vendor/autoload.php'; if (is_admin()) { $settingsPage = new SettingsPage(__FILE__);