PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.4.10
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.4.10
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 2.7.1 All 27 releases
insert-php / admin / pages / settings.php

settings.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.4.10, at admin/pages/settings.php

291 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
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 */
10
11 // Exit if accessed directly
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Common Settings
18 */
19 class WINP_SettingsPage extends WINP_Page {
20
21 /**
22 * @param Wbcr_Factory466_Plugin $plugin
23 */
24 public function __construct( Wbcr_Factory466_Plugin $plugin ) {
25 $this->menu_post_type = WINP_SNIPPETS_POST_TYPE;
26
27 $this->id = "settings";
28 $this->menu_title = __( 'Settings', 'insert-php' );
29
30 parent::__construct( $plugin );
31
32 $this->plugin = $plugin;
33
34 do_action( 'wbcr/inp/settings/after_construct' );
35 }
36
37 public function assets( $scripts, $styles ) {
38 $this->scripts->request( 'jquery' );
39
40 $this->scripts->request( [
41 'control.checkbox',
42 'control.dropdown'
43 ], 'bootstrap' );
44
45 $this->styles->request( [
46 'bootstrap.core',
47 'bootstrap.form-group',
48 'bootstrap.separator',
49 'control.dropdown',
50 'control.checkbox',
51 ], 'bootstrap' );
52 }
53
54 /**
55 * Returns options for the Basic Settings screen.
56 *
57 * @since 1.0.0
58 * @return array
59 */
60 public function getOptions() {
61
62 $options = [];
63
64 $options[] = [
65 'type' => 'separator'
66 ];
67
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 ];
76
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 ];
85
86 $options[] = [
87 'type' => 'checkbox',
88 'way' => 'buttons',
89 'name' => 'execute_shortcode',
90 'title' => __( 'Execute shortcodes in snippets', 'insert-php' ),
91 'default' => false,
92 'hint' => __( 'Execute shortcodes in the snippet code before executing the snippet.', 'insert-php' )
93 ];
94
95 $options[] = [
96 'type' => 'checkbox',
97 'way' => 'buttons',
98 'name' => 'complete_uninstall',
99 'title' => __( 'Complete Uninstall', 'insert-php' ),
100 'default' => false,
101 'hint' => __( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings.', 'insert-php' )
102 ];
103
104 $options[] = [
105 'type' => 'checkbox',
106 'way' => 'buttons',
107 'name' => 'support_old_shortcodes',
108 'title' => __( 'Support old shortcodes [insert_php]', 'insert-php' ),
109 'default' => false,
110 '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' )
111 ];
112
113 $options[] = [
114 'type' => 'html',
115 'html' => '<h3 style="margin-left:0">Code Editor</h3>'
116 ];
117
118 $options[] = [
119 'type' => 'separator'
120 ];
121
122 $options[] = [
123 'type' => 'dropdown',
124 'name' => 'code_editor_theme',
125 'title' => __( 'Code style', 'insert-php' ),
126 'data' => $this->getAvailableThemes(),
127 'default' => 'default',
128 'hint' => __( 'The optional feature. You can customize the code style in the snippet editor. The "Default" style is applied by default.', 'insert-php' )
129 ];
130
131 $options[] = [
132 'type' => 'checkbox',
133 'way' => 'buttons',
134 'name' => 'code_editor_indent_with_tabs',
135 'title' => __( 'Indent With Tabs', 'insert-php' ),
136 'default' => false,
137 'hint' => __( 'The optional feature. Whether, when indenting, the first N*tabSize spaces should be replaced by N tabs. The default is false.', 'insert-php' )
138 ];
139
140 $options[] = [
141 'type' => 'integer',
142 'way' => 'buttons',
143 'name' => 'code_editor_tab_size',
144 'title' => __( 'Tab Size', 'insert-php' ),
145 'default' => 4,
146 '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' )
147 ];
148
149 $options[] = [
150 'type' => 'integer',
151 'way' => 'buttons',
152 'name' => 'code_editor_indent_unit',
153 'title' => __( 'Indent Unit', 'insert-php' ),
154 'default' => 4,
155 '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' )
156 ];
157
158 $options[] = [
159 'type' => 'checkbox',
160 'way' => 'buttons',
161 'name' => 'code_editor_wrap_lines',
162 'title' => __( 'Wrap Lines', 'insert-php' ),
163 'default' => true,
164 'hint' => __( 'The optional feature. If ON, the editor will wrap long lines. Otherwise, it will create a horizontal scroll.', 'insert-php' )
165 ];
166
167 $options[] = [
168 'type' => 'checkbox',
169 'way' => 'buttons',
170 'name' => 'code_editor_line_numbers',
171 'title' => __( 'Line Numbers', 'insert-php' ),
172 'default' => true,
173 'hint' => __( 'The optional feature. If ON, all lines in the editor will be numbered.', 'insert-php' )
174 ];
175
176 $options[] = [
177 'type' => 'checkbox',
178 'way' => 'buttons',
179 'name' => 'code_editor_auto_close_brackets',
180 'title' => __( 'Auto Close Brackets', 'insert-php' ),
181 'default' => true,
182 'hint' => __( 'The optional feature. If ON, the editor will automatically close opened quotes or brackets. Sometimes, it speeds up coding.', 'insert-php' )
183 ];
184
185 $options[] = [
186 'type' => 'checkbox',
187 'way' => 'buttons',
188 'name' => 'code_editor_highlight_selection_matches',
189 'title' => __( 'Highlight Selection Matches', 'insert-php' ),
190 'default' => false,
191 'hint' => __( 'The optional feature. If ON, it searches for matches for the selected variable/function name. Highlight matches with green. Improves readability.', 'insert-php' )
192 ];
193
194 $options = apply_filters( 'wbcr/inp/settings/form_options', $options );
195
196 $options[] = [
197 'type' => 'separator'
198 ];
199
200 return $options;
201 }
202
203
204 public function indexAction() {
205
206 // creating a form
207 $form = WINP_Helper::get_factory_form( [
208 'scope' => substr( $this->plugin->getPrefix(), 0, - 1 ),
209 'name' => 'setting'
210 ], $this->plugin );
211
212 $form->setProvider( WINP_Helper::get_options_value_provider( $this->plugin ) );
213
214 $form->add( $this->getOptions() );
215
216 if ( isset( $_POST['wbcr_inp_setting_form_save'] ) ) {
217 check_admin_referer( 'wbcr_inp_settings_form', 'wbcr_inp_settings_form_nonce_field' );
218
219 if ( ! WINP_Plugin::app()->currentUserCan() ) {
220 wp_die( __( 'Sorry, you are not allowed to save settings as this user.' ), __( 'You need a higher level of permission.' ), 403 );
221 }
222
223 $form->save();
224
225 do_action( 'wbcr/inp/settings/after_form_save' );
226 }
227 ?>
228 <div class="wrap">
229 <div class="<?php echo WINP_Helper::get_factory_class(); ?>">
230 <h3><?php _e( 'Settings', 'insert-php' ) ?></h3>
231 <div class="row">
232 <div class="col-md-9">
233 <form method="post" class="form-horizontal">
234 <?php if ( isset( $_POST['wbcr_inp_setting_form_save'] ) ) { ?>
235 <div id="message" class="alert alert-success">
236 <p><?php _e( 'The settings have been updated successfully!', 'insert-php' ) ?></p>
237 </div>
238 <?php } ?>
239 <div style="padding-top: 10px;">
240 <?php $form->html(); ?>
241 </div>
242 <div class="form-group form-horizontal">
243 <label class="col-sm-2 control-label"> </label>
244 <div class="control-group controls col-sm-10">
245 <?php wp_nonce_field( 'wbcr_inp_settings_form', 'wbcr_inp_settings_form_nonce_field' ); ?>
246 <input name="wbcr_inp_setting_form_save" class="btn btn-primary" type="submit" value="<?php _e( 'Save settings', 'insert-php' ) ?>"/>
247 </div>
248 </div>
249 </form>
250 </div>
251 <div class="col-md-3">
252 <div id="winp-dashboard-widget" class="winp-right-widget">
253 <?php
254 apply_filters( 'wbcr/inp/dashboard/widget/print', '' );
255 ?>
256 </div>
257 </div>
258 </div>
259 </div>
260 </div>
261 <?php
262 }
263
264 /**
265 * Retrieve a list of the available CodeMirror themes
266 *
267 * @return array the available themes
268 */
269 public function getAvailableThemes() {
270 static $themes = null;
271
272 if ( ! is_null( $themes ) ) {
273 return $themes;
274 }
275
276 $themes = [];
277 $themes_dir = WINP_PLUGIN_DIR . '/admin/assets/css/cmthemes/';
278 $theme_files = glob( $themes_dir . '*.css' );
279
280 foreach ( $theme_files as $i => $theme ) {
281 $theme = str_replace( $themes_dir, '', $theme );
282 $theme = str_replace( '.css', '', $theme );
283 $themes[] = [ $theme, $theme ];
284 }
285
286 array_unshift( $themes, [ 'default', 'default' ] );
287
288 return $themes;
289 }
290 }
291