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