PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / php / Settings / Settings_Fields.php

Settings_Fields.php in Code Snippets 4.0.0-beta.2, at php/Settings/Settings_Fields.php

336 lines 11.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets\Settings;
4
5 use function Code_Snippets\code_snippets;
6
7 /**
8 * Plugin settings fields definitions.
9 *
10 * This class defines the settings fields and their default values for the Code Snippets plugin.
11 * It provides methods to retrieve the settings fields and default values.
12 *
13 * @package Code_Snippets\Settings
14 */
15 class Settings_Fields {
16
17 /**
18 * Instance of this class.
19 *
20 * @var Settings_Fields
21 */
22 private static Settings_Fields $instance;
23
24 /**
25 * The settings fields definitions.
26 *
27 * @var array<string, array<string, array>>
28 */
29 private array $fields;
30
31 /**
32 * The default settings values.
33 *
34 * @var array<string, array<string, mixed>>
35 */
36 private array $defaults;
37
38 /**
39 * Constructor.
40 *
41 * Initializes the settings fields and default values.
42 */
43 public function __construct() {
44 $this->init_fields();
45 $this->init_defaults();
46 }
47
48 /**
49 * Retrieve the instance of this class.
50 *
51 * @return Settings_Fields
52 */
53 private static function get_instance(): Settings_Fields {
54 if ( ! isset( self::$instance ) ) {
55 self::$instance = new self();
56 }
57
58 return self::$instance;
59 }
60
61 /**
62 * Retrieve the default setting values
63 *
64 * @return array<string, array<string, mixed>>
65 */
66 public static function get_default_values(): array {
67 return self::get_instance()->defaults;
68 }
69
70 /**
71 * Retrieve the settings fields.
72 *
73 * @return array<string, array<string, array>>
74 */
75 public static function get_field_definitions(): array {
76 return self::get_instance()->fields;
77 }
78
79 /**
80 * Initialize default settings values.
81 *
82 * @return void
83 */
84 private function init_defaults() {
85 $this->defaults = [
86 'general' => [
87 'activate_by_default' => true,
88 'enable_tags' => true,
89 'enable_description' => true,
90 'visual_editor_rows' => 5,
91 'list_order' => 'priority-asc',
92 'disable_prism' => false,
93 'hide_upgrade_menu' => false,
94 'complete_uninstall' => false,
95 'enable_flat_files' => false,
96 'enable_admin_bar' => true,
97 'admin_bar_snippet_limit' => 20,
98 'enable_feedback_reporter' => false,
99 ],
100 'editor' => [
101 'indent_with_tabs' => true,
102 'tab_size' => 4,
103 'indent_unit' => 4,
104 'font_size' => 14,
105 'wrap_lines' => true,
106 'code_folding' => true,
107 'line_numbers' => true,
108 'auto_close_brackets' => true,
109 'highlight_selection_matches' => true,
110 'highlight_active_line' => true,
111 'keymap' => 'default',
112 'theme' => 'default',
113 ],
114 'version-switch' => [
115 'selected_version' => '',
116 ],
117 ];
118
119 $this->defaults = apply_filters( 'code_snippets_settings_defaults', $this->defaults );
120 }
121
122 /**
123 * Initialize the settings fields values.
124 *
125 * @return void
126 */
127 private function init_fields() {
128 $this->fields = [];
129
130 $this->fields['debug'] = [
131 'database_update' => [
132 'name' => __( 'Database Table Upgrade', 'code-snippets' ),
133 'type' => 'action',
134 'label' => __( 'Upgrade Database Table', 'code-snippets' ),
135 'desc' => __( 'Use this button to manually upgrade the Code Snippets database table. This action will only affect the snippets table and should be used only when necessary.', 'code-snippets' ),
136 ],
137 'reset_caches' => [
138 'name' => __( 'Reset Caches', 'code-snippets' ),
139 'type' => 'action',
140 'desc' => __( 'Use this button to manually clear snippets caches. Worth doing before switching to an older version of the plugin, if your site uses a persistent object cache.', 'code-snippets' ),
141 ],
142 ];
143
144 $this->fields['version-switch'] = [
145 'version_switcher' => [
146 'name' => __( 'Switch Version', 'code-snippets' ),
147 'type' => 'callback',
148 'render_callback' => [ '\\Code_Snippets\\Settings\\Version_Switch', 'render_version_switch_field' ],
149 ],
150 'refresh_versions' => [
151 'name' => __( 'Refresh Versions', 'code-snippets' ),
152 'type' => 'callback',
153 'render_callback' => [ '\\Code_Snippets\\Settings\\Version_Switch', 'render_refresh_versions_field' ],
154 ],
155 'version_warning' => [
156 'name' => '',
157 'type' => 'callback',
158 'render_callback' => [ '\\Code_Snippets\\Settings\\Version_Switch', 'render_version_switch_warning' ],
159 ],
160 ];
161
162 $this->fields['general'] = [
163 'activate_by_default' => [
164 'name' => __( 'Activate by Default', 'code-snippets' ),
165 'type' => 'checkbox',
166 'label' => __( "Make the 'Save and Activate' button the default action when saving a snippet.", 'code-snippets' ),
167 ],
168 'enable_tags' => [
169 'name' => __( 'Enable Snippet Tags', 'code-snippets' ),
170 'type' => 'checkbox',
171 'label' => __( 'Show snippet tags on admin pages.', 'code-snippets' ),
172 ],
173 'enable_description' => [
174 'name' => __( 'Enable Snippet Descriptions', 'code-snippets' ),
175 'type' => 'checkbox',
176 'label' => __( 'Show snippet descriptions on admin pages.', 'code-snippets' ),
177 ],
178 'visual_editor_rows' => [
179 'name' => __( 'Description Editor Height', 'code-snippets' ),
180 'type' => 'number',
181 'label' => _x( 'rows', 'unit', 'code-snippets' ),
182 'min' => 0,
183 ],
184 'list_order' => [
185 'name' => __( 'Snippets List Order', 'code-snippets' ),
186 'type' => 'select',
187 'desc' => __( 'Default way to order snippets on the All Snippets admin menu.', 'code-snippets' ),
188 'options' => [
189 'priority-asc' => __( 'Priority', 'code-snippets' ),
190 'name-asc' => __( 'Name (A-Z)', 'code-snippets' ),
191 'name-desc' => __( 'Name (Z-A)', 'code-snippets' ),
192 'modified-desc' => __( 'Modified (latest first)', 'code-snippets' ),
193 'modified-asc' => __( 'Modified (oldest first)', 'code-snippets' ),
194 ],
195 ],
196 'disable_prism' => [
197 'name' => __( 'Disable Syntax Highlighter', 'code-snippets' ),
198 'type' => 'checkbox',
199 'label' => __( 'Disable syntax highlighting when displaying snippet code on the front-end.', 'code-snippets' ),
200 ],
201 ];
202
203 if ( ! code_snippets()->licensing->is_licensed() ) {
204 $this->fields['general']['hide_upgrade_menu'] = [
205 'name' => __( 'Hide Upgrade Notices', 'code-snippets' ),
206 'type' => 'checkbox',
207 'label' => __( 'Hide notices inviting you to upgrade to Code Snippets Pro.', 'code-snippets' ),
208 ];
209 }
210
211 if ( ! is_multisite() || is_main_site() ) {
212 $this->fields['general']['complete_uninstall'] = [
213 'name' => __( 'Complete Uninstall', 'code-snippets' ),
214 'type' => 'checkbox',
215 'label' => __( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings.', 'code-snippets' ),
216 ];
217 }
218
219 $this->fields['general']['enable_admin_bar'] = [
220 'name' => __( 'Enable Admin Bar Menu', 'code-snippets' ),
221 'type' => 'checkbox',
222 'label' => __( 'Show a Snippets menu in the admin bar for quick access to snippets.', 'code-snippets' ),
223 ];
224
225 $this->fields['general']['admin_bar_snippet_limit'] = [
226 'name' => __( 'Admin Bar Snippets Per Page', 'code-snippets' ),
227 'type' => 'number',
228 'desc' => __( 'Number of snippets to show in the admin bar Active/Inactive menus before paginating.', 'code-snippets' ),
229 'label' => __( 'snippets', 'code-snippets' ),
230 'min' => 1,
231 'max' => 100,
232 'show_if' => [
233 'section' => 'general',
234 'field' => 'enable_admin_bar',
235 'value' => true,
236 ],
237 ];
238
239 $this->fields['general']['enable_feedback_reporter'] = [
240 'name' => __( 'Enable Feedback Reporter', 'code-snippets' ),
241 'type' => 'checkbox',
242 'label' => __( 'Show a button on Code Snippets pages for reporting bugs, requesting features and sending feedback.', 'code-snippets' ),
243 'desc' => __( 'Reports include your site address, contact details and a list of active plugins, so that the team can reproduce the problem.', 'code-snippets' ),
244 ];
245
246 $this->fields['editor'] = [
247 'indent_with_tabs' => [
248 'name' => __( 'Indent With Tabs', 'code-snippets' ),
249 'type' => 'checkbox',
250 'label' => __( 'Use hard tabs instead of spaces for indentation.', 'code-snippets' ),
251 'codemirror' => 'indentWithTabs',
252 ],
253 'tab_size' => [
254 'name' => __( 'Tab Size', 'code-snippets' ),
255 'type' => 'number',
256 'desc' => __( 'The width of a tab character.', 'code-snippets' ),
257 'label' => _x( 'spaces', 'unit', 'code-snippets' ),
258 'codemirror' => 'tabSize',
259 'min' => 0,
260 ],
261 'indent_unit' => [
262 'name' => __( 'Indent Unit', 'code-snippets' ),
263 'type' => 'number',
264 'desc' => __( 'The number of spaces to indent a block.', 'code-snippets' ),
265 'label' => _x( 'spaces', 'unit', 'code-snippets' ),
266 'codemirror' => 'indentUnit',
267 'min' => 0,
268 ],
269 'font_size' => [
270 'name' => __( 'Font Size', 'code-snippets' ),
271 'type' => 'number',
272 'label' => _x( 'px', 'unit', 'code-snippets' ),
273 'codemirror' => 'fontSize',
274 'min' => 8,
275 'max' => 28,
276 ],
277 'wrap_lines' => [
278 'name' => __( 'Wrap Lines', 'code-snippets' ),
279 'type' => 'checkbox',
280 'label' => __( 'Soft-wrap long lines of code instead of horizontally scrolling.', 'code-snippets' ),
281 'codemirror' => 'lineWrapping',
282 ],
283 'code_folding' => [
284 'name' => __( 'Code Folding', 'code-snippets' ),
285 'type' => 'checkbox',
286 'label' => __( 'Allow folding functions or other blocks into a single line.', 'code-snippets' ),
287 'codemirror' => 'foldGutter',
288 ],
289 'line_numbers' => [
290 'name' => __( 'Line Numbers', 'code-snippets' ),
291 'type' => 'checkbox',
292 'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ),
293 'codemirror' => 'lineNumbers',
294 ],
295 'auto_close_brackets' => [
296 'name' => __( 'Auto Close Brackets', 'code-snippets' ),
297 'type' => 'checkbox',
298 'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ),
299 'codemirror' => 'autoCloseBrackets',
300 ],
301 'highlight_selection_matches' => [
302 'name' => __( 'Highlight Selection Matches', 'code-snippets' ),
303 'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ),
304 'type' => 'checkbox',
305 'codemirror' => 'highlightSelectionMatches',
306 ],
307 'highlight_active_line' => [
308 'name' => __( 'Highlight Active Line', 'code-snippets' ),
309 'label' => __( 'Highlight the line that is currently being edited.', 'code-snippets' ),
310 'type' => 'checkbox',
311 'codemirror' => 'styleActiveLine',
312 ],
313 'keymap' => [
314 'name' => __( 'Keymap', 'code-snippets' ),
315 'type' => 'select',
316 'desc' => __( 'The set of keyboard shortcuts to use in the code editor.', 'code-snippets' ),
317 'options' => [
318 'default' => __( 'Default', 'code-snippets' ),
319 'vim' => __( 'Vim', 'code-snippets' ),
320 'emacs' => __( 'Emacs', 'code-snippets' ),
321 'sublime' => __( 'Sublime Text', 'code-snippets' ),
322 ],
323 'codemirror' => 'keyMap',
324 ],
325 'theme' => [
326 'name' => __( 'Theme', 'code-snippets' ),
327 'type' => 'select',
328 'options' => Editor_Preview::get_editor_theme_list(),
329 'codemirror' => 'theme',
330 ],
331 ];
332
333 $this->fields = apply_filters( 'code_snippets_settings_fields', $this->fields );
334 }
335 }
336