PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.2.7
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.2.7
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
← All changes | admin/pages/settings.php +234 -199 2.0.42.2.7 View file →
@@ -1,246 +1,281 @@
1 1 <?php
2 - /**
3 - * The file contains a short help info.
4 - *
5 - * @author Alex Kovalev <alex.kovalevv@gmail.com>
6 - * @copyright (c) 2018, OnePress Ltd
7 - *s
8 - * @package core
9 - * @since 1.0.0
10 - */
2 +/**
3 + * The file contains a short help info.
4 + *
5 + * @author Alex Kovalev <alex.kovalevv@gmail.com>
6 + * @since 1.0.0
7 + * @package core
8 + * @copyright (c) 2018, OnePress Ltd
9 + */
11 10
12 - // Exit if accessed directly
13 - if( !defined('ABSPATH') ) {
14 - exit;
15 - }
11 +// Exit if accessed directly
12 +if ( ! defined( 'ABSPATH' ) ) {
13 + exit;
14 +}
16 15
16 +/**
17 + * Common Settings
18 + */
19 +class WINP_SettingsPage extends WINP_Page {
20 +
17 21 /**
18 - * Common Settings
22 + * @param Wbcr_Factory419_Plugin $plugin
19 23 */
20 - class WINP_SettingsPage extends Wbcr_FactoryPages402_AdminPage {
24 + public function __construct( Wbcr_Factory419_Plugin $plugin ) {
25 + $this->menu_post_type = WINP_SNIPPETS_POST_TYPE;
21 26
22 - /**
23 - * @param Wbcr_Factory401_Plugin $plugin
24 - */
25 - public function __construct(Wbcr_Factory401_Plugin $plugin)
26 - {
27 - $this->menu_post_type = WINP_SNIPPETS_POST_TYPE;
27 + $this->id = "settings";
28 + $this->menu_title = __( 'Settings', 'insert-php' );
28 29
29 - /*if( !current_user_can('administrator') ) {
30 - $this->capabilitiy = "read_wbcr-scrapes";
31 - }*/
30 + parent::__construct( $plugin );
32 31
33 - $this->id = "scrapes_settings";
34 - $this->menu_title = __('Settings', 'insert-php');
32 + $this->plugin = $plugin;
35 33
36 - parent::__construct($plugin);
34 + do_action( 'wbcr/inp/settings/after_construct' );
35 + }
37 36
38 - $this->plugin = $plugin;
39 - }
37 + public function assets( $scripts, $styles ) {
38 + $this->scripts->request( 'jquery' );
40 39
41 - public function assets($scripts, $styles)
42 - {
43 - $this->scripts->request('jquery');
40 + $this->scripts->request( [
41 + 'control.checkbox',
42 + 'control.dropdown'
43 + ], 'bootstrap' );
44 44
45 - $this->scripts->request(array(
46 - 'control.checkbox',
47 - 'control.dropdown'
48 - ), 'bootstrap');
45 + $this->styles->request( [
46 + 'bootstrap.core',
47 + 'bootstrap.form-group',
48 + 'bootstrap.separator',
49 + 'control.dropdown',
50 + 'control.checkbox',
51 + ], 'bootstrap' );
52 + }
49 53
50 - $this->styles->request(array(
51 - 'bootstrap.core',
52 - 'bootstrap.form-group',
53 - 'bootstrap.separator',
54 - 'control.dropdown',
55 - 'control.checkbox',
56 - ), 'bootstrap');
57 - }
54 + /**
55 + * Returns options for the Basic Settings screen.
56 + *
57 + * @since 1.0.0
58 + * @return array
59 + */
60 + public function getOptions() {
58 61
59 - /**
60 - * Returns options for the Basic Settings screen.
61 - *
62 - * @since 1.0.0
63 - * @return array
64 - */
65 - public function getOptions()
66 - {
62 + $options = [];
67 63
68 - $options = array();
64 + $options[] = [
65 + 'type' => 'separator'
66 + ];
69 67
70 - $options[] = array(
71 - 'type' => 'separator'
72 - );
68 + $options[] = [
69 + 'type' => 'checkbox',
70 + 'way' => 'buttons',
71 + 'name' => 'activate_by_default',
72 + 'title' => __( 'Activate by Default', 'insert-php' ),
73 + 'default' => true,
74 + 'hint' => __( 'When creating a new snippet or updating an old one, make the code snippets active by default.', 'insert-php' )
75 + ];
73 76
74 - $options[] = array(
75 - 'type' => 'checkbox',
76 - 'way' => 'buttons',
77 - 'name' => 'activate_by_default',
78 - 'title' => __('Activate by Default', 'insert-php'),
79 - 'default' => true,
80 - 'hint' => __('When creating a new snippet or updating an old one, make the code snippets active by default.', 'insert-php')
81 - );
77 + $options[] = [
78 + 'type' => 'checkbox',
79 + 'way' => 'buttons',
80 + 'name' => 'keep_html_entities',
81 + 'title' => __( 'Keep the HTML entities, don\'t convert to its character', 'insert-php' ),
82 + 'default' => false,
83 + 'hint' => __( 'If you want to use an HTML entity in your code (for example &gt; or &quot;), but the editor keeps on changing them to its equivalent character (> and " for the previous example), then you might want to enable this option.', 'insert-php' )
84 + ];
82 85
83 - $options[] = array(
84 - 'type' => 'html',
85 - 'html' => '<h3 style="margin-left:0px">Code Editor</h3>'
86 - );
86 + $options[] = [
87 + 'type' => 'checkbox',
88 + 'way' => 'buttons',
89 + 'name' => 'complete_uninstall',
90 + 'title' => __( 'Complete Uninstall', 'insert-php' ),
91 + 'default' => false,
92 + 'hint' => __( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings.', 'insert-php' )
93 + ];
87 94
88 - $options[] = array(
89 - 'type' => 'separator'
90 - );
95 + $options[] = [
96 + 'type' => 'checkbox',
97 + 'way' => 'buttons',
98 + 'name' => 'support_old_shortcodes',
99 + 'title' => __( 'Support old shortcodes [insert_php]', 'insert-php' ),
100 + 'default' => false,
101 + 'hint' => __( 'If you used our plugin from version 1.3.0, then you could use the old shortcodes [insert_php][/insert_php]; from version 2.2.0 we disabled this type of shortcodes by default, as their use is not safe. If you still want to execute your php code via [insert_php][/insert_php] shortcodes, you can enable this option.', 'insert-php' )
102 + ];
91 103
92 - $options[] = array(
93 - 'type' => 'dropdown',
94 - 'name' => 'code_editor_theme',
95 - 'title' => __('Code style', 'insert-php'),
96 - 'data' => $this->getAvailableThemes(),
97 - 'default' => 'default',
98 - 'hint' => __('Select theme for the code editor.', 'insert-php')
99 - );
104 + $options[] = [
105 + 'type' => 'html',
106 + 'html' => '<h3 style="margin-left:0">Code Editor</h3>'
107 + ];
100 108
101 - $options[] = array(
102 - 'type' => 'checkbox',
103 - 'way' => 'buttons',
104 - 'name' => 'code_editor_indent_with_tabs',
105 - 'title' => __('Indent With Tabs', 'insert-php'),
106 - 'default' => true,
107 - 'hint' => __('Use hard tabs (not spaces) for indentation.', 'insert-php')
108 - );
109 + $options[] = [
110 + 'type' => 'separator'
111 + ];
109 112
110 - $options[] = array(
111 - 'type' => 'integer',
112 - 'way' => 'buttons',
113 - 'name' => 'code_editor_tab_size',
114 - 'title' => __('Tab Size', 'insert-php'),
115 - 'default' => 4,
116 - 'hint' => __('The width of a tab character.', 'insert-php')
117 - );
113 + $options[] = [
114 + 'type' => 'dropdown',
115 + 'name' => 'code_editor_theme',
116 + 'title' => __( 'Code style', 'insert-php' ),
117 + 'data' => $this->getAvailableThemes(),
118 + 'default' => 'default',
119 + 'hint' => __( 'The optional feature. You can customize the code style in the snippet editor. The "Default" style is applied by default.', 'insert-php' )
120 + ];
118 121
119 - $options[] = array(
120 - 'type' => 'integer',
121 - 'way' => 'buttons',
122 - 'name' => 'code_editor_indent_unit',
123 - 'title' => __('Indent Unit', 'insert-php'),
124 - 'default' => 2,
125 - 'hint' => __('How many spaces a block should be indented.', 'insert-php')
126 - );
122 + $options[] = [
123 + 'type' => 'checkbox',
124 + 'way' => 'buttons',
125 + 'name' => 'code_editor_indent_with_tabs',
126 + 'title' => __( 'Indent With Tabs', 'insert-php' ),
127 + 'default' => false,
128 + 'hint' => __( 'The optional feature. Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs. The default is false.', 'insert-php' )
129 + ];
127 130
128 - $options[] = array(
129 - 'type' => 'checkbox',
130 - 'way' => 'buttons',
131 - 'name' => 'code_editor_wrap_lines',
132 - 'title' => __('Wrap Lines', 'insert-php'),
133 - 'default' => true,
134 - 'hint' => __('Whether the editor should scroll or wrap for long lines.', 'insert-php')
135 - );
131 + $options[] = [
132 + 'type' => 'integer',
133 + 'way' => 'buttons',
134 + 'name' => 'code_editor_tab_size',
135 + 'title' => __( 'Tab Size', 'insert-php' ),
136 + 'default' => 4,
137 + 'hint' => __( 'The optional feature. Pressing Tab in the code editor increases left indent to N spaces. N is a number pre-defined by you.', 'insert-php' )
138 + ];
136 139
137 - $options[] = array(
138 - 'type' => 'checkbox',
139 - 'way' => 'buttons',
140 - 'name' => 'code_editor_line_numbers',
141 - 'title' => __('Line Numbers', 'insert-php'),
142 - 'default' => true,
143 - 'hint' => __('Show line numbers to the left of the editor.', 'insert-php')
144 - );
140 + $options[] = [
141 + 'type' => 'integer',
142 + 'way' => 'buttons',
143 + 'name' => 'code_editor_indent_unit',
144 + 'title' => __( 'Indent Unit', 'insert-php' ),
145 + 'default' => 4,
146 + 'hint' => __( 'The optional feature. The indent for code lines (units). Example: select a snippet, press Tab. The left indent in the selected code increases to N spaces. N is a number pre-defined by you.', 'insert-php' )
147 + ];
145 148
146 - $options[] = array(
147 - 'type' => 'checkbox',
148 - 'way' => 'buttons',
149 - 'name' => 'code_editor_auto_close_brackets',
150 - 'title' => __('Auto Close Brackets', 'insert-php'),
151 - 'default' => true,
152 - 'hint' => __('Auto-close brackets and quotes when typed.', 'insert-php')
153 - );
149 + $options[] = [
150 + 'type' => 'checkbox',
151 + 'way' => 'buttons',
152 + 'name' => 'code_editor_wrap_lines',
153 + 'title' => __( 'Wrap Lines', 'insert-php' ),
154 + 'default' => true,
155 + 'hint' => __( 'The optional feature. If ON, the editor will wrap long lines. Otherwise, it will create a horizontal scroll.', 'insert-php' )
156 + ];
154 157
155 - $options[] = array(
156 - 'type' => 'checkbox',
157 - 'way' => 'buttons',
158 - 'name' => 'code_editor_highlight_selection_matches',
159 - 'title' => __('Highlight Selection Matches', 'insert-php'),
160 - 'default' => true,
161 - 'hint' => __('Highlight all instances of a currently selected word.', 'insert-php')
162 - );
158 + $options[] = [
159 + 'type' => 'checkbox',
160 + 'way' => 'buttons',
161 + 'name' => 'code_editor_line_numbers',
162 + 'title' => __( 'Line Numbers', 'insert-php' ),
163 + 'default' => true,
164 + 'hint' => __( 'The optional feature. If ON, all lines in the editor will be numbered.', 'insert-php' )
165 + ];
163 166
164 - $options[] = array(
165 - 'type' => 'separator'
166 - );
167 + $options[] = [
168 + 'type' => 'checkbox',
169 + 'way' => 'buttons',
170 + 'name' => 'code_editor_auto_close_brackets',
171 + 'title' => __( 'Auto Close Brackets', 'insert-php' ),
172 + 'default' => true,
173 + 'hint' => __( 'The optional feature. If ON, the editor will automatically close opened quotes or brackets. Sometimes, it speeds up coding.', 'insert-php' )
174 + ];
167 175
168 - return $options;
169 - }
176 + $options[] = [
177 + 'type' => 'checkbox',
178 + 'way' => 'buttons',
179 + 'name' => 'code_editor_highlight_selection_matches',
180 + 'title' => __( 'Highlight Selection Matches', 'insert-php' ),
181 + 'default' => false,
182 + 'hint' => __( 'The optional feature. If ON, it searches for matches for the selected variable/function name. Highlight matches with green. Improves readability.', 'insert-php' )
183 + ];
170 184
185 + $options = apply_filters( 'wbcr/inp/settings/form_options', $options );
171 186
172 - public function indexAction()
173 - {
187 + $options[] = [
188 + 'type' => 'separator'
189 + ];
174 190
175 - // creating a form
176 - $form = new Wbcr_FactoryForms402_Form(array(
177 - 'scope' => substr($this->plugin->getPrefix(), 0, -1),
178 - 'name' => 'setting'
179 - ), $this->plugin);
191 + return $options;
192 + }
180 193
181 - $form->setProvider(new Wbcr_FactoryForms402_OptionsValueProvider($this->plugin));
182 194
183 - $form->add($this->getOptions());
195 + public function indexAction() {
184 196
185 - if( isset($_POST[$this->plugin->getPrefix() . 'saved']) ) {
186 - if( !wp_verify_nonce($_POST[$this->plugin->getPrefix() . 'nonce'], $this->plugin->getPrefix() . 'settings_form') ) {
187 - wp_die('Permission error. You can not edit this page.');
188 - }
189 - $form->save();
190 - }
197 + // creating a form
198 + $form = WINP_Helper::get_factory_form( [
199 + 'scope' => substr( $this->plugin->getPrefix(), 0, - 1 ),
200 + 'name' => 'setting'
201 + ], $this->plugin );
191 202
192 - ?>
193 - <div class="wrap ">
194 - <div class="factory-bootstrap-401 factory-fontawesome-000">
195 - <h3><?php _e('Settings', 'insert-php') ?></h3>
203 + $form->setProvider( WINP_Helper::get_options_value_provider( $this->plugin ) );
196 204
197 - <form method="post" class="form-horizontal">
198 - <?php if( isset($_POST[$this->plugin->getPrefix() . 'saved']) ) { ?>
199 - <div id="message" class="alert alert-success">
200 - <p><?php _e('The settings have been updated successfully!', 'insert-php') ?></p>
201 - </div>
202 - <?php } ?>
203 - <div style="padding-top: 10px;">
204 - <?php $form->html(); ?>
205 - </div>
206 - <div class="form-group form-horizontal">
207 - <label class="col-sm-2 control-label"> </label>
205 + $form->add( $this->getOptions() );
208 206
209 - <div class="control-group controls col-sm-10">
210 - <?php wp_nonce_field($this->plugin->getPrefix() . 'settings_form', $this->plugin->getPrefix() . 'nonce'); ?>
211 - <input name="<?= $this->plugin->getPrefix() . 'saved' ?>" class="btn btn-primary" type="submit" value="<?php _e('Save settings', 'insert-php') ?>"/>
212 - </div>
213 - </div>
214 - </form>
215 - </div>
216 - </div>
217 - <?php
218 - }
207 + if ( isset( $_POST['wbcr_inp_setting_form_save'] ) ) {
208 + check_admin_referer( 'wbcr_inp_settings_form', 'wbcr_inp_settings_form_nonce_field' );
219 209
220 - /**
221 - * Retrieve a list of the available CodeMirror themes
222 - * @return array the available themes
223 - */
224 - public function getAvailableThemes()
225 - {
226 - static $themes = null;
227 -
228 - if( !is_null($themes) ) {
229 - return $themes;
210 + if ( ! WINP_Plugin::app()->currentUserCan() ) {
211 + wp_die( __( 'Sorry, you are not allowed to save settings as this user.' ), __( 'You need a higher level of permission.' ), 403 );
230 212 }
231 213
232 - $themes = array();
233 - $themes_dir = WINP_PLUGIN_DIR . '/admin/assets/css/cmthemes/';
234 - $theme_files = glob($themes_dir . '*.css');
214 + $form->save();
235 215
236 - foreach($theme_files as $i => $theme) {
237 - $theme = str_replace($themes_dir, '', $theme);
238 - $theme = str_replace('.css', '', $theme);
239 - $themes[] = array($theme, $theme);
240 - }
216 + do_action( 'wbcr/inp/settings/after_form_save' );
217 + }
218 + ?>
219 + <div class="wrap">
220 + <div class="<?php echo WINP_Helper::get_factory_class(); ?>">
221 + <h3><?php _e( 'Settings', 'insert-php' ) ?></h3>
222 + <div class="row">
223 + <div class="col-md-9">
224 + <form method="post" class="form-horizontal">
225 + <?php if ( isset( $_POST['wbcr_inp_setting_form_save'] ) ) { ?>
226 + <div id="message" class="alert alert-success">
227 + <p><?php _e( 'The settings have been updated successfully!', 'insert-php' ) ?></p>
228 + </div>
229 + <?php } ?>
230 + <div style="padding-top: 10px;">
231 + <?php $form->html(); ?>
232 + </div>
233 + <div class="form-group form-horizontal">
234 + <label class="col-sm-2 control-label"> </label>
235 + <div class="control-group controls col-sm-10">
236 + <?php wp_nonce_field( 'wbcr_inp_settings_form', 'wbcr_inp_settings_form_nonce_field' ); ?>
237 + <input name="wbcr_inp_setting_form_save" class="btn btn-primary" type="submit" value="<?php _e( 'Save settings', 'insert-php' ) ?>"/>
238 + </div>
239 + </div>
240 + </form>
241 + </div>
242 + <div class="col-md-3">
243 + <div id="winp-dashboard-widget" class="winp-right-widget">
244 + <?php
245 + apply_filters( 'wbcr/inp/dashboard/widget/print', '' );
246 + ?>
247 + </div>
248 + </div>
249 + </div>
250 + </div>
251 + </div>
252 + <?php
253 + }
241 254
242 - array_unshift($themes, array('default', 'default'));
255 + /**
256 + * Retrieve a list of the available CodeMirror themes
257 + *
258 + * @return array the available themes
259 + */
260 + public function getAvailableThemes() {
261 + static $themes = null;
243 262
263 + if ( ! is_null( $themes ) ) {
244 264 return $themes;
245 265 }
266 +
267 + $themes = [];
268 + $themes_dir = WINP_PLUGIN_DIR . '/admin/assets/css/cmthemes/';
269 + $theme_files = glob( $themes_dir . '*.css' );
270 +
271 + foreach ( $theme_files as $i => $theme ) {
272 + $theme = str_replace( $themes_dir, '', $theme );
273 + $theme = str_replace( '.css', '', $theme );
274 + $themes[] = [ $theme, $theme ];
275 + }
276 +
277 + array_unshift( $themes, [ 'default', 'default' ] );
278 +
279 + return $themes;
246 280 }
281 +}