PluginProbe
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more / 0.2
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more v0.2
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 / Gateways.php

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

66 lines 1.5 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 Texty\Gateways\GatewayInterface;
6 use WP_Error;
7
8 /**
9 * Manager Class
10 */
11 class Gateways {
12
13 /**
14 * Send the message from the active gateway
15 *
16 * @param string $to The TO phone number
17 * @param string $message The message to send
18 *
19 * @return bool|WP_Error
20 */
21 public function send( $to, $message ) {
22 $gateway = $this->active_gateway();
23
24 if ( $gateway instanceof GatewayInterface ) {
25 return $gateway->send( $to, $message );
26 }
27
28 return false;
29 }
30
31 /**
32 * Get the active gateway
33 *
34 * @return Gateways\GatewayInterface|false
35 */
36 public function active_gateway() {
37 $gateways = $this->all();
38 $gateway = texty()->settings()->gateway();
39
40 if ( $gateway && array_key_exists( $gateway, $gateways ) ) {
41 return new $gateways[ $gateway ]();
42 }
43
44 return false;
45 }
46
47 /**
48 * Get all the available gateways
49 *
50 * @return array
51 */
52 public function all() {
53 $gateways = [
54 'twilio' => __NAMESPACE__ . '\Gateways\Twilio',
55 'vonage' => __NAMESPACE__ . '\Gateways\Vonage',
56 // 'clickatell' => __NAMESPACE__ . '\Gateways\Clickatell',
57 ];
58
59 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
60 $gateways['fake'] = __NAMESPACE__ . '\Gateways\Fake';
61 }
62
63 return apply_filters( 'texty_available_gateways', $gateways );
64 }
65 }
66