PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / trunk
OttoKit: All-in-One Automation Platform vtrunk
1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Controllers / SettingsController.php
suretriggers / src / Controllers Last commit date
AuthController.php 3 months ago AutomationController.php 11 months ago EventController.php 11 months ago GlobalSearchController.php 2 weeks ago IntegrationsController.php 11 months ago OptionController.php 3 years ago RestController.php 4 weeks ago RoutesController.php 1 year ago SettingsController.php 10 months ago WebhookRequestsController.php 1 month ago
SettingsController.php
94 lines
1 <?php
2 /**
3 * SettingsController.
4 * php version 5.6
5 *
6 * @category SettingsController
7 * @package SureTrigger
8 * @author BSF <username@example.com>
9 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
10 * @link https://www.brainstormforce.com/
11 * @since 1.0.0
12 */
13
14 namespace SureTriggers\Controllers;
15
16 use SureTriggers\Traits\SingletonLoader;
17
18 if ( ! class_exists( 'SettingsController' ) ) :
19 /**
20 * SettingsController
21 *
22 * @category SettingsController
23 * @package SureTrigger
24 * @author BSF <username@example.com>
25 * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3
26 * @link https://www.brainstormforce.com/
27 * @since 1.0.0
28 */
29 class SettingsController {
30
31 use SingletonLoader;
32
33 /**
34 * SettingsController constructor.
35 */
36 public function __construct() {
37 add_action( 'wp_ajax_suretriggers_save_settings', [ $this, 'suretriggers_save_settings_callback' ] );
38 add_action( 'wp_ajax_nopriv_suretriggers_save_settings', [ $this, 'suretriggers_settings_unauthorized_access' ] );
39 }
40
41 /**
42 * Save settings.
43 *
44 * @return void
45 */
46 public function suretriggers_settings_unauthorized_access() {
47 wp_send_json_error( [ 'message' => 'Unauthorized access' ] );
48 }
49
50 /**
51 * Save settings.
52 *
53 * @return void
54 */
55 public function suretriggers_save_settings_callback() {
56 if ( ! current_user_can( 'manage_options' ) ) {
57 wp_send_json_error( [ 'message' => 'Permission denied' ] );
58 }
59 if ( ! isset( $_POST['suretriggers_settings_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['suretriggers_settings_nonce'] ) ), 'suretriggers_settings_nonce_action' ) ) {
60 wp_send_json_error( [ 'message' => 'Security check failed' ] );
61 }
62 $user_id = get_current_user_id();
63 $transient_name = 'suretriggers_settings_save_' . $user_id;
64 if ( get_transient( $transient_name ) ) {
65 wp_send_json_error( [ 'message' => 'Please wait before submitting again' ] );
66 }
67 set_transient( $transient_name, true, 3 );
68
69 // Always reset to empty arrays first.
70 $user_ids = [];
71 $user_roles = [];
72
73 // Process user IDs if present.
74 if ( isset( $_POST['st_selected_users'] ) && is_array( $_POST['st_selected_users'] ) ) {
75 $user_ids = array_map( 'absint', array_map( 'sanitize_text_field', wp_unslash( $_POST['st_selected_users'] ) ) );
76 }
77
78 // Process user roles if present.
79 if ( isset( $_POST['st_selected_user_roles'] ) && is_array( $_POST['st_selected_user_roles'] ) ) {
80 $user_roles = array_map( 'sanitize_key', array_map( 'sanitize_text_field', wp_unslash( $_POST['st_selected_user_roles'] ) ) );
81 }
82
83 // Update options with the processed arrays (empty or with values).
84 update_option( 'suretriggers_enabled_users', $user_ids );
85 update_option( 'suretriggers_enabled_user_roles', $user_roles );
86
87 wp_send_json_success( [ 'message' => 'Settings saved successfully' ] );
88 }
89
90 }
91 SettingsController::get_instance();
92
93 endif;
94