| @@ -225,18 +225,14 @@ | ||
| 225 | 225 | * @return bool |
| 226 | 226 | */ |
| 227 | 227 | public function enabled() { |
| 228 | 228 | $settings = $this->settings(); |
| 229 | - $enabled = isset( $settings['enabled'] ) && $settings['enabled'] === true; | |
| 230 | 229 | |
| 231 | - /** | |
| 232 | - * Filter whether a notification is enabled. | |
| 233 | - * | |
| 234 | - * @param bool $enabled Whether the notification is enabled | |
| 235 | - * @param string $id The notification ID | |
| 236 | - * @param Notification $notification The notification instance | |
| 237 | - */ | |
| 238 | - return apply_filters( 'texty_notification_enabled', $enabled, $this->get_id(), $this ); | |
| 230 | + if ( isset( $settings['enabled'] ) && $settings['enabled'] === true ) { | |
| 231 | + return true; | |
| 232 | + } | |
| 233 | + | |
| 234 | + return false; | |
| 239 | 235 | } |
| 240 | 236 | |
| 241 | 237 | /** |
| 242 | 238 | * Get the notification settings |
| @@ -244,44 +240,30 @@ | ||
| 244 | 240 | * @return array |
| 245 | 241 | */ |
| 246 | 242 | public function settings() { |
| 247 | 243 | $settings = texty()->notifications()->settings(); |
| 248 | - $value = isset( $settings[ $this->get_id() ] ) ? $settings[ $this->get_id() ] : []; | |
| 249 | 244 | |
| 250 | - /** | |
| 251 | - * Filter the notification settings. | |
| 252 | - * | |
| 253 | - * @param array $value The notification settings | |
| 254 | - * @param string $id The notification ID | |
| 255 | - * @param Notification $notification The notification instance | |
| 256 | - */ | |
| 257 | - return apply_filters( 'texty_notification_settings', $value, $this->get_id(), $this ); | |
| 245 | + if ( isset( $settings[ $this->get_id() ] ) ) { | |
| 246 | + return $settings[ $this->get_id() ]; | |
| 247 | + } | |
| 248 | + | |
| 249 | + return []; | |
| 258 | 250 | } |
| 259 | 251 | |
| 260 | 252 | /** |
| 261 | 253 | * Send message to recipients |
| 262 | 254 | * |
| 263 | - * @return bool | |
| 255 | + * @return void | |
| 264 | 256 | */ |
| 265 | - public function send(): bool { | |
| 257 | + public function send() { | |
| 266 | 258 | if ( ! $this->enabled() ) { |
| 267 | - return false; | |
| 259 | + return; | |
| 268 | 260 | } |
| 269 | 261 | |
| 270 | - /** | |
| 271 | - * Filter the recipients for a notification. | |
| 272 | - * | |
| 273 | - * @param array $recipients The recipient phone numbers | |
| 274 | - * @param Notification $notification The notification instance | |
| 275 | - */ | |
| 276 | - $recipients = apply_filters( 'texty_notification_recipients', $this->get_recipients(), $this ); | |
| 262 | + $recipients = $this->get_recipients(); | |
| 277 | 263 | |
| 278 | - // Drop nulls / empty strings before deduping — these can leak in | |
| 279 | - // from an empty `texty_phone` meta or a third-party filter. | |
| 280 | - $recipients = is_array( $recipients ) ? array_values( array_filter( $recipients ) ) : []; | |
| 281 | - | |
| 282 | 264 | if ( ! $recipients ) { |
| 283 | - return false; | |
| 265 | + return; | |
| 284 | 266 | } |
| 285 | 267 | |
| 286 | 268 | // Check unique recipients numbers |
| 287 | 269 | $recipients = array_unique( $recipients ); |
| @@ -286,61 +268,15 @@ | ||
| 286 | 268 | // Check unique recipients numbers |
| 287 | 269 | $recipients = array_unique( $recipients ); |
| 288 | 270 | |
| 289 | 271 | $content = $this->get_message(); |
| 290 | - | |
| 291 | - /** | |
| 292 | - * Filter the notification message content. | |
| 293 | - * | |
| 294 | - * @param string $content The message content | |
| 295 | - * @param Notification $notification The notification instance | |
| 296 | - */ | |
| 297 | - $content = apply_filters( 'texty_notification_message', $content, $this ); | |
| 298 | - | |
| 299 | - /** | |
| 300 | - * Filter the message for a specific notification type. | |
| 301 | - * | |
| 302 | - * @param string $content The message content | |
| 303 | - * @param Notification $notification The notification instance | |
| 304 | - */ | |
| 305 | - $content = apply_filters( 'texty_notification_message_' . $this->get_id(), $content, $this ); | |
| 306 | - | |
| 307 | - /** | |
| 308 | - * Fires before the notification send loop. | |
| 309 | - * | |
| 310 | - * @param Notification $notification The notification instance | |
| 311 | - * @param array $recipients The recipient phone numbers | |
| 312 | - * @param string $content The message content | |
| 313 | - */ | |
| 314 | - do_action( 'texty_before_notification', $this, $recipients, $content ); | |
| 315 | - | |
| 316 | 272 | $gateway = texty()->gateways(); |
| 317 | 273 | |
| 318 | - // Stash the active notification so the after-send logger can attach | |
| 319 | - // notification_id / notification_group to each SmsStat row without | |
| 320 | - // threading them through the gateway pipeline. | |
| 321 | - texty()->notifications()->set_active( $this ); | |
| 274 | + foreach ( $recipients as $number ) { | |
| 275 | + if ( empty( $number ) ) { | |
| 276 | + continue; | |
| 277 | + } | |
| 322 | 278 | |
| 323 | - try { | |
| 324 | - foreach ( $recipients as $number ) { | |
| 325 | - if ( empty( $number ) ) { | |
| 326 | - continue; | |
| 327 | - } | |
| 328 | - | |
| 329 | - $gateway->send( $number, $content ); | |
| 330 | - } | |
| 331 | - } finally { | |
| 332 | - texty()->notifications()->clear_active(); | |
| 279 | + $gateway->send( $number, $content ); | |
| 333 | 280 | } |
| 334 | - | |
| 335 | - /** | |
| 336 | - * Fires after the notification send loop. | |
| 337 | - * | |
| 338 | - * @param Notification $notification The notification instance | |
| 339 | - * @param array $recipients The recipient phone numbers | |
| 340 | - * @param string $content The message content | |
| 341 | - */ | |
| 342 | - do_action( 'texty_after_notification', $this, $recipients, $content ); | |
| 343 | - | |
| 344 | - return true; | |
| 345 | 281 | } |
| 346 | 282 | } |