Skip to content

Commit 7b4f731

Browse files
committed
Build list of setting defaults without calling translation functions early.
1 parent a123b52 commit 7b4f731

File tree

1 file changed

+74
-90
lines changed

1 file changed

+74
-90
lines changed

src/php/settings/settings-fields.php

Lines changed: 74 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Code_Snippets\Settings;
1010

11+
use function Code_Snippets\code_snippets;
12+
1113
/**
1214
* Retrieve the default setting values
1315
*
@@ -20,17 +22,33 @@ function get_default_settings(): array {
2022
return $defaults;
2123
}
2224

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+
];
2750

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 );
3452

3553
return $defaults;
3654
}
@@ -65,35 +83,27 @@ function get_settings_fields(): array {
6583

6684
$fields['general'] = [
6785
'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' => [
97107
'name' => __( 'Snippets List Order', 'code-snippets' ),
98108
'type' => 'select',
99109
'desc' => __( 'Default way to order snippets on the All Snippets admin menu.', 'code-snippets' ),
@@ -104,117 +114,93 @@ function get_settings_fields(): array {
104114
'modified-desc' => __( 'Modified (latest first)', 'code-snippets' ),
105115
'modified-asc' => __( 'Modified (oldest first)', 'code-snippets' ),
106116
],
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,
115117
],
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' ),
122122
],
123123
];
124124

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+
125133
if ( ! is_multisite() || is_main_site() ) {
126134
$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' ),
131138
];
132139
}
133140

134-
// Code Editor settings section.
135-
136141
$fields['editor'] = [
137-
'indent_with_tabs' => [
142+
'indent_with_tabs' => [
138143
'name' => __( 'Indent With Tabs', 'code-snippets' ),
139144
'type' => 'checkbox',
140145
'label' => __( 'Use hard tabs instead of spaces for indentation.', 'code-snippets' ),
141-
'default' => true,
142146
'codemirror' => 'indentWithTabs',
143147
],
144-
145-
'tab_size' => [
148+
'tab_size' => [
146149
'name' => __( 'Tab Size', 'code-snippets' ),
147150
'type' => 'number',
148151
'desc' => __( 'The width of a tab character.', 'code-snippets' ),
149-
'default' => 4,
150152
'label' => _x( 'spaces', 'unit', 'code-snippets' ),
151153
'codemirror' => 'tabSize',
152154
'min' => 0,
153155
],
154-
155-
'indent_unit' => [
156+
'indent_unit' => [
156157
'name' => __( 'Indent Unit', 'code-snippets' ),
157158
'type' => 'number',
158159
'desc' => __( 'The number of spaces to indent a block.', 'code-snippets' ),
159-
'default' => 4,
160160
'label' => _x( 'spaces', 'unit', 'code-snippets' ),
161161
'codemirror' => 'indentUnit',
162162
'min' => 0,
163163
],
164-
165-
'wrap_lines' => [
164+
'wrap_lines' => [
166165
'name' => __( 'Wrap Lines', 'code-snippets' ),
167166
'type' => 'checkbox',
168167
'label' => __( 'Soft-wrap long lines of code instead of horizontally scrolling.', 'code-snippets' ),
169-
'default' => true,
170168
'codemirror' => 'lineWrapping',
171169
],
172-
173-
'code_folding' => [
170+
'code_folding' => [
174171
'name' => __( 'Code Folding', 'code-snippets' ),
175172
'type' => 'checkbox',
176173
'label' => __( 'Allow folding functions or other blocks into a single line.', 'code-snippets' ),
177-
'default' => true,
178174
'codemirror' => 'foldGutter',
179175
],
180-
181-
'line_numbers' => [
176+
'line_numbers' => [
182177
'name' => __( 'Line Numbers', 'code-snippets' ),
183178
'type' => 'checkbox',
184179
'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ),
185-
'default' => true,
186180
'codemirror' => 'lineNumbers',
187181
],
188-
189-
'auto_close_brackets' => [
182+
'auto_close_brackets' => [
190183
'name' => __( 'Auto Close Brackets', 'code-snippets' ),
191184
'type' => 'checkbox',
192185
'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ),
193-
'default' => true,
194186
'codemirror' => 'autoCloseBrackets',
195187
],
196-
197188
'highlight_selection_matches' => [
198189
'name' => __( 'Highlight Selection Matches', 'code-snippets' ),
199190
'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ),
200191
'type' => 'checkbox',
201-
'default' => true,
202192
'codemirror' => 'highlightSelectionMatches',
203193
],
204-
205-
'highlight_active_line' => [
194+
'highlight_active_line' => [
206195
'name' => __( 'Highlight Active Line', 'code-snippets' ),
207196
'label' => __( 'Highlight the line that is currently being edited.', 'code-snippets' ),
208197
'type' => 'checkbox',
209-
'default' => true,
210198
'codemirror' => 'styleActiveLine',
211199
],
212-
213-
'keymap' => [
200+
'keymap' => [
214201
'name' => __( 'Keymap', 'code-snippets' ),
215202
'type' => 'select',
216203
'desc' => __( 'The set of keyboard shortcuts to use in the code editor.', 'code-snippets' ),
217-
'default' => 'default',
218204
'options' => [
219205
'default' => __( 'Default', 'code-snippets' ),
220206
'vim' => __( 'Vim', 'code-snippets' ),
@@ -223,11 +209,9 @@ function get_settings_fields(): array {
223209
],
224210
'codemirror' => 'keyMap',
225211
],
226-
227-
'theme' => [
212+
'theme' => [
228213
'name' => __( 'Theme', 'code-snippets' ),
229214
'type' => 'select',
230-
'default' => 'default',
231215
'options' => get_editor_theme_list(),
232216
'codemirror' => 'theme',
233217
],

0 commit comments

Comments
 (0)