PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.0
YayMail – WooCommerce Email Customizer v4.4.0
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Controllers / TemplateLibraryController.php

TemplateLibraryController.php in YayMail – WooCommerce Email Customizer 4.4.0, at src/Controllers/TemplateLibraryController.php

82 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Controllers;
4
5 use YayMail\Abstracts\BaseController;
6 use YayMail\TemplateLibrary\TemplateLibraryService;
7 use YayMail\Utils\SingletonTrait;
8
9 /**
10 * Template Library Controller
11 *
12 * @method static TemplateLibraryController get_instance()
13 */
14 class TemplateLibraryController extends BaseController {
15 use SingletonTrait;
16
17 protected function __construct() {
18 $this->init_hooks();
19 }
20
21 /**
22 * Register REST routes.
23 *
24 * @return void
25 */
26 protected function init_hooks() {
27 register_rest_route(
28 YAYMAIL_REST_NAMESPACE,
29 '/template-library',
30 [
31 [
32 'methods' => \WP_REST_Server::READABLE,
33 'callback' => [ $this, 'exec_get_templates' ],
34 'permission_callback' => [ $this, 'permission_callback' ],
35 'args' => [
36 'email_type' => [
37 'type' => 'string',
38 'required' => true,
39 ],
40 ],
41 ],
42 ]
43 );
44 }
45
46 /**
47 * Exec wrapper for getting list of templates.
48 *
49 * @param \WP_REST_Request $request Request.
50 *
51 * @return \WP_REST_Response|\WP_Error
52 */
53 public function exec_get_templates( \WP_REST_Request $request ) {
54 return $this->exec( [ $this, 'get_templates' ], $request );
55 }
56
57 /**
58 * Get list of template summaries for current email type.
59 *
60 * @param \WP_REST_Request $request Request.
61 *
62 * @return array
63 */
64 public function get_templates( \WP_REST_Request $request ) {
65 $email_type = sanitize_text_field( $request->get_param( 'email_type' ) );
66
67 if ( empty( $email_type ) ) {
68 return [
69 'success' => false,
70 'message' => __( 'Template name is required.', 'yaymail' ),
71 ];
72 }
73
74 $templates = TemplateLibraryService::get_instance()->get_list( $email_type );
75
76 return [
77 'success' => true,
78 'templates' => $templates,
79 ];
80 }
81 }
82