PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
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 / SettingController.php

SettingController.php in YayMail – WooCommerce Email Customizer trunk, at src/Controllers/SettingController.php

66 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\Models\SettingModel;
7 use YayMail\Utils\SingletonTrait;
8
9 /**
10 * Settings Controller
11 * * @method static SettingController get_instance()
12 */
13 class SettingController extends BaseController {
14 use SingletonTrait;
15
16 private $model = null;
17
18 protected function __construct() {
19 $this->model = SettingModel::get_instance();
20 $this->init_hooks();
21 }
22
23 protected function init_hooks() {
24 register_rest_route(
25 YAYMAIL_REST_NAMESPACE,
26 '/settings',
27 [
28 [
29 'methods' => \WP_REST_Server::READABLE,
30 'callback' => [ $this, 'exec_get_settings' ],
31 'permission_callback' => [ $this, 'permission_callback' ],
32 ],
33 [
34 'methods' => \WP_REST_Server::EDITABLE,
35 'callback' => [ $this, 'exec_update_settings' ],
36 'permission_callback' => [ $this, 'permission_callback' ],
37 ],
38 ]
39 );
40 }
41
42 public function exec_get_settings( \WP_REST_Request $request ) {
43 return $this->exec( [ $this, 'get_settings' ], $request );
44 }
45
46 public function get_settings() {
47 $settings = $this->model::find_all();
48 return $settings;
49 }
50
51 public function exec_update_settings( \WP_REST_Request $request ) {
52 return $this->exec( [ $this, 'update_settings' ], $request );
53 }
54
55 public function update_settings( \WP_REST_Request $request ) {
56 $data = json_decode( $request->get_param( 'data' ), true );
57 $settings = is_array( $data ) ? array_map( 'sanitize_text_field', wp_unslash( $data ) ) : [];
58 $settings['custom_css'] = wp_strip_all_tags( isset( $data['custom_css'] ) ? $data['custom_css'] : '' );
59 $this->model::update( $settings );
60 return [
61 'success' => true,
62 'data' => $settings,
63 ];
64 }
65 }
66