PluginProbe
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more / trunk
Texty – SMS Notification for WordPress, WooCommerce, Dokan and more vtrunk
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 / Tools.php

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

66 lines 1.7 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 Tools extends Base {
8
9 /**
10 * Initialize
11 *
12 * @return void
13 */
14 public function __construct() {
15 $this->namespace = 'texty/v1';
16 $this->rest_base = 'tools';
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 . '/test',
28 [
29 [
30 'methods' => WP_REST_Server::CREATABLE,
31 'callback' => [ $this, 'test_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 ],
40 ],
41 ]
42 );
43 }
44
45 /*
46 * Send a test.
47 *
48 * @param WP_Rest_Request $request
49 *
50 * @return WP_Rest_Response|WP_Error
51 */
52 public function test_send( $request ) {
53 $to = $request->get_param( 'to' );
54 $message = 'This is a test message from Texty.';
55
56 $status = texty()->gateways()->send( $to, $message );
57
58 $response = [
59 'success' => is_wp_error( $status ) ? false : true,
60 'message' => is_wp_error( $status ) ? $status->get_error_message() : '',
61 ];
62
63 return rest_ensure_response( $response );
64 }
65 }
66