diff --git a/CHANGELOG.md b/CHANGELOG.md index ca2dbad..d8f2153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Release Notes for Webhooks for Craft CMS +## 2.4.1 - 2021-09-09 + +### Added +- Added the `disableAllWebhooks` setting. ([#4](https://github.com/craftcms/webhooks/issues/4)) + ## 2.4.0.1 - 2021-08-30 ### Fixed diff --git a/README.md b/README.md index 47794f3..df87a74 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ To configure Webhooks, go to **Settings** → **Webhooks**, or create a `config/ ```php false, 'maxDepth' => 10, 'maxAttempts' => 3, 'initialDelay' => null, @@ -50,6 +51,7 @@ return [ The array can define the following keys: +- `disableAllWebhooks` – Whether all webhooks should be disabled. - `maxDepth` – The maximum depth that the plugin should go into objects/arrays when converting them to arrays for event payloads. (Default is `5`.) - `maxAttempts` – The maximum number of attempts each webhook should have before giving up, if the requests are coming back with non 2xx responses. (Default is `1`.) - `initialDelay` – The delay (in seconds) that initial webhook request attempts should have. @@ -200,6 +202,15 @@ Webhooks can be enabled or disabled from both the Webhooks index page and within Only enabled webhooks will send webhook requests when their corresponding events are triggered. +You can disable *all* webhooks by setting `disableAllWebhooks` to `true` in your `config/webhooks.php` file. + +```php +return [ + 'disableAllWebhooks' => true, + // ... +]; +``` + ## Integrating with Task Automation Tools ### Netlify diff --git a/composer.json b/composer.json index 0a5625f..a3469f6 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "craftcms/webhooks", "description": "Post webhooks when events are triggered in Craft CMS.", - "version": "2.4.0.1", + "version": "2.4.1", "type": "craft-plugin", "keywords": [ "html", diff --git a/src/Plugin.php b/src/Plugin.php index 777bb91..5e1796c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -116,12 +116,14 @@ public function init() $this->set('webhookManager', $manager); // Register webhook events - try { - $webhooks = $manager->getEnabledWebhooks(); - } catch (Throwable $e) { - Craft::error('Unable to fetch enabled webhooks: ' . $e->getMessage(), __METHOD__); - Craft::$app->getErrorHandler()->logException($e); - $webhooks = []; + $webhooks = []; + if (!$this->getSettings()->disableAllWebhooks) { + try { + $webhooks = $manager->getEnabledWebhooks(); + } catch (Throwable $e) { + Craft::error('Unable to fetch enabled webhooks: ' . $e->getMessage(), __METHOD__); + Craft::$app->getErrorHandler()->logException($e); + } } foreach ($webhooks as $webhook) { diff --git a/src/Settings.php b/src/Settings.php index 6fdb252..b3b32a6 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -7,6 +7,12 @@ class Settings extends Model { + /** + * @var bool Whether all webhooks should be disabled. + * @since 2.4.1 + */ + public $disableAllWebhooks = false; + /** * @var int The maximum depth that the plugin should go into objects/arrays when converting them to arrays for * event payloads.