first commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Core\Notifications;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
abstract class Notification {
|
||||
|
||||
/**
|
||||
* Get the payloads of the notification data shape (e.g. `Email_Message`, `Database_Message`). Those will automatically
|
||||
* be sent over to the appropriate `Actions` under the `Integration_Manager` (using the `notify()` method).
|
||||
* This method is also used to determine notification channels based on user ($notifiable) preferences.
|
||||
*
|
||||
* Returned shape:
|
||||
* [
|
||||
* $payload1_instance,
|
||||
* $payload2_instance,
|
||||
* ]
|
||||
*
|
||||
* @param \ElementorPro\Core\Notifications\Traits\Notifiable $notifiable - The notified model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_payloads( $notifiable ) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Core\Notifications;
|
||||
|
||||
use ElementorPro\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Notifications_Manager {
|
||||
|
||||
/**
|
||||
* Send a notification.
|
||||
*
|
||||
* @param \ElementorPro\Core\Notifications\Notification $notification
|
||||
* @param $notifiable
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function send( Notification $notification, $notifiable ) {
|
||||
$payloads = $notification->get_payloads( $notifiable );
|
||||
|
||||
Plugin::instance()->integrations->run( $payloads );
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Core\Notifications\Traits;
|
||||
|
||||
use ElementorPro\Core\Notifications\Notification;
|
||||
use ElementorPro\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
trait Notifiable {
|
||||
|
||||
/**
|
||||
* Notify a Model with a notification.
|
||||
* Syntactic sugar for sending notifications via the `Notifications_Manager`.
|
||||
*
|
||||
* Usage:
|
||||
* $model->notify( new User_Created_Notification( $new_user ) );
|
||||
*
|
||||
* @param Notification $notification - Notification to send.
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function notify( Notification $notification ) {
|
||||
Plugin::instance()->notifications->send( $notification, $this );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user