PluginProbe
Float menu – awesome floating side menu / 6.0
Float menu – awesome floating side menu v6.0
7.2.5 trunk 2.1 2.2 3.0.1 3.1 3.2.2 3.3.1 3.5 3.5.1 3.5.2 3.5.3. 3.5.4 4.0 4.1 4.1.1 4.2 4.3 4.3.1 4.3.2 5.0 5.0.1 5.0.2 5.0.3 5.1 All 57 releases
← All changes | classes/Admin/Settings.php +21 -40 trunk6.0 View file →
@@ -19,12 +19,8 @@
19 19 use FloatMenuLite\WOWP_Plugin;
20 20
21 21 class Settings {
22 22
23 - public function __construct() {
24 -// add_action('wp_ajax_'.WOWP_Plugin::PREFIX . '_ajax_settings', [$this, 'save_item']);
25 - }
26 -
27 23 public static function init(): void {
28 24
29 25 $pages = DashboardHelper::get_files( 'settings' );
30 26 $options = self::get_options();
@@ -39,9 +35,9 @@
39 35
40 36 echo '<div class="wpie-tabs-contents">';
41 37 foreach ( $pages as $key => $page ) {
42 38 $file = DashboardHelper::get_folder_path( 'settings' ) . '/' . $key . '.' . $page['file'] . '.php';
43 - echo '<input type="radio" class="wpie-tab-toggle" name="param[setting_tab]" value="' . absint( $key ) . '" id="setting_tab_' . absint( $key ) . '" ' . checked( $key, $checked, false ) . '>';
39 + echo '<input type="radio" class="wpie-tab-toggle" name="setting_tab" value="' . absint( $key ) . '" id="setting_tab_' . absint( $key ) . '" ' . checked( $key, $checked, false ) . '>';
44 40 if ( file_exists( $file ) ) {
45 41 echo '<div class="wpie-tab-content">';
46 42 require_once $file;
47 43 echo '</div>';
@@ -51,36 +47,26 @@
51 47
52 48 }
53 49
54 50 public static function save_item() {
55 - $raw_data = file_get_contents('php://input');
56 - $request = json_decode($raw_data, true);
57 51
58 - if (json_last_error() !== JSON_ERROR_NONE) {
59 - wp_send_json_error(['message' => 'Invalid JSON']);
52 + if ( empty( $_POST['submit_settings'] ) ) {
53 + return false;
60 54 }
61 55
62 - if (!isset($request['security']) || !wp_verify_nonce($request['security'], WOWP_Plugin::PREFIX . '_settings')) {
63 - wp_send_json_error(['message' => 'Invalid nonce'], 400);
64 - }
56 + $id = absint( $_POST['tool_id'] );
65 57
66 - if ( ! current_user_can( 'manage_options' ) ) {
67 - wp_send_json_error( [ 'message' => 'Permission denied' ], 403 );
68 - }
58 + $settings = apply_filters( WOWP_Plugin::PREFIX . '_save_settings', $_POST );
69 59
70 - $info = ( isset( $request['info'] ) && is_array( $request['info'] ) ) ? $request['info'] : [];
60 + $removes = [ 'wpie_buttons_settings', '_wp_http_referer', 'submit_settings' ];
61 + $keys_flipped = array_flip( $removes );
62 + $settings = array_diff_key( $settings, $keys_flipped );
71 63
72 - $id = isset( $info['tool_id'] ) ? absint( $info['tool_id'] ) : 0;
73 -
74 - $param = ( isset( $info['param'] ) && is_array( $info['param'] ) ) ? $info['param'] : [];
75 -
76 - $settings = apply_filters( WOWP_Plugin::PREFIX . '_save_settings', $param ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound
77 -
78 64 $data = [
79 - 'title' => isset( $info['title'] ) ? sanitize_text_field( wp_unslash( $info['title'] ) ) : '',
80 - 'status' => isset( $info['status'] ) ? 1 : 0,
81 - 'mode' => isset( $info['mode'] ) ? 1 : 0,
82 - 'tag' => isset( $info['tag'] ) ? sanitize_text_field( wp_unslash( $info['tag'] ) ) : '',
65 + 'title' => isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( $_POST['title'] ) ) : '',
66 + 'status' => isset( $_POST['status'] ) ? 1 : 0,
67 + 'mode' => isset( $_POST['mode'] ) ? 1 : 0,
68 + 'tag' => isset( $_POST['tag'] ) ? sanitize_text_field( wp_unslash( $_POST['tag'] ) ) : '',
83 69 'param' => maybe_serialize( $settings ),
84 70 ];
85 71 $formats = [
86 72 '%s',
@@ -99,54 +85,50 @@
99 85 DBManager::update( $data, $where, $formats );
100 86 $id_item = $id;
101 87 }
102 88
103 - wp_send_json_success(['id' => absint($id_item) ]);
89 + wp_safe_redirect( Link::save_item( $id_item ) );
104 90 exit;
105 - // phpcs:enable
91 +
106 92 }
107 93
108 94 public static function deactivate_item( $id = 0 ): void {
109 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
110 95 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
111 96
112 97 if ( ! empty( $id ) ) {
113 - DBManager::update( [ 'status' => '1' ], [ 'id' => $id ], [ '%d' ] );
98 + DBManager::update( [ 'status' => '1' ], [ 'ID' => $id ], [ '%d' ] );
114 99 }
115 100
116 101 }
117 102
118 103 public static function activate_item( $id = 0 ): void {
119 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
120 104 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
121 105
122 106 if ( ! empty( $id ) ) {
123 - DBManager::update( [ 'status' => '' ], [ 'id' => $id ], [ '%d' ] );
107 + DBManager::update( [ 'status' => '' ], [ 'ID' => $id ], [ '%d' ] );
124 108 }
125 109
126 110 }
127 111
128 112 public static function deactivate_mode( $id = 0 ): void {
129 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
130 113 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
131 114
132 115 if ( ! empty( $id ) ) {
133 - DBManager::update( [ 'mode' => '' ], [ 'id' => $id ], [ '%d' ] );
116 + DBManager::update( [ 'mode' => '' ], [ 'ID' => $id ], [ '%d' ] );
134 117 }
135 118
136 119 }
137 120
138 121 public static function activate_mode( $id = 0 ): void {
139 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
140 122 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
141 123
142 124 if ( ! empty( $id ) ) {
143 - DBManager::update( [ 'mode' => '1' ], [ 'id' => $id ], [ '%d' ] );
125 + DBManager::update( [ 'mode' => '1' ], [ 'ID' => $id ], [ '%d' ] );
144 126 }
145 127 }
146 128
147 129 public static function get_options() {
148 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
130 +
149 131 $id = isset( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0;
150 132
151 133 if ( empty( $id ) ) {
152 134 return false;
@@ -151,10 +133,9 @@
151 133 if ( empty( $id ) ) {
152 134 return false;
153 135 }
154 136
155 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
156 - $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : 'update';
137 + $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : 'update';
157 138 $result = DBManager::get_data_by_id( $id );
158 139
159 140 if ( empty( $result ) ) {
160 141 return false;
@@ -176,9 +157,9 @@
176 157
177 158 return $param;
178 159 }
179 160
180 - public static function option( $name, $options ) {
161 + public static function option( $name, $option ) {
181 162 return $options[ $name ] ?? '';
182 163 }
183 164
184 165 }