Adding a notification service

Post Status Notifier has a built-in email notification service. But it is easy to implement custom notification services.

After the built-in services have been loaded, PSN triggers the action psn_after_load_services which you can use to register your custom notification service.

Let’s say you put the logic for your custom service in a class file MyService.php located in the Example module’s subdirectory lib/Service:

└ lib
  └ Service
    └ MyService.php

In the module’s bootstrap.php you can load your service like this:

public function bootstrap()
    // register a method for the load_services action
    add_action('psn_after_load_services', array($this, 'addNotificationService'));

 * Adds a new notification service
 * @param Psn_Notification_Manager $notificationManager
public function addNotificationService(Psn_Notification_Manager $notificationManager)
    // include the service class
    require_once $this->getPathinfo()->getRootLib() . 'Service/MyService.php';
    // add the service to the notification service manager
    $notificationManager->addService(new Psn_Module_Example_Service_MyService($this->_pm));

The callback function for the action psn_after_load_services expects one parameter, an object of type Psn_Notification_Manager. This is PSN’s Notification Manager object. Use it to add your service with the method addService.

Service object

A Post Status Notifier service object must implement the interface Psn_Notification_Service_Interface to be accepted by the Notification Manager’s addService method. Following the interface, the notification service object must implement the method execute. It receives two parameters, the notification rule object which matched the post status transition and the WordPress post object of the post which got changed.

public function execute(Psn_Model_Rule $rule, $post)

Now it’s up to you to implement your custom notification service.