Skip to content

Commit

Permalink
Merge pull request #5 from Appsero/develop
Browse files Browse the repository at this point in the history
Show Custom Message on Plugin Update Page
  • Loading branch information
anisAronno authored Aug 22, 2024
2 parents ddc3944 + 1ecd8ed commit 5be55d9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public function __construct($client)
{
$this->client = $client;
$this->cache_key = 'appsero_' . md5(sanitize_key($this->client->slug)) . '_version_info';


add_filter('upgrader_pre_download', [$this , 'validate_plugin_update_url'], 10, 2);

// Run hooks based on the client type
if ($this->client->type === 'plugin') {
$this->run_plugin_hooks();
Expand Down Expand Up @@ -416,4 +418,23 @@ public function add_custom_plugin_row($plugin_file, $plugin_data, $status, $warn
esc_html(implode(' ', $warnings))
);
}

public function validate_plugin_update_url($reply, $package) {
$response = wp_remote_get($package);

if (is_wp_error($response) || wp_remote_retrieve_response_code($response) != 200) {

$error_message = is_wp_error($response)
? $response->get_error_message()
: wp_remote_retrieve_body($response);

if (empty($error_message)) {
$error_message = wp_remote_retrieve_response_message($response);
}

return new \WP_Error('invalid_update_url', $error_message);
}

return $reply;
}
}

0 comments on commit 5be55d9

Please sign in to comment.