PluginProbe
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more / 1.1
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more v1.1
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 / Api / Send.php

Send.php in Texty – SMS Notification for WordPress, WooCommerce, Dokan and more 1.1, at includes/Api/Send.php

71 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Texty\Api;
4
5 use WP_REST_Server;
6
7 class Send extends Base {
8
9 /**
10 * Initialize
11 *
12 * @return void
13 */
14 public function __construct() {
15 $this->namespace = 'texty/v1';
16 $this->rest_base = 'send';
17 }
18
19 /**
20 * Registers the routes for the objects of the controller.
21 *
22 * @return void
23 */
24 public function register_routes() {
25 register_rest_route(
26 $this->namespace,
27 '/' . $this->rest_base,
28 [
29 [
30 'methods' => WP_REST_Server::CREATABLE,
31 'callback' => [ $this, 'send' ],
32 'permission_callback' => [ $this, 'admin_permissions_check' ],
33 'args' => [
34 'to' => [
35 'description' => __( 'The to phone number', 'texty' ),
36 'type' => 'string',
37 'required' => true,
38 ],
39 'message' => [
40 'description' => __( 'The message to be sent', 'texty' ),
41 'type' => 'string',
42 'required' => true,
43 ],
44 ],
45 ],
46 ]
47 );
48 }
49
50 /*
51 * Send the message
52 *
53 * @param WP_Rest_Request $request
54 *
55 * @return WP_Rest_Response|WP_Error
56 */
57 public function send( $request ) {
58 $to = $request->get_param( 'to' );
59 $message = $request->get_param( 'message' );
60
61 $status = texty()->gateways()->send( $to, $message );
62
63 $response = [
64 'success' => is_wp_error( $status ) ? false : true,
65 'message' => is_wp_error( $status ) ? $status->get_error_message() : '',
66 ];
67
68 return rest_ensure_response( $response );
69 }
70 }
71