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