PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.1
ShopBuilder – WooCommerce Builder For Elementor v2.6.1
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / Admin / Ajax / AdminSettings.php

AdminSettings.php in ShopBuilder – WooCommerce Builder For Elementor 2.6.1, at app/Controllers/Admin/Ajax/AdminSettings.php

185 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Controllers\Admin\Ajax;
4
5 use RadiusTheme\SB\Helpers\Fns;
6 use RadiusTheme\SB\Models\DataModel;
7 use RadiusTheme\SB\Models\Settings;
8 use RadiusTheme\SB\Traits\SingletonTrait;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 /**
16 * Settings Page.
17 */
18 class AdminSettings {
19 /**
20 * Singleton Trait.
21 */
22 use SingletonTrait;
23
24 /**
25 * Construct function
26 */
27 private function __construct() {
28 // add_action( 'wp_ajax_rtsb_settings_fields', [ $this, 'get_settings_fields' ] );
29 // add_action( 'wp_ajax_rtsb_settings_data', [ $this, 'get_settings_data' ] );
30 add_action( 'wp_ajax_rtsb_save_settings_data', [ $this, 'save_settings_data' ] );
31 add_action( 'wp_ajax_rtsb_toggle_modules_activation', [ $this, 'toggle_modules' ] );
32
33 add_action( 'wp_ajax_rtsb_get_multiselect_data', [ $this, 'get_multiselect_data' ] );
34 }
35
36 /**
37 * Get settings fields
38 *
39 * @return void
40 */
41 public function get_multiselect_data() {
42 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! current_user_can( 'manage_options' ) ) {
43 wp_send_json_error( esc_html__( 'Security error: Insufficient permissions.', 'shopbuilder' ) );
44 }
45
46 $func_with_param = sanitize_text_field( $_REQUEST['func_with_param'] ?? '' ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
47 $s = sanitize_text_field( $_REQUEST['s'] ?? '' ); //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
48 $decodedString = stripslashes( $func_with_param );
49 $functionArray = json_decode( $decodedString, true );
50 $className = $functionArray[0];
51 $methodName = $functionArray[1];
52 $argument = $functionArray[2] ?? [];
53 $result = [];
54 $params = [];
55 if ( class_exists( $className ) && method_exists( $className, $methodName ) ) {
56 $params[] = $s; // Modify this array with your parameters
57 $params[] = $argument;
58 $result = call_user_func_array( [ $className, $methodName ], $params );
59 }
60 wp_send_json_success( $result );
61 }
62
63 /**
64 * Get settings fields
65 *
66 * @return void
67 */
68 // public function get_settings_fields() {
69 // $data = Settings::instance()->get_fields();
70 // wp_send_json_success( $data );
71 // }
72
73 /**
74 * Get settings Data
75 *
76 * @return void
77 */
78 public function get_settings_data() {
79 $data = Settings::instance()->get_data();
80 wp_send_json_success( $data );
81 }
82
83 /**
84 * Save settings data
85 *
86 * @return void
87 */
88 public function save_settings_data() {
89 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! current_user_can( 'manage_options' ) ) {
90 wp_send_json_error( esc_html__( 'Security error: Insufficient permissions.', 'shopbuilder' ) );
91 }
92
93 $section_id = isset( $_POST['section_id'] ) ? sanitize_text_field( wp_unslash( $_POST['section_id'] ) ) : '';
94 $block_id = isset( $_POST['block_id'] ) ? sanitize_text_field( wp_unslash( $_POST['block_id'] ) ) : '';
95 // Fns::set_options Sanitized all array values Before saving.
96 $rawOptions = $_POST['options'] ?? []; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
97
98 $sections = Settings::instance()->get_sections();
99 $options = [];
100 if ( ! empty( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) ) {
101 $fields = $sections[ $section_id ]['list'][ $block_id ]['fields'];
102 $db_options = Fns::get_options( $section_id, $block_id );
103 foreach ( $fields as $field_id => $field ) {
104 if ( ! array_key_exists( $field_id, $db_options ) ) {
105 $type = 'array' === gettype( $field['value'] ) ? [] : '';
106 $options[ $field_id ] = ! empty( $field['value'] ) ? $field['value'] : $type;
107 }
108 }
109 }
110
111 $rawOptions = wp_parse_args( $rawOptions, $options );
112
113 $status = Fns::set_options( $section_id, $block_id, $rawOptions );
114
115 if ( boolval( $status['status'] ) ) {
116 do_action( 'rtsb/after/saved/settings/success/' . $section_id . '/' . $block_id, $rawOptions );
117 do_action( 'rtsb/after/saved/settings/success', $section_id, $block_id, $rawOptions );
118 wp_send_json_success( $status );
119 } else {
120 wp_send_json_error( $status );
121 }
122 }
123
124 /**
125 * Toggle modules
126 *
127 * @return void
128 */
129 public function toggle_modules() {
130
131 if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) || ! current_user_can( 'manage_options' ) ) {
132 wp_send_json_error(
133 [
134 'message' => esc_html__( 'Security error: Insufficient permissions.', 'shopbuilder' ),
135 ]
136 );
137 }
138
139 $section_id = isset( $_POST['section_id'] ) ? sanitize_text_field( wp_unslash( $_POST['section_id'] ) ) : '';
140 $module_ids = isset( $_POST['module_ids'] ) ? array_map( 'sanitize_text_field', $_POST['module_ids'] ) : []; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
141 $type = isset( $_POST['type'] ) && 'active' === sanitize_text_field( wp_unslash( $_POST['type'] ) ) ? 'active' : false;
142
143 if ( ! $section_id || empty( $module_ids ) ) {
144 wp_send_json_error(
145 [
146 'message' => esc_html__( 'Section , block or options may be empty', 'shopbuilder' ),
147 ]
148 );
149 }
150
151 $sections = Settings::instance()->get_sections();
152 if ( empty( $sections[ $section_id ] ) ) {
153 wp_send_json_error(
154 [
155 'message' => esc_html__( 'No section found with given data', 'shopbuilder' ),
156 ]
157 );
158 }
159 $options = DataModel::source()->get_option( $section_id, [] );
160 foreach ( $module_ids as $module_id ) {
161 if ( isset( $sections[ $section_id ]['list'][ $module_id ] ) ) {
162 if ( isset( $sections[ $section_id ]['list'][ $module_id ]['package'] ) && 'pro-disabled' === $sections[ $section_id ]['list'][ $module_id ]['package'] ) {
163 continue;
164 }
165 if ( $type === 'active' ) {
166 $options[ $module_id ]['active'] = 'on';
167 $sections[ $section_id ]['list'][ $module_id ]['active'] = 'on';
168 } else {
169 $options[ $module_id ]['active'] = '';
170 $sections[ $section_id ]['list'][ $module_id ]['active'] = '';
171 }
172 }
173 }
174
175 DataModel::source()->set_option( $section_id, $options );
176
177 wp_send_json_success(
178 [
179 'message' => esc_html__( 'Successfully Saved', 'shopbuilder' ),
180 'sections' => $sections,
181 ]
182 );
183 }
184 }
185