Skip to content

Commit 906f8e3

Browse files
committed
2.4.1 - disableAllWebhooks
Resolves #4
1 parent 5bfe1ca commit 906f8e3

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes for Webhooks for Craft CMS
22

3+
## 2.4.1 - 2021-09-09
4+
5+
### Added
6+
- Added the `disableAllWebhooks` setting. ([#4](https://github.com/craftcms/webhooks/issues/4))
7+
38
## 2.4.0.1 - 2021-08-30
49

510
### Fixed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ To configure Webhooks, go to **Settings** → **Webhooks**, or create a `config/
4040
```php
4141
<?php
4242
return [
43+
'disableAllWebhooks' => false,
4344
'maxDepth' => 10,
4445
'maxAttempts' => 3,
4546
'initialDelay' => null,
@@ -50,6 +51,7 @@ return [
5051

5152
The array can define the following keys:
5253

54+
- `disableAllWebhooks` – Whether all webhooks should be disabled.
5355
- `maxDepth` – The maximum depth that the plugin should go into objects/arrays when converting them to arrays for event payloads. (Default is `5`.)
5456
- `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`.)
5557
- `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
200202

201203
Only enabled webhooks will send webhook requests when their corresponding events are triggered.
202204

205+
You can disable *all* webhooks by setting `disableAllWebhooks` to `true` in your `config/webhooks.php` file.
206+
207+
```php
208+
return [
209+
'disableAllWebhooks' => true,
210+
// ...
211+
];
212+
```
213+
203214
## Integrating with Task Automation Tools
204215

205216
### Netlify

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "craftcms/webhooks",
33
"description": "Post webhooks when events are triggered in Craft CMS.",
4-
"version": "2.4.0.1",
4+
"version": "2.4.1",
55
"type": "craft-plugin",
66
"keywords": [
77
"html",

src/Plugin.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ public function init()
116116
$this->set('webhookManager', $manager);
117117

118118
// Register webhook events
119-
try {
120-
$webhooks = $manager->getEnabledWebhooks();
121-
} catch (Throwable $e) {
122-
Craft::error('Unable to fetch enabled webhooks: ' . $e->getMessage(), __METHOD__);
123-
Craft::$app->getErrorHandler()->logException($e);
124-
$webhooks = [];
119+
$webhooks = [];
120+
if (!$this->getSettings()->disableAllWebhooks) {
121+
try {
122+
$webhooks = $manager->getEnabledWebhooks();
123+
} catch (Throwable $e) {
124+
Craft::error('Unable to fetch enabled webhooks: ' . $e->getMessage(), __METHOD__);
125+
Craft::$app->getErrorHandler()->logException($e);
126+
}
125127
}
126128

127129
foreach ($webhooks as $webhook) {

src/Settings.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
class Settings extends Model
99
{
10+
/**
11+
* @var bool Whether all webhooks should be disabled.
12+
* @since 2.4.1
13+
*/
14+
public $disableAllWebhooks = false;
15+
1016
/**
1117
* @var int The maximum depth that the plugin should go into objects/arrays when converting them to arrays for
1218
* event payloads.

0 commit comments

Comments
 (0)