8
8
9
9
namespace Code_Snippets \Settings ;
10
10
11
+ use function Code_Snippets \code_snippets ;
12
+
11
13
/**
12
14
* Retrieve the default setting values
13
15
*
@@ -20,17 +22,33 @@ function get_default_settings(): array {
20
22
return $ defaults ;
21
23
}
22
24
23
- $ defaults = array ();
24
-
25
- foreach ( get_settings_fields () as $ section_id => $ fields ) {
26
- $ defaults [ $ section_id ] = array ();
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
+ ],
36
+ 'editor ' => [
37
+ 'indent_with_tabs ' => true ,
38
+ 'tab_size ' => 4 ,
39
+ 'indent_unit ' => 4 ,
40
+ 'wrap_lines ' => true ,
41
+ 'code_folding ' => true ,
42
+ 'line_numbers ' => true ,
43
+ 'auto_close_brackets ' => true ,
44
+ 'highlight_selection_matches ' => true ,
45
+ 'highlight_active_line ' => true ,
46
+ 'keymap ' => 'default ' ,
47
+ 'theme ' => 'default ' ,
48
+ ],
49
+ ];
27
50
28
- foreach ( $ fields as $ field_id => $ field_atts ) {
29
- if ( isset ( $ field_atts ['default ' ] ) ) {
30
- $ defaults [ $ section_id ][ $ field_id ] = $ field_atts ['default ' ];
31
- }
32
- }
33
- }
51
+ $ defaults = apply_filters ( 'code_snippets_settings_defaults ' , $ defaults );
34
52
35
53
return $ defaults ;
36
54
}
@@ -65,35 +83,27 @@ function get_settings_fields(): array {
65
83
66
84
$ fields ['general ' ] = [
67
85
'activate_by_default ' => [
68
- 'name ' => __ ( 'Activate by Default ' , 'code-snippets ' ),
69
- 'type ' => 'checkbox ' ,
70
- 'label ' => __ ( "Make the 'Save and Activate' button the default action when saving a snippet. " , 'code-snippets ' ),
71
- 'default ' => true ,
72
- ],
73
-
74
- 'enable_tags ' => [
75
- 'name ' => __ ( 'Enable Snippet Tags ' , 'code-snippets ' ),
76
- 'type ' => 'checkbox ' ,
77
- 'label ' => __ ( 'Show snippet tags on admin pages. ' , 'code-snippets ' ),
78
- 'default ' => true ,
79
- ],
80
-
81
- 'enable_description ' => [
82
- 'name ' => __ ( 'Enable Snippet Descriptions ' , 'code-snippets ' ),
83
- 'type ' => 'checkbox ' ,
84
- 'label ' => __ ( 'Show snippet descriptions on admin pages. ' , 'code-snippets ' ),
85
- 'default ' => true ,
86
- ],
87
-
88
- 'visual_editor_rows ' => [
89
- 'name ' => __ ( 'Description Editor Height ' , 'code-snippets ' ),
90
- 'type ' => 'number ' ,
91
- 'label ' => _x ( 'rows ' , 'unit ' , 'code-snippets ' ),
92
- 'default ' => 5 ,
93
- 'min ' => 0 ,
94
- ],
95
-
96
- 'list_order ' => [
86
+ 'name ' => __ ( 'Activate by Default ' , 'code-snippets ' ),
87
+ 'type ' => 'checkbox ' ,
88
+ 'label ' => __ ( "Make the 'Save and Activate' button the default action when saving a snippet. " , 'code-snippets ' ),
89
+ ],
90
+ 'enable_tags ' => [
91
+ 'name ' => __ ( 'Enable Snippet Tags ' , 'code-snippets ' ),
92
+ 'type ' => 'checkbox ' ,
93
+ 'label ' => __ ( 'Show snippet tags on admin pages. ' , 'code-snippets ' ),
94
+ ],
95
+ 'enable_description ' => [
96
+ 'name ' => __ ( 'Enable Snippet Descriptions ' , 'code-snippets ' ),
97
+ 'type ' => 'checkbox ' ,
98
+ 'label ' => __ ( 'Show snippet descriptions on admin pages. ' , 'code-snippets ' ),
99
+ ],
100
+ 'visual_editor_rows ' => [
101
+ 'name ' => __ ( 'Description Editor Height ' , 'code-snippets ' ),
102
+ 'type ' => 'number ' ,
103
+ 'label ' => _x ( 'rows ' , 'unit ' , 'code-snippets ' ),
104
+ 'min ' => 0 ,
105
+ ],
106
+ 'list_order ' => [
97
107
'name ' => __ ( 'Snippets List Order ' , 'code-snippets ' ),
98
108
'type ' => 'select ' ,
99
109
'desc ' => __ ( 'Default way to order snippets on the All Snippets admin menu. ' , 'code-snippets ' ),
@@ -104,117 +114,93 @@ function get_settings_fields(): array {
104
114
'modified-desc ' => __ ( 'Modified (latest first) ' , 'code-snippets ' ),
105
115
'modified-asc ' => __ ( 'Modified (oldest first) ' , 'code-snippets ' ),
106
116
],
107
- 'default ' => 'priority-asc ' ,
108
- ],
109
-
110
- 'disable_prism ' => [
111
- 'name ' => __ ( 'Disable Syntax Highlighter ' , 'code-snippets ' ),
112
- 'type ' => 'checkbox ' ,
113
- 'label ' => __ ( 'Disable syntax highlighting when displaying snippet code on the front-end. ' , 'code-snippets ' ),
114
- 'default ' => false ,
115
117
],
116
-
117
- 'hide_upgrade_menu ' => [
118
- 'name ' => __ ( 'Hide Upgrade Menu ' , 'code-snippets ' ),
119
- 'type ' => 'checkbox ' ,
120
- 'label ' => __ ( 'Hide the Upgrade button from the admin menu. ' , 'code-snippets ' ),
121
- 'default ' => false ,
118
+ 'disable_prism ' => [
119
+ 'name ' => __ ( 'Disable Syntax Highlighter ' , 'code-snippets ' ),
120
+ 'type ' => 'checkbox ' ,
121
+ 'label ' => __ ( 'Disable syntax highlighting when displaying snippet code on the front-end. ' , 'code-snippets ' ),
122
122
],
123
123
];
124
124
125
+ if ( ! code_snippets ()->licensing ->is_licensed () ) {
126
+ $ fields ['general ' ]['hide_upgrade_menu ' ] = [
127
+ 'name ' => __ ( 'Hide Upgrade Menu ' , 'code-snippets ' ),
128
+ 'type ' => 'checkbox ' ,
129
+ 'label ' => __ ( 'Hide the Upgrade button from the admin menu. ' , 'code-snippets ' ),
130
+ ];
131
+ }
132
+
125
133
if ( ! is_multisite () || is_main_site () ) {
126
134
$ fields ['general ' ]['complete_uninstall ' ] = [
127
- 'name ' => __ ( 'Complete Uninstall ' , 'code-snippets ' ),
128
- 'type ' => 'checkbox ' ,
129
- 'label ' => __ ( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings. ' , 'code-snippets ' ),
130
- 'default ' => false ,
135
+ 'name ' => __ ( 'Complete Uninstall ' , 'code-snippets ' ),
136
+ 'type ' => 'checkbox ' ,
137
+ 'label ' => __ ( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings. ' , 'code-snippets ' ),
131
138
];
132
139
}
133
140
134
- // Code Editor settings section.
135
-
136
141
$ fields ['editor ' ] = [
137
- 'indent_with_tabs ' => [
142
+ 'indent_with_tabs ' => [
138
143
'name ' => __ ( 'Indent With Tabs ' , 'code-snippets ' ),
139
144
'type ' => 'checkbox ' ,
140
145
'label ' => __ ( 'Use hard tabs instead of spaces for indentation. ' , 'code-snippets ' ),
141
- 'default ' => true ,
142
146
'codemirror ' => 'indentWithTabs ' ,
143
147
],
144
-
145
- 'tab_size ' => [
148
+ 'tab_size ' => [
146
149
'name ' => __ ( 'Tab Size ' , 'code-snippets ' ),
147
150
'type ' => 'number ' ,
148
151
'desc ' => __ ( 'The width of a tab character. ' , 'code-snippets ' ),
149
- 'default ' => 4 ,
150
152
'label ' => _x ( 'spaces ' , 'unit ' , 'code-snippets ' ),
151
153
'codemirror ' => 'tabSize ' ,
152
154
'min ' => 0 ,
153
155
],
154
-
155
- 'indent_unit ' => [
156
+ 'indent_unit ' => [
156
157
'name ' => __ ( 'Indent Unit ' , 'code-snippets ' ),
157
158
'type ' => 'number ' ,
158
159
'desc ' => __ ( 'The number of spaces to indent a block. ' , 'code-snippets ' ),
159
- 'default ' => 4 ,
160
160
'label ' => _x ( 'spaces ' , 'unit ' , 'code-snippets ' ),
161
161
'codemirror ' => 'indentUnit ' ,
162
162
'min ' => 0 ,
163
163
],
164
-
165
- 'wrap_lines ' => [
164
+ 'wrap_lines ' => [
166
165
'name ' => __ ( 'Wrap Lines ' , 'code-snippets ' ),
167
166
'type ' => 'checkbox ' ,
168
167
'label ' => __ ( 'Soft-wrap long lines of code instead of horizontally scrolling. ' , 'code-snippets ' ),
169
- 'default ' => true ,
170
168
'codemirror ' => 'lineWrapping ' ,
171
169
],
172
-
173
- 'code_folding ' => [
170
+ 'code_folding ' => [
174
171
'name ' => __ ( 'Code Folding ' , 'code-snippets ' ),
175
172
'type ' => 'checkbox ' ,
176
173
'label ' => __ ( 'Allow folding functions or other blocks into a single line. ' , 'code-snippets ' ),
177
- 'default ' => true ,
178
174
'codemirror ' => 'foldGutter ' ,
179
175
],
180
-
181
- 'line_numbers ' => [
176
+ 'line_numbers ' => [
182
177
'name ' => __ ( 'Line Numbers ' , 'code-snippets ' ),
183
178
'type ' => 'checkbox ' ,
184
179
'label ' => __ ( 'Show line numbers to the left of the editor. ' , 'code-snippets ' ),
185
- 'default ' => true ,
186
180
'codemirror ' => 'lineNumbers ' ,
187
181
],
188
-
189
- 'auto_close_brackets ' => [
182
+ 'auto_close_brackets ' => [
190
183
'name ' => __ ( 'Auto Close Brackets ' , 'code-snippets ' ),
191
184
'type ' => 'checkbox ' ,
192
185
'label ' => __ ( 'Auto-close brackets and quotes when typed. ' , 'code-snippets ' ),
193
- 'default ' => true ,
194
186
'codemirror ' => 'autoCloseBrackets ' ,
195
187
],
196
-
197
188
'highlight_selection_matches ' => [
198
189
'name ' => __ ( 'Highlight Selection Matches ' , 'code-snippets ' ),
199
190
'label ' => __ ( 'Highlight all instances of a currently selected word. ' , 'code-snippets ' ),
200
191
'type ' => 'checkbox ' ,
201
- 'default ' => true ,
202
192
'codemirror ' => 'highlightSelectionMatches ' ,
203
193
],
204
-
205
- 'highlight_active_line ' => [
194
+ 'highlight_active_line ' => [
206
195
'name ' => __ ( 'Highlight Active Line ' , 'code-snippets ' ),
207
196
'label ' => __ ( 'Highlight the line that is currently being edited. ' , 'code-snippets ' ),
208
197
'type ' => 'checkbox ' ,
209
- 'default ' => true ,
210
198
'codemirror ' => 'styleActiveLine ' ,
211
199
],
212
-
213
- 'keymap ' => [
200
+ 'keymap ' => [
214
201
'name ' => __ ( 'Keymap ' , 'code-snippets ' ),
215
202
'type ' => 'select ' ,
216
203
'desc ' => __ ( 'The set of keyboard shortcuts to use in the code editor. ' , 'code-snippets ' ),
217
- 'default ' => 'default ' ,
218
204
'options ' => [
219
205
'default ' => __ ( 'Default ' , 'code-snippets ' ),
220
206
'vim ' => __ ( 'Vim ' , 'code-snippets ' ),
@@ -223,11 +209,9 @@ function get_settings_fields(): array {
223
209
],
224
210
'codemirror ' => 'keyMap ' ,
225
211
],
226
-
227
- 'theme ' => [
212
+ 'theme ' => [
228
213
'name ' => __ ( 'Theme ' , 'code-snippets ' ),
229
214
'type ' => 'select ' ,
230
- 'default ' => 'default ' ,
231
215
'options ' => get_editor_theme_list (),
232
216
'codemirror ' => 'theme ' ,
233
217
],
0 commit comments