PluginProbe
Button Generator – Easily Create Custom Buttons with Icons and Analytics / 3.2.3
Button Generator – Easily Create Custom Buttons with Icons and Analytics v3.2.3
trunk 1.1.1 2.0 2.1 2.2 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.2 3.1.3 3.2 3.2.1 3.2.2 3.2.3 All 28 releases
button-generation / classes / Admin / Settings.php

Settings.php in Button Generator – Easily Create Custom Buttons with Icons and Analytics 3.2.3, at classes/Admin/Settings.php

172 lines 5.0 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 ButtonGenerator\Admin;
16
17 defined( 'ABSPATH' ) || exit;
18
19 use ButtonGenerator\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
53 if ( empty( $_POST['submit_settings'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
54 return false;
55 }
56
57 $id = isset( $_POST['tool_id'] ) ? absint( wp_unslash( $_POST['tool_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing
58
59 $settings = apply_filters( WOWP_Plugin::PREFIX . '_save_settings', $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
60
61 $removes = [ 'wpie_buttons_settings', '_wp_http_referer', 'submit_settings' ];
62 $keys_flipped = array_flip( $removes );
63 $settings = array_diff_key( $settings, $keys_flipped );
64
65 $data = [
66 'title' => isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( $_POST['title'] ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Missing
67 'status' => isset( $_POST['status'] ) ? 1 : 0, // phpcs:ignore WordPress.Security.NonceVerification.Missing
68 'mode' => isset( $_POST['mode'] ) ? 1 : 0, // phpcs:ignore WordPress.Security.NonceVerification.Missing
69 'tag' => isset( $_POST['tag'] ) ? sanitize_text_field( wp_unslash( $_POST['tag'] ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Missing
70 'param' => maybe_serialize( $settings ),
71 ];
72 $formats = [
73 '%s',
74 '%d',
75 '%d',
76 '%s',
77 '%s'
78 ];
79
80 if ( empty( $id ) ) {
81 $id_item = DBManager::insert( $data, $formats );
82 } else {
83 $where = [
84 'id' => absint( $id ),
85 ];
86 DBManager::update( $data, $where, $formats );
87 $id_item = $id;
88 }
89
90 wp_safe_redirect( Link::save_item( $id_item ) );
91 exit;
92
93 }
94
95 public static function deactivate_item( $id = 0 ): void {
96 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
97 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
98
99 if ( ! empty( $id ) ) {
100 DBManager::update( [ 'status' => '1' ], [ 'ID' => $id ], [ '%d' ] );
101 }
102
103 }
104
105 public static function activate_item( $id = 0 ): void {
106 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
107 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
108
109 if ( ! empty( $id ) ) {
110 DBManager::update( [ 'status' => '' ], [ 'ID' => $id ], [ '%d' ] );
111 }
112
113 }
114
115 public static function deactivate_mode( $id = 0 ): void {
116 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
117 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
118
119 if ( ! empty( $id ) ) {
120 DBManager::update( [ 'mode' => '' ], [ 'ID' => $id ], [ '%d' ] );
121 }
122
123 }
124
125 public static function activate_mode( $id = 0 ): void {
126 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
127 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
128
129 if ( ! empty( $id ) ) {
130 DBManager::update( [ 'mode' => '1' ], [ 'ID' => $id ], [ '%d' ] );
131 }
132 }
133
134 public static function get_options() {
135
136 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
137 $id = isset( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0;
138
139 if ( empty( $id ) ) {
140 return false;
141 }
142
143 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
144 $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : 'update';
145 $result = DBManager::get_data_by_id( $id );
146
147 if ( empty( $result ) ) {
148 return false;
149 }
150
151 $param = ( ! empty( $result->param ) ) ? maybe_unserialize( $result->param ) : [];
152
153 $param['tag'] = $result->tag;
154 $param['status'] = $result->status;
155 $param['mode'] = $result->mode;
156
157 if ( $action === 'duplicate' ) {
158 $param['id'] = '';
159 $param['title'] = '';
160 } else {
161 $param['id'] = $id;
162 $param['title'] = $result->title;
163 }
164
165 return $param;
166 }
167
168 public static function option( $name, $option ) {
169 return $options[ $name ] ?? '';
170 }
171
172 }