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 Recipients, so you may want to add a custom one as well.
Carrier class
useBracketSpace\Notification\Interfaces\Triggerable;useBracketSpace\Notification\Abstracts;useBracketSpace\Notification\Defaults\Field;/** * ExampleCarrier Carrier */classExampleCarrierextendsAbstracts\Carrier {/** * 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->add_form_field(); * * @returnvoid */publicfunctionform_fields() {$this->add_form_field(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->add_recipients_field( ['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.