| @@ -19,68 +19,8 @@ | ||
| 19 | 19 | */ |
| 20 | 20 | private $notifications = []; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Whether built-in notifications have been registered | |
| 24 | - * | |
| 25 | - * @var bool | |
| 26 | - */ | |
| 27 | - private $registered = false; | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * The notification currently driving a send-pipeline call. | |
| 31 | - * | |
| 32 | - * `Notification::send()` sets this around its `$gateway->send()` loop so | |
| 33 | - * that `Dispatcher::log_sms` (hooked on `texty_after_send_sms`) can write | |
| 34 | - * the originating notification's id + group into the SmsStat row without | |
| 35 | - * having to pass them through the gateway pipeline. | |
| 36 | - * | |
| 37 | - * @var \Texty\Notifications\Notification|null | |
| 38 | - */ | |
| 39 | - private $active = null; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * Set the active notification for the duration of a send. | |
| 43 | - * | |
| 44 | - * @param \Texty\Notifications\Notification|null $notification | |
| 45 | - * | |
| 46 | - * @return void | |
| 47 | - */ | |
| 48 | - public function set_active( $notification ) { | |
| 49 | - $this->active = $notification; | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Get the active notification, if any. | |
| 54 | - * | |
| 55 | - * @return \Texty\Notifications\Notification|null | |
| 56 | - */ | |
| 57 | - public function get_active() { | |
| 58 | - return $this->active; | |
| 59 | - } | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * Clear the active notification. | |
| 63 | - * | |
| 64 | - * @return void | |
| 65 | - */ | |
| 66 | - public function clear_active() { | |
| 67 | - $this->active = null; | |
| 68 | - } | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * Register a notification | |
| 72 | - * | |
| 73 | - * @param string $key Notification identifier | |
| 74 | - * @param string $classname Fully qualified class name | |
| 75 | - * | |
| 76 | - * @return void | |
| 77 | - */ | |
| 78 | - public function register( $key, $classname ) { | |
| 79 | - $this->notifications[ $key ] = $classname; | |
| 80 | - } | |
| 81 | - | |
| 82 | - /** | |
| 83 | 23 | * Get a notification class |
| 84 | 24 | * |
| 85 | 25 | * @param string $key |
| 86 | 26 | * |
| @@ -101,25 +41,36 @@ | ||
| 101 | 41 | * |
| 102 | 42 | * @return array |
| 103 | 43 | */ |
| 104 | 44 | public function all() { |
| 105 | - if ( ! $this->registered ) { | |
| 106 | - $this->notifications = [ | |
| 107 | - 'registration' => __NAMESPACE__ . '\Notifications\WP\Registration', | |
| 108 | - 'comment' => __NAMESPACE__ . '\Notifications\WP\Comment', | |
| 109 | - ]; | |
| 45 | + if ( $this->notifications ) { | |
| 46 | + return $this->notifications; | |
| 47 | + } | |
| 110 | 48 | |
| 111 | - /** | |
| 112 | - * Fires to allow registration of custom notifications. | |
| 113 | - * | |
| 114 | - * @param Notifications $manager The notifications manager instance | |
| 115 | - */ | |
| 116 | - do_action( 'texty_register_notifications', $this ); | |
| 49 | + $notifications = [ | |
| 50 | + 'registration' => __NAMESPACE__ . '\Notifications\WP\Registration', | |
| 51 | + 'comment' => __NAMESPACE__ . '\Notifications\WP\Comment', | |
| 52 | + ]; | |
| 117 | 53 | |
| 118 | - $this->registered = true; | |
| 54 | + if ( class_exists( 'WooCommerce' ) ) { | |
| 55 | + // WC Admin | |
| 56 | + $notifications['order_admin_processing'] = __NAMESPACE__ . '\Notifications\WC\ProcessingAdmin'; | |
| 57 | + $notifications['order_admin_complete'] = __NAMESPACE__ . '\Notifications\WC\CompleteAdmin'; | |
| 58 | + | |
| 59 | + // WC Customers | |
| 60 | + $notifications['order_customer_hold'] = __NAMESPACE__ . '\Notifications\WC\HoldCustomer'; | |
| 61 | + $notifications['order_customer_processing'] = __NAMESPACE__ . '\Notifications\WC\ProcessingCustomer'; | |
| 62 | + $notifications['order_customer_complete'] = __NAMESPACE__ . '\Notifications\WC\CompleteCustomer'; | |
| 119 | 63 | } |
| 120 | 64 | |
| 121 | - return apply_filters( 'texty_available_notifications', $this->notifications ); | |
| 65 | + if ( class_exists( 'WeDevs_Dokan' ) ) { | |
| 66 | + $notifications['order_dokan_processing'] = __NAMESPACE__ . '\Notifications\Dokan\ProcessingVendor'; | |
| 67 | + $notifications['order_dokan_complete'] = __NAMESPACE__ . '\Notifications\Dokan\CompleteVendor'; | |
| 68 | + } | |
| 69 | + | |
| 70 | + $this->notifications = apply_filters( 'texty_available_notifications', $notifications ); | |
| 71 | + | |
| 72 | + return $this->notifications; | |
| 122 | 73 | } |
| 123 | 74 | |
| 124 | 75 | /** |
| 125 | 76 | * Get the name of the groups |
| @@ -129,19 +80,19 @@ | ||
| 129 | 80 | public function get_groups() { |
| 130 | 81 | return apply_filters( 'texty_notification_groups', [ // phpcs:ignore |
| 131 | 82 | 'wp' => [ |
| 132 | 83 | 'title' => __( 'WordPress', 'texty' ), |
| 133 | - 'description' => __( 'Default WordPress system alerts', 'texty' ), | |
| 84 | + 'description' => '', | |
| 134 | 85 | 'available' => true, |
| 135 | 86 | ], |
| 136 | 87 | 'wc' => [ |
| 137 | 88 | 'title' => __( 'WooCommerce', 'texty' ), |
| 138 | - 'description' => __( 'WooCommerce order and customer alerts', 'texty' ), | |
| 89 | + 'description' => '', | |
| 139 | 90 | 'available' => class_exists( 'WooCommerce' ) ? true : false, |
| 140 | 91 | ], |
| 141 | 92 | 'dokan' => [ |
| 142 | 93 | 'title' => __( 'Dokan', 'texty' ), |
| 143 | - 'description' => __( 'Vendor and marketplace alerts', 'texty' ), | |
| 94 | + 'description' => '', | |
| 144 | 95 | 'available' => class_exists( 'WeDevs_Dokan' ) ? true : false, |
| 145 | 96 | ], |
| 146 | 97 | ] ); // phpcs:ignore |
| 147 | 98 | } |