PluginProbe
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more / 2.0.0
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more v2.0.0
2.0.2 trunk 0.2 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 2.0.0 2.0.1
texty / includes / Compliance.php

Compliance.php in Texty – SMS Notification for WordPress, WooCommerce, Dokan and more 2.0.0, at includes/Compliance.php

102 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Texty;
4
5 use WP_Error;
6
7 defined( 'ABSPATH' ) || exit;
8
9 /**
10 * Compliance Class.
11 *
12 * Wires global notification settings into the send pipeline:
13 * - Pause all outgoing SMS when `pause_all` is on.
14 * - Append company name to outgoing messages.
15 *
16 * @since TEXTY_VERSION
17 */
18 class Compliance {
19
20 /**
21 * Initialize hooks.
22 */
23 public function __construct() {
24 add_filter( 'texty_pre_send_sms', [ $this, 'maybe_block_send' ], 10, 4 );
25 add_filter( 'texty_sms_message', [ $this, 'maybe_append_footer' ], 10, 3 );
26 }
27
28 /**
29 * Short-circuit the send pipeline when paused.
30 *
31 * @param null|mixed $pre_send Existing short-circuit value.
32 * @param string $to Recipient phone number.
33 * @param string $message Message body.
34 * @param mixed $gateway Gateway instance.
35 *
36 * @return null|WP_Error
37 */
38 public function maybe_block_send( $pre_send, $to, $message, $gateway ) {
39 unset( $to, $message, $gateway );
40
41 // Respect a previous short-circuit (don't override an upstream filter).
42 if ( null !== $pre_send ) {
43 return $pre_send;
44 }
45
46 $settings = texty()->notification_settings();
47
48 if ( ! empty( $settings->get( 'pause_all' ) ) ) {
49 return new WP_Error(
50 'texty_paused',
51 __( 'Outgoing SMS notifications are paused.', 'texty' )
52 );
53 }
54
55 return null;
56 }
57
58 /**
59 * Append the company name footer to outgoing messages.
60 *
61 * @param string $message Message body.
62 * @param string $to Recipient phone number.
63 * @param mixed $gateway Gateway instance.
64 *
65 * @return string
66 */
67 public function maybe_append_footer( $message, $to, $gateway ) {
68 unset( $to, $gateway );
69
70 if ( ! is_string( $message ) ) {
71 return $message;
72 }
73
74 $settings = texty()->notification_settings();
75 $footer = [];
76
77 if ( ! empty( $settings->get( 'append_company_name' ) ) ) {
78 $store_name = (string) get_bloginfo( 'name' );
79
80 /**
81 * Filter the company / store name appended to outgoing SMS.
82 *
83 * @since TEXTY_VERSION
84 *
85 * @param string $store_name Default store name (site title).
86 */
87 $store_name = (string) apply_filters( 'texty_company_name', $store_name );
88
89 if ( '' !== $store_name ) {
90 /* translators: %s: company / store name */
91 $footer[] = sprintf( __( 'from %s', 'texty' ), $store_name );
92 }
93 }
94
95 if ( empty( $footer ) ) {
96 return $message;
97 }
98
99 return rtrim( $message ) . "\n\n" . implode( ' ', $footer );
100 }
101 }
102