Carrier is an element that connects the WordPress action with a service. Default Carriers are Email and Webhook.
If you want to connect with API or other delivery services, you should create a custom Carrier.
Carriers very often need the Recipients, so you may want to add a custom one as well.
Carrier class
useBracketSpace\Notification\Interfaces\Triggerable;useBracketSpace\Notification\Repository\Carrier\BaseCarrier;useBracketSpace\Notification\Repository\Field;/** * ExampleCarrier Carrier */classExampleCarrierextendsBaseCarrier{/** * Carrier icon, optional * * @varstring SVG */public $icon ='<svg>...</svg>';/** * Carrier constructor */publicfunction__construct() {// Provide the slug and translatable name.parent::__construct('example-carrier',__('Example Carrier','textdomain')); }/** * Used to register Carrier form fields * Uses $this->addFormField(); * * @returnvoid */publicfunctionformFields() {$this->addFormField(newField\InputField(['label'=>__('Example field','notification'),'name'=>'fieldslug', ]));// Special field which renders all Carrier's recipients.// You may override name, slug and description here.$this->addRecipientsField(['name'=>'Items','slug'=>'items', ]); }/** * Sends the notification * * @paramTriggerable $trigger trigger object. * @returnvoid */publicfunctionsend(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.