| 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 |
| 15 |
*/ |
| 16 |
function get_default_settings() { |
| 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 |
| 40 |
*/ |
| 41 |
function get_settings_fields() { |
| 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 |
'list_order' => [ |
| 73 |
'name' => __( 'Snippets List Order', 'code-snippets' ), |
| 74 |
'type' => 'select', |
| 75 |
'desc' => __( 'Default way to order snippets on the All Snippets admin menu.', 'code-snippets' ), |
| 76 |
'options' => [ |
| 77 |
'priority-asc' => __( 'Priority', 'code-snippets' ), |
| 78 |
'name-asc' => __( 'Name (A-Z)', 'code-snippets' ), |
| 79 |
'name-desc' => __( 'Name (Z-A)', 'code-snippets' ), |
| 80 |
'modified-desc' => __( 'Modified (latest first)', 'code-snippets' ), |
| 81 |
'modified-asc' => __( 'Modified (oldest first)', 'code-snippets' ), |
| 82 |
], |
| 83 |
'default' => 'priority-asc', |
| 84 |
], |
| 85 |
|
| 86 |
'disable_prism' => [ |
| 87 |
'name' => __( 'Disable Shortcode Syntax Highlighter', 'code-snippets' ), |
| 88 |
'type' => 'checkbox', |
| 89 |
'label' => __( 'Disable syntax highlighting when displaying snippet code on the front-end.', 'code-snippets' ), |
| 90 |
'default' => false, |
| 91 |
], |
| 92 |
|
| 93 |
'complete_uninstall' => [ |
| 94 |
'name' => __( 'Complete Uninstall', 'code-snippets' ), |
| 95 |
'type' => 'checkbox', |
| 96 |
'label' => __( 'When the plugin is deleted from the Plugins menu, also delete all snippets and plugin settings.', 'code-snippets' ), |
| 97 |
'default' => false, |
| 98 |
], |
| 99 |
]; |
| 100 |
|
| 101 |
if ( is_multisite() && ! is_main_site() ) { |
| 102 |
unset( $fields['general']['complete_uninstall'] ); |
| 103 |
} |
| 104 |
|
| 105 |
/* Description Editor settings section */ |
| 106 |
$fields['description_editor'] = [ |
| 107 |
|
| 108 |
'rows' => [ |
| 109 |
'name' => __( 'Row Height', 'code-snippets' ), |
| 110 |
'type' => 'number', |
| 111 |
'label' => __( 'rows', 'code-snippets' ), |
| 112 |
'default' => 5, |
| 113 |
'min' => 0, |
| 114 |
], |
| 115 |
|
| 116 |
'use_full_mce' => [ |
| 117 |
'name' => __( 'Use Full Editor', 'code-snippets' ), |
| 118 |
'type' => 'checkbox', |
| 119 |
'label' => __( 'Enable all features of the visual editor.', 'code-snippets' ), |
| 120 |
'default' => false, |
| 121 |
], |
| 122 |
|
| 123 |
'media_buttons' => [ |
| 124 |
'name' => __( 'Media Buttons', 'code-snippets' ), |
| 125 |
'type' => 'checkbox', |
| 126 |
'label' => __( 'Enable the add media buttons.', 'code-snippets' ), |
| 127 |
'default' => false, |
| 128 |
], |
| 129 |
]; |
| 130 |
|
| 131 |
/* Code Editor settings section */ |
| 132 |
|
| 133 |
$fields['editor'] = [ |
| 134 |
'theme' => [ |
| 135 |
'name' => __( 'Theme', 'code-snippets' ), |
| 136 |
'type' => 'select', |
| 137 |
'default' => 'default', |
| 138 |
'options' => get_editor_theme_list(), |
| 139 |
'codemirror' => 'theme', |
| 140 |
], |
| 141 |
|
| 142 |
'indent_with_tabs' => [ |
| 143 |
'name' => __( 'Indent With Tabs', 'code-snippets' ), |
| 144 |
'type' => 'checkbox', |
| 145 |
'label' => __( 'Use hard tabs (not spaces) for indentation.', 'code-snippets' ), |
| 146 |
'default' => true, |
| 147 |
'codemirror' => 'indentWithTabs', |
| 148 |
], |
| 149 |
|
| 150 |
'tab_size' => [ |
| 151 |
'name' => __( 'Tab Size', 'code-snippets' ), |
| 152 |
'type' => 'number', |
| 153 |
'desc' => __( 'The width of a tab character.', 'code-snippets' ), |
| 154 |
'default' => 4, |
| 155 |
'codemirror' => 'tabSize', |
| 156 |
'min' => 0, |
| 157 |
], |
| 158 |
|
| 159 |
'indent_unit' => [ |
| 160 |
'name' => __( 'Indent Unit', 'code-snippets' ), |
| 161 |
'type' => 'number', |
| 162 |
'desc' => __( 'How many spaces a block should be indented.', 'code-snippets' ), |
| 163 |
'default' => 4, |
| 164 |
'codemirror' => 'indentUnit', |
| 165 |
'min' => 0, |
| 166 |
], |
| 167 |
|
| 168 |
'wrap_lines' => [ |
| 169 |
'name' => __( 'Wrap Lines', 'code-snippets' ), |
| 170 |
'type' => 'checkbox', |
| 171 |
'label' => __( 'Whether the editor should scroll or wrap for long lines.', 'code-snippets' ), |
| 172 |
'default' => true, |
| 173 |
'codemirror' => 'lineWrapping', |
| 174 |
], |
| 175 |
|
| 176 |
'code_folding' => [ |
| 177 |
'name' => __( 'Code Folding', 'code-snippets' ), |
| 178 |
'type' => 'checkbox', |
| 179 |
'label' => __( 'Allow folding functions or other blocks into a single line.', 'code-snippets' ), |
| 180 |
'default' => true, |
| 181 |
'codemirror' => 'foldGutter', |
| 182 |
], |
| 183 |
|
| 184 |
'line_numbers' => [ |
| 185 |
'name' => __( 'Line Numbers', 'code-snippets' ), |
| 186 |
'type' => 'checkbox', |
| 187 |
'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ), |
| 188 |
'default' => true, |
| 189 |
'codemirror' => 'lineNumbers', |
| 190 |
], |
| 191 |
|
| 192 |
'auto_close_brackets' => [ |
| 193 |
'name' => __( 'Auto Close Brackets', 'code-snippets' ), |
| 194 |
'type' => 'checkbox', |
| 195 |
'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ), |
| 196 |
'default' => true, |
| 197 |
'codemirror' => 'autoCloseBrackets', |
| 198 |
], |
| 199 |
|
| 200 |
'highlight_selection_matches' => [ |
| 201 |
'name' => __( 'Highlight Selection Matches', 'code-snippets' ), |
| 202 |
'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ), |
| 203 |
'type' => 'checkbox', |
| 204 |
'default' => true, |
| 205 |
'codemirror' => 'highlightSelectionMatches', |
| 206 |
], |
| 207 |
|
| 208 |
'highlight_active_line' => [ |
| 209 |
'name' => __( 'Highlight Active Line', 'code-snippets' ), |
| 210 |
'label' => __( 'Highlight the line that is currently being edited.', 'code-snippets' ), |
| 211 |
'type' => 'checkbox', |
| 212 |
'default' => true, |
| 213 |
'codemirror' => 'styleActiveLine', |
| 214 |
], |
| 215 |
'keymap' => [ |
| 216 |
'name' => __( 'Keymap', 'code-snippets' ), |
| 217 |
'type' => 'select', |
| 218 |
'desc' => __( 'The keymap to use in the editor.', 'code-snippets' ), |
| 219 |
'default' => 'default', |
| 220 |
'options' => [ |
| 221 |
'default' => __( 'Default', 'code-snippets' ), |
| 222 |
'vim' => __( 'Vim', 'code-snippets' ), |
| 223 |
'emacs' => __( 'Emacs', 'code-snippets' ), |
| 224 |
'sublime' => __( 'Sublime Text', 'code-snippets' ), |
| 225 |
], |
| 226 |
'codemirror' => 'keyMap', |
| 227 |
], |
| 228 |
|
| 229 |
]; |
| 230 |
|
| 231 |
$fields = apply_filters( 'code_snippets_settings_fields', $fields ); |
| 232 |
|
| 233 |
return $fields; |
| 234 |
} |
| 235 |
|