Skip to content

Commit

Permalink
2.4.1 - disableAllWebhooks
Browse files Browse the repository at this point in the history
Resolves #4
  • Loading branch information
brandonkelly committed Sep 9, 2021
1 parent 5bfe1ca commit 906f8e3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ To configure Webhooks, go to **Settings** → **Webhooks**, or create a `config/
```php
<?php
return [
'disableAllWebhooks' => false,
'maxDepth' => 10,
'maxAttempts' => 3,
'initialDelay' => null,
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 8 additions & 6 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 906f8e3

Please sign in to comment.