class-shortcodes-ultimate-admin-settings.php
11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
/**
* The Settings menu component.
*
* @since 5.0.0
*
* @package Shortcodes_Ultimate
* @subpackage Shortcodes_Ultimate/admin
*/
final class Shortcodes_Ultimate_Admin_Settings extends Shortcodes_Ultimate_Admin {
/**
* The plugin settings data.
*
* @since 5.0.0
* @access private
* @var array $plugin_settings The plugin settings data.
*/
private $plugin_settings;
/**
* Default values for a single setting.
*
* @since 5.0.0
* @access private
* @var array $setting_defaults Default values for a single setting.
*/
private $setting_defaults;
/**
* Initialize the class and set its properties.
*
* @since 5.0.0
* @param string $plugin_file The path of the main plugin file
* @param string $plugin_version The current version of the plugin
*/
public function __construct( $plugin_file, $plugin_version, $plugin_prefix ) {
parent::__construct( $plugin_file, $plugin_version, $plugin_prefix );
$this->plugin_settings = array();
$this->setting_defaults = array(
'id' => '',
'title' => '',
'type' => 'text',
'description' => '',
'page' => $this->plugin_prefix . 'settings',
'section' => $this->plugin_prefix . 'general',
'group' => rtrim( $this->plugin_prefix, '-_' ),
'callback' => array( $this, 'the_settings_field' ),
'sanitize' => 'sanitize_text_field',
);
}
/**
* Retrieve the plugin settings data.
*
* @since 5.0.0
* @access protected
* @return array The plugin settings data.
*/
protected function get_plugin_settings() {
if ( empty( $this->plugin_settings ) ) {
/**
* General settings
*/
$this->plugin_settings[] = array(
'id' => 'su_option_custom-css',
'type' => 'css',
'sanitize' => 'wp_strip_all_tags',
'title' => __( 'Custom CSS code', 'shortcodes-ultimate' ),
'description' => __( 'In this field you can write your custom CSS code for shortcodes. These styles will have higher priority compared to original styles of shortcodes. You can use variables in your CSS code. These variables will be replaced by respective values.', 'shortcodes-ultimate' ),
);
$this->plugin_settings[] = array(
'id' => 'su_option_supported_blocks',
'type' => 'checkbox-group',
'sanitize' => array( $this, 'sanitize_checkbox_group' ),
'title' => __( 'Supported blocks', 'shortcodes-ultimate' ),
'description' => __( 'Enable the "Insert Shortcode" button in selected blocks', 'shortcodes-ultimate' ),
'options' => su_get_config( 'supported-blocks' ),
);
$this->plugin_settings[] = array(
'id' => 'su_option_enable_shortcodes_in',
'type' => 'checkbox-group',
'sanitize' => array( $this, 'sanitize_checkbox_group' ),
'title' => __( 'Enable shortcodes in', 'shortcodes-ultimate' ),
'description' => __( 'This option allows you to enable shortcodes in places where they are disabled by default', 'shortcodes-ultimate' ),
'options' => array(
'term_description' => __( 'Term descriptions (Categories, Tags, Custom Taxonomies)', 'shortcodes-ultimate' ),
'widget_text' => __( 'Text widgets', 'shortcodes-ultimate' ),
),
);
/**
* Advanced settings
*/
$this->plugin_settings[] = array(
'id' => 'su_option_prefix',
'sanitize' => array( $this, 'sanitize_prefix' ),
'page' => $this->plugin_prefix . 'advanced-settings',
'group' => $this->plugin_prefix . 'advanced-settings',
'section' => $this->plugin_prefix . 'advanced',
'title' => __( 'Shortcodes prefix', 'shortcodes-ultimate' ),
'description' => __( 'This prefix will be used in shortcode names. For example: set <code>MY_</code> prefix and shortcodes will look like <code>[MY_button]</code>. Please note that this setting does not change shortcodes that have been inserted earlier. Change this setting very carefully.', 'shortcodes-ultimate' ),
);
$this->plugin_settings[] = array(
'id' => 'su_option_custom-formatting',
'type' => 'checkbox',
'sanitize' => array( $this, 'sanitize_checkbox' ),
'page' => $this->plugin_prefix . 'advanced-settings',
'group' => $this->plugin_prefix . 'advanced-settings',
'section' => $this->plugin_prefix . 'advanced',
'title' => __( 'Custom formatting', 'shortcodes-ultimate' ),
'description' => __( 'Enable this option if you face any problems with formatting of nested shortcodes.', 'shortcodes-ultimate' ),
);
$this->plugin_settings[] = array(
'id' => 'su_option_skip',
'type' => 'checkbox',
'sanitize' => array( $this, 'sanitize_checkbox' ),
'page' => $this->plugin_prefix . 'advanced-settings',
'group' => $this->plugin_prefix . 'advanced-settings',
'section' => $this->plugin_prefix . 'advanced',
'title' => __( 'Skip default settings', 'shortcodes-ultimate' ),
'description' => __( 'Enable this option if you don\'t want the inserted shortcode to contain any settings that were not changed by you. As a result, inserted shortcodes will be much shorter.', 'shortcodes-ultimate' ),
);
$this->plugin_settings[] = array(
'id' => 'su_option_generator_access',
'page' => $this->plugin_prefix . 'advanced-settings',
'group' => $this->plugin_prefix . 'advanced-settings',
'section' => $this->plugin_prefix . 'advanced',
'title' => __( 'Required user capability', 'shortcodes-ultimate' ),
'description' => __( 'A user must have this capability to be able to use the "Insert Shortcode" button. Do not change this value if you do not understand its meaning as this may lower the plugin security.', 'shortcodes-ultimate' ),
);
$this->plugin_settings[] = array(
'id' => 'su_option_unsafe_features',
'type' => 'checkbox',
'sanitize' => array( $this, 'sanitize_checkbox' ),
'page' => $this->plugin_prefix . 'advanced-settings',
'group' => $this->plugin_prefix . 'advanced-settings',
'section' => $this->plugin_prefix . 'advanced',
'title' => __( 'Unsafe features', 'shortcodes-ultimate' ),
'description' => sprintf(
'%s <a href="https://getshortcodes.com/docs/unsafe-features/" target="_blank">%s</a>.',
__( 'This option enables potentially unsafe features of the plugin such as onlick attribute of the Button shortcode. The option is enabled by default and is turned off automatically once you have more than one non-admin user on the site.', 'shortcodes-ultimate' ),
__( 'Learn more', 'shortcodes-ultimate' )
),
);
$this->plugin_settings[] = array(
'id' => 'su_option_hide_deprecated',
'type' => 'checkbox',
'sanitize' => array( $this, 'sanitize_checkbox' ),
'page' => $this->plugin_prefix . 'advanced-settings',
'group' => $this->plugin_prefix . 'advanced-settings',
'section' => $this->plugin_prefix . 'advanced',
'title' => __( 'Hide deprecated shortcodes', 'shortcodes-ultimate' ),
'description' => __( 'This option hides all deprecated shortcodes from the Insert Shortcode window and at the Available Shortcodes page. Hidden shortcodes will continue to work.', 'shortcodes-ultimate' ),
);
$this->plugin_settings[] = array(
'id' => 'su_option_do_nested_shortcodes_alt',
'type' => 'checkbox',
'sanitize' => array( $this, 'sanitize_checkbox' ),
'page' => $this->plugin_prefix . 'advanced-settings',
'group' => $this->plugin_prefix . 'advanced-settings',
'section' => $this->plugin_prefix . 'advanced',
'title' => __( 'Nested shortcodes alternative mode', 'shortcodes-ultimate' ),
'description' => __( 'This option enables alternative (deprecated) mode for nested shortcodes.', 'shortcodes-ultimate' ),
);
}
return apply_filters( 'su/admin/settings', $this->plugin_settings );
}
/**
* Add menu page.
*
* @since 5.0.0
*/
public function add_menu_pages() {
/**
* Submenu: Settings
* admin.php?page=shortcodes-ultimate-settings
*/
$this->add_submenu_page(
rtrim( $this->plugin_prefix, '-_' ),
__( 'Settings', 'shortcodes-ultimate' ),
__( 'Settings', 'shortcodes-ultimate' ),
$this->get_capability(),
$this->plugin_prefix . 'settings',
array( $this, 'the_menu_page' )
);
}
/**
* Register plugin settings.
*
* @since 5.0.0
*/
public function add_settings() {
add_settings_section(
$this->plugin_prefix . 'general',
__( 'General settings', 'shortcodes-ultimate' ),
array( $this, 'the_settings_section' ),
$this->plugin_prefix . 'settings'
);
add_settings_section(
$this->plugin_prefix . 'advanced',
null,
array( $this, 'the_settings_section' ),
$this->plugin_prefix . 'advanced-settings'
);
/**
* Register plugin settings.
*/
foreach ( $this->get_plugin_settings() as $setting ) {
$setting = wp_parse_args( $setting, $this->setting_defaults );
$setting['label_for'] = $setting['id'];
add_settings_field(
$setting['id'],
$setting['title'],
$setting['callback'],
$setting['page'],
$setting['section'],
$setting
);
register_setting(
$setting['group'],
$setting['id'],
$setting['sanitize']
);
}
}
/**
* Enqueue JavaScript(s) and Stylesheet(s) for the component.
*
* @since 5.4.0
*/
public function enqueue_scripts() {
if ( ! $this->is_component_page() ) {
return;
}
if ( function_exists( 'wp_enqueue_code_editor' ) ) {
wp_enqueue_code_editor( array( 'type' => 'text/css' ) );
}
wp_enqueue_style(
'shortcodes-ultimate-admin',
plugins_url( 'css/admin.css', __FILE__ ),
false,
filemtime( plugin_dir_path( __FILE__ ) . 'css/admin.css' )
);
}
/**
* Add help tabs and set help sidebar at Add-ons page.
*
* @since 5.0.0
* @param WP_Screen $screen WP_Screen instance.
*/
public function add_help_tabs( $screen ) {
if ( ! $this->is_component_page() ) {
return;
}
$screen->add_help_tab(
array(
'id' => 'shortcodes-ultimate-general',
'title' => __( 'General settings', 'shortcodes-ultimate' ),
'content' => $this->get_template( 'admin/partials/help/settings' ),
)
);
$screen->set_help_sidebar( $this->get_template( 'admin/partials/help/sidebar' ) );
}
/**
* Filter to add action links at plugins screen.
*
* @since 5.0.8
* @param array $links Default links.
*/
public function add_action_links( $links ) {
$plugin_links = array(
sprintf(
'<a href="%s">%s</a>',
esc_attr( $this->get_component_url() ),
esc_html( __( 'Settings', 'shortcodes-ultimate' ) )
),
);
return array_merge( $plugin_links, $links );
}
protected function is_advanced_settings() {
return isset( $_GET['advanced'] );
}
public function maybe_disable_unsafe_features() {
if ( '' === get_option( 'su_option_unsafe_features' ) ) {
return;
}
if ( su_current_user_can_insert() ) {
return;
}
if ( 0 !== get_option( 'su_option_unsafe_features_auto_off', 0 ) ) {
return;
}
update_option( 'su_option_unsafe_features', '' );
add_option( 'su_option_unsafe_features_auto_off', true );
}
}