Notification
WordPress.orgExtensionsSupport
Version 8
Version 8
  • Notification – Custom Notifications and Alerts for WordPress
  • Known issues
  • πŸ€Έβ€β™€οΈ User guide
    • Update broke my site
    • How Notification plugin works
    • Who can use this plugin
    • How to create Notifications
    • Troubleshooting
    • Advanced
      • How to escape { character
      • Background processing
      • How to setup different FROM address for different Notifications
      • Custom Post Type support
      • Disable upselling
      • How to send HTML Emails
  • πŸ”§Developer
    • General
      • Plugin loading chain
      • Runtime
      • Extension possibilities
      • Creating an extension
      • Customizations
      • Bundling Notification plugin
      • White label mode
    • Notifications
      • Suppressing the Notification
      • JSON synchronization
      • Programmatic Notifications
    • Triggers
      • List of all default Triggers
      • Custom Trigger
      • Enable support for non-public Custom Post Type
      • Adding Merge Tags to existing Triggers
    • Carriers
      • Custom Carrier
      • Adding custom fields to Carrier form
      • Suppressing the Carrier
    • Recipients
      • Custom Recipient
    • Snippets
      • General
        • Automatic Trigger testing
        • Allow other roles to edit Notifications
        • Programmatic Notification with manual Trigger
        • Background Processing filter
      • Triggers
        • Post
        • User
      • Integations
        • WP All Import
        • MemberPress
  • 🧩Extensions
    • Installation
    • Planned extensions
    • 3rd Party Extensions
    • Custom Fields
      • v2.2
      • v1.4
      • v1.3
    • Conditionals
    • Email Attachments
    • Push
    • Scheduled Triggers
    • Slack
    • Twilio
    • Webhooks
Powered by GitBook
On this page
  • Carrier class
  • Registering the Carrier
  1. Developer
  2. Carriers

Custom Carrier

PreviousCarriersNextAdding custom fields to Carrier form

Last updated 7 months ago

Carrier is an element which connects the WordPress action with a service. Default Carriers are Email and Webhook.

If you want to connect with API or other delivery service, you should create a custom Carrier.

Carriers very often needs the , so you may want to add a custom one as well.

Carrier class

use BracketSpace\Notification\Interfaces\Triggerable;
use BracketSpace\Notification\Abstracts;
use BracketSpace\Notification\Defaults\Field;

/**
 * ExampleCarrier Carrier
 */
class ExampleCarrier extends Abstracts\Carrier {

	/**
	 * Carrier icon, optional
	 *
	 * @var string SVG
	 */
	public $icon = '<svg>...</svg>';

	/**
	 * Carrier constructor
	 */
	public function __construct() {
		// Provide the slug and translatable name.
		parent::__construct( 'example-carrier', __( 'Example Carrier', 'textdomain' ) );
	}

	/**
	 * Used to register Carrier form fields
	 * Uses $this->add_form_field();
	 *
	 * @return void
	 */
	public function form_fields() {

		$this->add_form_field( new Field\InputField( [
			'label' => __( 'Example field', 'notification' ),
			'name'  => 'fieldslug',
		] ) );

		// Special field which renders all Carrier's recipients.
		// You may override name, slug and description here.
		$this->add_recipients_field( [
			'name' => 'Items',
			'slug' => 'items',
		] );

	}

	/**
	 * Sends the notification
	 *
	 * @param  Triggerable $trigger trigger object.
	 * @return void
	 */
	public function send( Triggerable $trigger ) {
		// Data contains the user data with rendered Merge Tags.
		$data = $this->data;

		// Parsed recipients are also available.
		$data['parsed_recipients'];

		// This is where you should connect with your service to send out the Notifiation.
	}

}

Registering the Carrier

To get the Carrier registered you must create an instance of your class and pass it to the Notification plugin. The best action to do that is notification/init.

use BracketSpace\Notification\Register;

add_action( 'notification/init', function() {
    Register::carrier( new ExampleCarrier() );
} );
πŸ”§
Recipients