PluginProbe
Ultimate Store Kit – Addon For WooCommerce, EDD and Elementor / trunk
Ultimate Store Kit – Addon For WooCommerce, EDD and Elementor vtrunk
3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 All 87 releases
ultimate-store-kit / includes / API / Settings.php

Settings.php in Ultimate Store Kit – Addon For WooCommerce, EDD and Elementor trunk, at includes/API/Settings.php

67 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 /**
4 * Core Plugin REST API Settings Handler
5 *
6 * Registers REST routes for saving core admin settings.
7 * Loaded unconditionally so REST requests work outside is_admin().
8 */
9
10 namespace UltimateStoreKit\API;
11
12 use UltimateStoreKit\API\Base;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 class Settings extends Base {
19
20 private static $instance = null;
21
22 public static function get_instance() {
23 if (is_null(self::$instance)) {
24 self::$instance = new self();
25 }
26 return self::$instance;
27 }
28
29 protected function get_namespace() {
30 return 'ultimate-store-kit/v1';
31 }
32
33 protected function get_routes() {
34 return [
35 [
36 'path' => '/settings',
37 'methods' => 'POST',
38 'callback' => [$this, 'save_settings'],
39 ],
40 ];
41 }
42
43 /**
44 * Save core plugin settings.
45 */
46 public function save_settings(\WP_REST_Request $request) {
47 $section = sanitize_text_field($request->get_param('section'));
48 $settings = $request->get_param('settings');
49
50 $allowed_sections = [
51 'ultimate_store_kit_active_modules',
52 'ultimate_store_kit_edd_modules',
53 'ultimate_store_kit_general_modules',
54 'ultimate_store_kit_other_settings',
55 ];
56
57 if (!in_array($section, $allowed_sections, true)) {
58 return $this->error('invalid_section', 'Invalid section');
59 }
60
61 $sanitized = $this->sanitize_settings($settings);
62 update_option($section, $sanitized);
63
64 return $this->success(['message' => __('Settings saved successfully.', 'ultimate-store-kit')]);
65 }
66 }
67