PluginProbe
Float menu – awesome floating side menu / 6.0.2
Float menu – awesome floating side menu v6.0.2
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
float-menu / classes / Admin / Settings.php

Settings.php in Float menu – awesome floating side menu 6.0.2, at classes/Admin/Settings.php

165 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Settings
5 *
6 * Handles the settings functionality for the plugin.
7 *
8 * @package WowPlugin
9 * @subpackage Admin
10 * @author Dmytro Lobov <dev@wow-company.com>, Wow-Company
11 * @copyright 2024 Dmytro Lobov
12 * @license GPL-2.0+
13 */
14
15 namespace FloatMenuLite\Admin;
16
17 defined( 'ABSPATH' ) || exit;
18
19 use FloatMenuLite\WOWP_Plugin;
20
21 class Settings {
22
23 public static function init(): void {
24
25 $pages = DashboardHelper::get_files( 'settings' );
26 $options = self::get_options();
27 $checked = $options['setting_tab'] ?? 1;
28
29 echo '<h3 class="wpie-tabs">';
30 foreach ( $pages as $key => $page ) {
31 $class = ( absint( $checked ) === $key ) ? ' selected' : '';
32 echo '<label class="wpie-tab-label' . esc_attr( $class ) . '" for="setting_tab_' . absint( $key ) . '">' . esc_html( $page['name'] ) . '</label>';
33 }
34 echo '</h3>';
35
36 echo '<div class="wpie-tabs-contents">';
37 foreach ( $pages as $key => $page ) {
38 $file = DashboardHelper::get_folder_path( 'settings' ) . '/' . $key . '.' . $page['file'] . '.php';
39 echo '<input type="radio" class="wpie-tab-toggle" name="setting_tab" value="' . absint( $key ) . '" id="setting_tab_' . absint( $key ) . '" ' . checked( $key, $checked, false ) . '>';
40 if ( file_exists( $file ) ) {
41 echo '<div class="wpie-tab-content">';
42 require_once $file;
43 echo '</div>';
44 }
45 }
46 echo '</div>';
47
48 }
49
50 public static function save_item() {
51
52 if ( empty( $_POST['submit_settings'] ) ) {
53 return false;
54 }
55
56 $id = absint( $_POST['tool_id'] );
57
58 $settings = apply_filters( WOWP_Plugin::PREFIX . '_save_settings', $_POST );
59
60 $removes = [ 'wpie_buttons_settings', '_wp_http_referer', 'submit_settings' ];
61 $keys_flipped = array_flip( $removes );
62 $settings = array_diff_key( $settings, $keys_flipped );
63
64 $data = [
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'] ) ) : '',
69 'param' => maybe_serialize( $settings ),
70 ];
71 $formats = [
72 '%s',
73 '%d',
74 '%d',
75 '%s',
76 '%s'
77 ];
78
79 if ( empty( $id ) ) {
80 $id_item = DBManager::insert( $data, $formats );
81 } else {
82 $where = [
83 'id' => absint( $id ),
84 ];
85 DBManager::update( $data, $where, $formats );
86 $id_item = $id;
87 }
88
89 wp_safe_redirect( Link::save_item( $id_item ) );
90 exit;
91
92 }
93
94 public static function deactivate_item( $id = 0 ): void {
95 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
96
97 if ( ! empty( $id ) ) {
98 DBManager::update( [ 'status' => '1' ], [ 'ID' => $id ], [ '%d' ] );
99 }
100
101 }
102
103 public static function activate_item( $id = 0 ): void {
104 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
105
106 if ( ! empty( $id ) ) {
107 DBManager::update( [ 'status' => '' ], [ 'ID' => $id ], [ '%d' ] );
108 }
109
110 }
111
112 public static function deactivate_mode( $id = 0 ): void {
113 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
114
115 if ( ! empty( $id ) ) {
116 DBManager::update( [ 'mode' => '' ], [ 'ID' => $id ], [ '%d' ] );
117 }
118
119 }
120
121 public static function activate_mode( $id = 0 ): void {
122 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
123
124 if ( ! empty( $id ) ) {
125 DBManager::update( [ 'mode' => '1' ], [ 'ID' => $id ], [ '%d' ] );
126 }
127 }
128
129 public static function get_options() {
130
131 $id = isset( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0;
132
133 if ( empty( $id ) ) {
134 return false;
135 }
136
137 $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : 'update';
138 $result = DBManager::get_data_by_id( $id );
139
140 if ( empty( $result ) ) {
141 return false;
142 }
143
144 $param = ( ! empty( $result->param ) ) ? maybe_unserialize( $result->param ) : [];
145
146 $param['tag'] = $result->tag;
147 $param['status'] = $result->status;
148 $param['mode'] = $result->mode;
149
150 if ( $action === 'duplicate' ) {
151 $param['id'] = '';
152 $param['title'] = '';
153 } else {
154 $param['id'] = $id;
155 $param['title'] = $result->title;
156 }
157
158 return $param;
159 }
160
161 public static function option( $name, $option ) {
162 return $options[ $name ] ?? '';
163 }
164
165 }