PluginProbe
Code Snippets / 3.9.6
Code Snippets v3.9.6
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 3.9.6, at php/settings/settings-fields.php

264 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Manages the settings field definitions.
4 *
5 * @package Code_Snippets
6 * @subpackage Settings
7 */
8
9 namespace Code_Snippets\Settings;
10
11 use function Code_Snippets\code_snippets;
12
13 /**
14 * Retrieve the default setting values
15 *
16 * @return array<string, array<string, mixed>>
17 */
18 function get_default_settings(): array {
19 static $defaults;
20
21 if ( isset( $defaults ) ) {
22 return $defaults;
23 }
24
25 $defaults = [
26 'general' => [
27 'activate_by_default' => true,
28 'enable_tags' => true,
29 'enable_description' => true,
30 'visual_editor_rows' => 5,
31 'list_order' => 'priority-asc',
32 'disable_prism' => false,
33 'hide_upgrade_menu' => false,
34 'complete_uninstall' => false,
35 'enable_flat_files' => false,
36 ],
37 'editor' => [
38 'indent_with_tabs' => true,
39 'tab_size' => 4,
40 'indent_unit' => 4,
41 'font_size' => 14,
42 'wrap_lines' => true,
43 'code_folding' => true,
44 'line_numbers' => true,
45 'auto_close_brackets' => true,
46 'highlight_selection_matches' => true,
47 'highlight_active_line' => true,
48 'keymap' => 'default',
49 'theme' => 'default',
50 ],
51 'version-switch' => [
52 'selected_version' => '',
53 ],
54 'debug' => [
55 'enable_version_change' => false,
56 ],
57 ];
58
59 $defaults = apply_filters( 'code_snippets_settings_defaults', $defaults );
60
61 return $defaults;
62 }
63
64 /**
65 * Retrieve the settings fields
66 *
67 * @return array<string, array<string, array>>
68 */
69 function get_settings_fields(): array {
70 static $fields;
71
72 if ( isset( $fields ) ) {
73 return $fields;
74 }
75
76 $fields = [];
77
78 $fields['debug'] = [
79 'database_update' => [
80 'name' => __( 'Database Table Upgrade', 'code-snippets' ),
81 'type' => 'action',
82 'label' => __( 'Upgrade Database Table', 'code-snippets' ),
83 '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' ),
84 ],
85 'reset_caches' => [
86 'name' => __( 'Reset Caches', 'code-snippets' ),
87 'type' => 'action',
88 'desc' => __( 'Use this button to manually clear snippets caches.', 'code-snippets' ),
89 ],
90 'enable_version_change' => [
91 'name' => __( 'Version Change', 'code-snippets' ),
92 'type' => 'checkbox',
93 'label' => __( 'Enable the ability to switch or rollback versions of the Code Snippets core plugin.', 'code-snippets' ),
94 ],
95 ];
96
97 $fields['version-switch'] = [
98 'version_switcher' => [
99 'name' => __( 'Switch Version', 'code-snippets' ),
100 'type' => 'callback',
101 'render_callback' => [ '\\Code_Snippets\\Settings\\Version_Switch', 'render_version_switch_field' ],
102 ],
103 'refresh_versions' => [
104 'name' => __( 'Refresh Versions', 'code-snippets' ),
105 'type' => 'callback',
106 'render_callback' => [ '\\Code_Snippets\\Settings\\Version_Switch', 'render_refresh_versions_field' ],
107 ],
108 'version_warning' => [
109 'name' => '',
110 'type' => 'callback',
111 'render_callback' => [ '\\Code_Snippets\\Settings\\Version_Switch', 'render_version_switch_warning' ],
112 ],
113 ];
114
115 $fields['general'] = [
116 'activate_by_default' => [
117 'name' => __( 'Activate by Default', 'code-snippets' ),
118 'type' => 'checkbox',
119 'label' => __( "Make the 'Save and Activate' button the default action when saving a snippet.", 'code-snippets' ),
120 ],
121 'enable_tags' => [
122 'name' => __( 'Enable Snippet Tags', 'code-snippets' ),
123 'type' => 'checkbox',
124 'label' => __( 'Show snippet tags on admin pages.', 'code-snippets' ),
125 ],
126 'enable_description' => [
127 'name' => __( 'Enable Snippet Descriptions', 'code-snippets' ),
128 'type' => 'checkbox',
129 'label' => __( 'Show snippet descriptions on admin pages.', 'code-snippets' ),
130 ],
131 'visual_editor_rows' => [
132 'name' => __( 'Description Editor Height', 'code-snippets' ),
133 'type' => 'number',
134 'label' => _x( 'rows', 'unit', 'code-snippets' ),
135 'min' => 0,
136 ],
137 'list_order' => [
138 'name' => __( 'Snippets List Order', 'code-snippets' ),
139 'type' => 'select',
140 'desc' => __( 'Default way to order snippets on the All Snippets admin menu.', 'code-snippets' ),
141 'options' => [
142 'priority-asc' => __( 'Priority', 'code-snippets' ),
143 'name-asc' => __( 'Name (A-Z)', 'code-snippets' ),
144 'name-desc' => __( 'Name (Z-A)', 'code-snippets' ),
145 'modified-desc' => __( 'Modified (latest first)', 'code-snippets' ),
146 'modified-asc' => __( 'Modified (oldest first)', 'code-snippets' ),
147 ],
148 ],
149 'disable_prism' => [
150 'name' => __( 'Disable Syntax Highlighter', 'code-snippets' ),
151 'type' => 'checkbox',
152 'label' => __( 'Disable syntax highlighting when displaying snippet code on the front-end.', 'code-snippets' ),
153 ],
154 ];
155
156 if ( ! code_snippets()->licensing->is_licensed() ) {
157 $fields['general']['hide_upgrade_menu'] = [
158 'name' => __( 'Hide Upgrade Notices', 'code-snippets' ),
159 'type' => 'checkbox',
160 'label' => __( 'Hide notices inviting you to upgrade to Code Snippets Pro.', 'code-snippets' ),
161 ];
162 }
163
164 if ( ! is_multisite() || is_main_site() ) {
165 $fields['general']['complete_uninstall'] = [
166 'name' => __( 'Complete Uninstall', 'code-snippets' ),
167 'type' => 'checkbox',
168 'label' => __( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings.', 'code-snippets' ),
169 ];
170 }
171
172 $fields['editor'] = [
173 'indent_with_tabs' => [
174 'name' => __( 'Indent With Tabs', 'code-snippets' ),
175 'type' => 'checkbox',
176 'label' => __( 'Use hard tabs instead of spaces for indentation.', 'code-snippets' ),
177 'codemirror' => 'indentWithTabs',
178 ],
179 'tab_size' => [
180 'name' => __( 'Tab Size', 'code-snippets' ),
181 'type' => 'number',
182 'desc' => __( 'The width of a tab character.', 'code-snippets' ),
183 'label' => _x( 'spaces', 'unit', 'code-snippets' ),
184 'codemirror' => 'tabSize',
185 'min' => 0,
186 ],
187 'indent_unit' => [
188 'name' => __( 'Indent Unit', 'code-snippets' ),
189 'type' => 'number',
190 'desc' => __( 'The number of spaces to indent a block.', 'code-snippets' ),
191 'label' => _x( 'spaces', 'unit', 'code-snippets' ),
192 'codemirror' => 'indentUnit',
193 'min' => 0,
194 ],
195 'font_size' => [
196 'name' => __( 'Font Size', 'code-snippets' ),
197 'type' => 'number',
198 'label' => _x( 'px', 'unit', 'code-snippets' ),
199 'codemirror' => 'fontSize',
200 'min' => 8,
201 'max' => 28,
202 ],
203 'wrap_lines' => [
204 'name' => __( 'Wrap Lines', 'code-snippets' ),
205 'type' => 'checkbox',
206 'label' => __( 'Soft-wrap long lines of code instead of horizontally scrolling.', 'code-snippets' ),
207 'codemirror' => 'lineWrapping',
208 ],
209
210 'code_folding' => [
211 'name' => __( 'Code Folding', 'code-snippets' ),
212 'type' => 'checkbox',
213 'label' => __( 'Allow folding functions or other blocks into a single line.', 'code-snippets' ),
214 'codemirror' => 'foldGutter',
215 ],
216 'line_numbers' => [
217 'name' => __( 'Line Numbers', 'code-snippets' ),
218 'type' => 'checkbox',
219 'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ),
220 'codemirror' => 'lineNumbers',
221 ],
222 'auto_close_brackets' => [
223 'name' => __( 'Auto Close Brackets', 'code-snippets' ),
224 'type' => 'checkbox',
225 'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ),
226 'codemirror' => 'autoCloseBrackets',
227 ],
228 'highlight_selection_matches' => [
229 'name' => __( 'Highlight Selection Matches', 'code-snippets' ),
230 'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ),
231 'type' => 'checkbox',
232 'codemirror' => 'highlightSelectionMatches',
233 ],
234 'highlight_active_line' => [
235 'name' => __( 'Highlight Active Line', 'code-snippets' ),
236 'label' => __( 'Highlight the line that is currently being edited.', 'code-snippets' ),
237 'type' => 'checkbox',
238 'codemirror' => 'styleActiveLine',
239 ],
240 'keymap' => [
241 'name' => __( 'Keymap', 'code-snippets' ),
242 'type' => 'select',
243 'desc' => __( 'The set of keyboard shortcuts to use in the code editor.', 'code-snippets' ),
244 'options' => [
245 'default' => __( 'Default', 'code-snippets' ),
246 'vim' => __( 'Vim', 'code-snippets' ),
247 'emacs' => __( 'Emacs', 'code-snippets' ),
248 'sublime' => __( 'Sublime Text', 'code-snippets' ),
249 ],
250 'codemirror' => 'keyMap',
251 ],
252 'theme' => [
253 'name' => __( 'Theme', 'code-snippets' ),
254 'type' => 'select',
255 'options' => get_editor_theme_list(),
256 'codemirror' => 'theme',
257 ],
258 ];
259
260 $fields = apply_filters( 'code_snippets_settings_fields', $fields );
261
262 return $fields;
263 }
264