Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate webhooks #472

Merged
merged 11 commits into from
Jun 27, 2024
3 changes: 2 additions & 1 deletion compat/component-aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use BracketSpace\Notification\Admin;
use BracketSpace\Notification\Api;
use BracketSpace\Notification\Core;
use BracketSpace\Notification\Compat;
use BracketSpace\Notification\Integration;

return [
Expand All @@ -19,7 +20,7 @@
'core_sync' => Core\Sync::class,
'core_binder' => Core\Binder::class,
'core_processor' => Core\Processor::class,
'test_rest_api' => Admin\CheckRestApi::class,
'test_rest_api' => Compat\RestApiCompat::class,
'admin_impexp' => Admin\ImportExport::class,
'admin_settings' => Admin\Settings::class,
'admin_duplicator' => Admin\NotificationDuplicator::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

declare(strict_types=1);

namespace BracketSpace\Notification\Repository\Carrier;
namespace BracketSpace\Notification\Defaults\Carrier;

use BracketSpace\Notification\Interfaces\Triggerable;
use BracketSpace\Notification\Repository\Carrier\BaseCarrier;
use BracketSpace\Notification\Repository\Field;
use BracketSpace\Notification\Traits\Webhook as WebhookTrait;

/**
* Webhook Carrier
*
* @deprecated [Next]
*/
class Webhook extends BaseCarrier
{
Expand All @@ -37,6 +40,26 @@ class Webhook extends BaseCarrier
*/
public function formFields()
{
$this->addFormField(
new Field\MessageField(
[
'name' => 'deprecated',
'label' => __('Deprecated', 'notification'),
'type' => 'error',
'message' =>
'<p>' . __("This carrier doesn't work since Notification v9.", 'notification') . '</p>' .
'<a
href="https://bracketspace.com/downloads/notification-webhooks
?utm_source=wp&utm_medium=carrier-box&utm_id=deprecated-webhook"
class="button button-small button-secondary"
target="_blank"
>' .
esc_html__('Get Notification : Webhooks extension', 'notification') .
'</a>',
]
)
);

$this->addRecipientsField(
[
'label' => __('URLs', 'notification'),
Expand Down Expand Up @@ -139,34 +162,16 @@ public function formFields()
*/
public function send(Triggerable $trigger)
{
$data = $this->data;

$args = $this->parseArgs($data['args']);
$args = apply_filters('notification/carrier/webhook/args', $args, $this, $trigger);

if ($data['json']) {
$args = wp_json_encode($args);
}

// Headers.
$headers = $data['json']
? ['Content-Type' => 'application/json']
: [];

if (\Notification::settings()->getSetting('carriers/webhook/headers')) {
$headers = array_merge($headers, $this->parseArgs($data['headers']));
}

// Call each URL separately.
foreach ($data['urls'] as $url) {
$filteredArgs = apply_filters(
sprintf('notification/carrier/webhook/args/%s', $url['type']),
$args,
$this,
$trigger
);

$this->httpRequest($url['recipient'], $filteredArgs, $headers, $url['type']);
}
/**
* ================== WARNING! ==================
*
* The Webhook carrier is not available in the plugin since version 9.
*
* We moved that function into a more robust paid extension that can
* also handle incoming webhooks.
*
* Read more: https://docs.bracketspace.com/notification/extensions/webhooks#webhooks-dont-work-after-upgrading-to-notification-v9
* Extension: https://bracketspace.com/downloads/notification-webhooks/
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

declare(strict_types=1);

namespace BracketSpace\Notification\Repository\Carrier;
namespace BracketSpace\Notification\Defaults\Carrier;

use BracketSpace\Notification\Interfaces\Triggerable;
use BracketSpace\Notification\Repository\Carrier\BaseCarrier;
use BracketSpace\Notification\Repository\Field;
use BracketSpace\Notification\Traits\Webhook as WebhookTrait;

/**
* Webhook Carrier
*
* @deprecated [Next]
*/
class WebhookJson extends BaseCarrier
{
Expand All @@ -37,6 +40,26 @@ class WebhookJson extends BaseCarrier
*/
public function formFields()
{
$this->addFormField(
new Field\MessageField(
[
'name' => 'deprecated',
'label' => __('Deprecated', 'notification'),
'type' => 'error',
'message' =>
'<p>' . __("This carrier doesn't work since Notification v9.", 'notification') . '</p>' .
'<a
href="https://bracketspace.com/downloads/notification-webhooks
?utm_source=wp&utm_medium=carrier-box&utm_id=deprecated-webhook"
class="button button-small button-secondary"
target="_blank"
>' .
esc_html__('Get Notification : Webhooks extension', 'notification') .
'</a>',
]
)
);

$this->addRecipientsField(
[
'label' => __('URLs', 'notification'),
Expand Down Expand Up @@ -108,37 +131,16 @@ public function formFields()
*/
public function send(Triggerable $trigger)
{
$data = $this->data;

$args = $this->parseArgs($data['args']);
$args = apply_filters('notification/carrier/webhook/args', $args, $this, $trigger);

if ($data['json']) {
$args = $data['json'];
}

// Headers.
$headers = $data['json']
? ['Content-Type' => 'application/json']
: [];

if (\Notification::settings()->getSetting('carriers/webhook/headers')) {
$headers = array_merge(
$headers,
$this->parseArgs($data['headers'])
);
}

// Call each URL separately.
foreach ($data['urls'] as $url) {
$filteredArgs = apply_filters(
sprintf('notification/carrier/webhook/args/%s', $url['type']),
$args,
$this,
$trigger
);

$this->httpRequest($url['recipient'], $filteredArgs, $headers, $url['type']);
}
/**
* ================== WARNING! ==================
*
* The Webhook carrier is not available in the plugin since version 9.
*
* We moved that function into a more robust paid extension that can
* also handle incoming webhooks.
*
* Read more: https://docs.bracketspace.com/notification/extensions/webhooks#webhooks-dont-work-after-upgrading-to-notification-v9
* Extension: https://bracketspace.com/downloads/notification-webhooks/
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Webhook trait
*
* @deprecated [Next]
*/
trait Webhook
{
Expand All @@ -26,6 +28,8 @@ trait Webhook
*/
public function __construct($name)
{
notification_deprecated_class( __CLASS__, '[Next]' );

$slug = strtolower(str_replace(' ', '_', $name));

parent::__construct($slug, __($name, 'notification'));
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"strauss": {
"namespace_prefix": "BracketSpace\\Notification\\Dependencies\\",
"target_directory": "dependencies",
"classmap_prefix": "BRSET_"
"classmap_prefix": ""
}
},
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading