routes.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | use Give\FormBuilder\EmailPreview\Controllers\SendEmailPreview; |
| 4 | use Give\FormBuilder\EmailPreview\Controllers\ShowEmailPreview; |
| 5 | |
| 6 | return [ |
| 7 | |
| 8 | /* |
| 9 | |-------------------------------------------------------------------------- |
| 10 | | Show the HTML of the email preview |
| 11 | |-------------------------------------------------------------------------- |
| 12 | | |
| 13 | */ |
| 14 | |
| 15 | 'show' => [ |
| 16 | 'methods' => WP_REST_Server::CREATABLE, |
| 17 | 'callback' => [give(ShowEmailPreview::class), '__invoke'], |
| 18 | 'permission_callback' => function () { |
| 19 | return current_user_can('manage_options'); |
| 20 | }, |
| 21 | 'args' => [ |
| 22 | 'email_type' => [ |
| 23 | 'required' => true, |
| 24 | 'type' => 'string', |
| 25 | 'sanitize_callback' => 'sanitize_text_field', |
| 26 | ], |
| 27 | 'form_id' => [ |
| 28 | 'required' => true, |
| 29 | 'type' => 'string', |
| 30 | 'sanitize_callback' => 'absint', |
| 31 | ], |
| 32 | ], |
| 33 | ], |
| 34 | |
| 35 | /* |
| 36 | |-------------------------------------------------------------------------- |
| 37 | | Send the email preview to a specified address |
| 38 | |-------------------------------------------------------------------------- |
| 39 | | |
| 40 | */ |
| 41 | |
| 42 | 'send' => [ |
| 43 | 'methods' => WP_REST_Server::CREATABLE, |
| 44 | 'callback' => [give(SendEmailPreview::class), '__invoke'], |
| 45 | 'permission_callback' => function () { |
| 46 | return current_user_can('manage_options'); |
| 47 | }, |
| 48 | 'args' => [ |
| 49 | 'email_type' => [ |
| 50 | 'required' => true, |
| 51 | 'type' => 'string', |
| 52 | 'sanitize_callback' => 'sanitize_text_field', |
| 53 | ], |
| 54 | 'email_address' => [ |
| 55 | 'required' => true, |
| 56 | 'type' => 'string', |
| 57 | 'sanitize_callback' => 'sanitize_email', |
| 58 | ], |
| 59 | ], |
| 60 | ], |
| 61 | ]; |
| 62 |