PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.2
WP Coder – Insert & Manage Code Snippets v4.2
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
wp-coder / classes / Dashboard / Settings.php

Settings.php in WP Coder – Insert & Manage Code Snippets 4.2, at classes/Dashboard/Settings.php

164 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 namespace WPCoder\Dashboard;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use WPCoder\WPCoder;
8
9 class Settings {
10
11 public static function init(): void {
12 $pages = DashboardHelper::get_files( 'settings' );
13
14 $default = Field::getDefault();
15
16 $i = 0;
17 echo '<div class="wowp-settins__tabs" id="wowp-settings-tabs">';
18 foreach ( $pages as $key => $page ) {
19 $tab = ! empty( $default['param']['tab'] ) ? $default['param']['tab'] : 'html-code';
20
21 echo '<input type="radio" class="wowp-settins__tabs-radio" name="param[tab]" value="' . esc_attr( $page['file'] ) . '" id="wowp-tab-' . esc_attr( $page['file'] ) . '" ' . checked( $tab, $page['file'], false ) . '>';
22 echo '<label class="wowp-settins__tabs-tab" for="wowp-tab-' . esc_attr( $page['file'] ) . '">' . esc_html( $page['name'] ) . '</label>';
23
24 $i ++;
25 }
26 ?>
27
28 <div class="popover-container">
29 <button id="popover-toggle" class="wowp-button button button-secondary">Hide Tabs</button>
30
31 <div class="popover" id="popover-box">
32 <div class="wowp-field has-checkbox is-reverse">
33 <span class="label">
34 <?php esc_html_e( 'HTML', 'wp-coder' ); ?>
35 </span>
36 <label class="switch">
37 <?php Field::checkbox( '[hide_html]' ); ?>
38 <span class="slider"></span>
39 </label>
40 </div>
41 <div class="wowp-field has-checkbox is-reverse">
42 <span class="label">
43 <?php esc_html_e( 'CSS', 'wp-coder' ); ?>
44 </span>
45 <label class="switch">
46 <?php Field::checkbox( '[hide_css]' ); ?>
47 <span class="slider"></span>
48 </label>
49 </div>
50 <div class="wowp-field has-checkbox is-reverse">
51 <span class="label">
52 <?php esc_html_e( 'JS', 'wp-coder' ); ?>
53 </span>
54 <label class="switch">
55 <?php Field::checkbox( '[hide_js]' ); ?>
56 <span class="slider"></span>
57 </label>
58 </div>
59 <div class="wowp-field has-checkbox is-reverse">
60 <span class="label">
61 <?php esc_html_e( 'PHP', 'wp-coder' ); ?>
62 </span>
63 <label class="switch">
64 <?php Field::checkbox( '[hide_php]' ); ?>
65 <span class="slider"></span>
66 </label>
67 </div>
68
69 <div class="wowp-field has-checkbox is-reverse">
70 <span class="label">
71 <?php esc_html_e( 'Scripts & Styles', 'wp-coder' ); ?>
72 </span>
73 <label class="switch">
74 <?php Field::checkbox( '[hide_include]' ); ?>
75 <span class="slider"></span>
76 </label>
77 </div>
78 </div>
79 </div>
80
81 <?php
82
83 $i = 0;
84 foreach ( $pages as $key => $page ) {
85 $file = DashboardHelper::get_folder_path( 'settings' ) . '/' . $key . '.' . $page['file'] . '.php';
86
87 if ( file_exists( $file ) ) {
88
89 echo '<div class="wowp-settins__tabs-content" data-content="wowp-tab-' . esc_attr( $page['file'] ) . '">';
90
91 require_once $file;
92
93 echo '<input type="submit" name="submit_settings" class="wowp-button button button-dark button-hero m-top" value="' . esc_attr__( 'Save', 'wp-coder' ) . '">';
94 echo '</div>';
95 }
96 $i ++;
97 }
98 echo '</div>';
99 }
100
101
102 public static function save_item() {
103
104 if ( empty( $_POST['submit_settings'] ) ) {
105 return false;
106 }
107
108 $id = absint( $_POST['tool_id'] );
109 $settings = apply_filters( WPCoder::PREFIX . '_save_settings', [ 'data' => [], 'formats' => [] ], $_POST );
110
111 if ( empty( $id ) ) {
112 $id_item = DBManager::insert( $settings['data'], $settings['formats'] );
113 } else {
114 $where = [
115 'id' => absint( $id ),
116 ];
117 DBManager::update( $settings['data'], $where, $settings['formats'] );
118 $id_item = $id;
119 }
120
121 FolderManager::update_files( $settings['data'], $id_item );
122
123 wp_safe_redirect( Link::save_item( $id_item ) );
124 exit;
125
126 }
127
128 public static function deactivate_item( $id = 0 ): void {
129 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
130
131 if ( ! empty( $id ) ) {
132 DBManager::update( [ 'status' => '1' ], [ 'ID' => $id ], [ '%d' ] );
133 }
134
135 }
136
137 public static function activate_item( $id = 0 ): void {
138 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
139
140 if ( ! empty( $id ) ) {
141 DBManager::update( [ 'status' => '' ], [ 'ID' => $id ], [ '%d' ] );
142 }
143
144 }
145
146 public static function deactivate_mode( $id = 0 ): void {
147 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
148
149 if ( ! empty( $id ) ) {
150 DBManager::update( [ 'mode' => '' ], [ 'ID' => $id ], [ '%d' ] );
151 }
152
153 }
154
155 public static function activate_mode( $id = 0 ): void {
156 $id = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : $id;
157
158 if ( ! empty( $id ) ) {
159 DBManager::update( [ 'mode' => '1' ], [ 'ID' => $id ], [ '%d' ] );
160 }
161
162 }
163
164 }