| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Retrieve the default setting values |
| 5 |
* @return array |
| 6 |
*/ |
| 7 |
function code_snippets_get_default_settings() { |
| 8 |
static $defaults; |
| 9 |
|
| 10 |
if ( isset( $defaults ) ) { |
| 11 |
return $defaults; |
| 12 |
} |
| 13 |
|
| 14 |
$defaults = array(); |
| 15 |
|
| 16 |
foreach ( code_snippets_get_settings_fields() as $section_id => $fields ) { |
| 17 |
$defaults[ $section_id ] = array(); |
| 18 |
|
| 19 |
foreach ( $fields as $field_id => $field_atts ) { |
| 20 |
$defaults[ $section_id ][ $field_id ] = $field_atts['default']; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
return $defaults; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Retrieve the settings fields |
| 29 |
* @return array |
| 30 |
*/ |
| 31 |
function code_snippets_get_settings_fields() { |
| 32 |
static $fields; |
| 33 |
|
| 34 |
if ( isset( $fields ) ) { |
| 35 |
return $fields; |
| 36 |
} |
| 37 |
|
| 38 |
$fields = array(); |
| 39 |
|
| 40 |
$fields['general'] = array( |
| 41 |
'activate_by_default' => array( |
| 42 |
'name' => __( 'Activate by Default', 'code-snippets' ), |
| 43 |
'type' => 'checkbox', |
| 44 |
'label' => __( "Make the 'Save and Activate' button the default action when saving a snippet.", 'code-snippets' ), |
| 45 |
'default' => true, |
| 46 |
), |
| 47 |
|
| 48 |
'snippet_scope_enabled' => array( |
| 49 |
'name' => __( 'Enable Scope Selector', 'code-snippets' ), |
| 50 |
'type' => 'checkbox', |
| 51 |
'label' => __( 'Enable the scope selector when editing a snippet', 'code-snippets' ), |
| 52 |
'default' => true, |
| 53 |
), |
| 54 |
|
| 55 |
'enable_tags' => array( |
| 56 |
'name' => __( 'Enable Snippet Tags', 'code-snippets' ), |
| 57 |
'type' => 'checkbox', |
| 58 |
'label' => __( 'Show snippet tags on admin pages', 'code-snippets' ), |
| 59 |
'default' => true, |
| 60 |
), |
| 61 |
|
| 62 |
'enable_description' => array( |
| 63 |
'name' => __( 'Enable Snippet Descriptions', 'code-snippets' ), |
| 64 |
'type' => 'checkbox', |
| 65 |
'label' => __( 'Show snippet descriptions on admin pages', 'code-snippets' ), |
| 66 |
'default' => true, |
| 67 |
), |
| 68 |
|
| 69 |
'disable_prism' => array( |
| 70 |
'name' => __( 'Disable Shortcode Syntax Highlighter', 'code-snippets' ), |
| 71 |
'type' => 'checkbox', |
| 72 |
'label' => __( 'Disable the syntax highlighting for the [code_snippet] shortcode on the front-end', 'code-snippets' ), |
| 73 |
'default' => false, |
| 74 |
), |
| 75 |
|
| 76 |
'complete_uninstall' => array( |
| 77 |
'name' => __( 'Complete Uninstall', 'code-snippets' ), |
| 78 |
'type' => 'checkbox', |
| 79 |
'label' => sprintf( |
| 80 |
/* translators: %s: URL for Plugins admin menu */ |
| 81 |
__( 'When the plugin is deleted from the <a href="%s">Plugins</a> menu, also delete all snippets and plugin settings.', 'code-snippets' ), |
| 82 |
self_admin_url( 'plugins.php' ) |
| 83 |
), |
| 84 |
'default' => false, |
| 85 |
), |
| 86 |
); |
| 87 |
|
| 88 |
if ( is_multisite() && ! is_main_site() ) { |
| 89 |
unset( $fields['general']['complete_uninstall'] ); |
| 90 |
} |
| 91 |
|
| 92 |
/* Description Editor settings section */ |
| 93 |
$fields['description_editor'] = array( |
| 94 |
|
| 95 |
'rows' => array( |
| 96 |
'name' => __( 'Row Height', 'code-snippets' ), |
| 97 |
'type' => 'number', |
| 98 |
'label' => __( 'rows', 'code-snippets' ), |
| 99 |
'default' => 5, |
| 100 |
'min' => 0, |
| 101 |
), |
| 102 |
|
| 103 |
'use_full_mce' => array( |
| 104 |
'name' => __( 'Use Full Editor', 'code-snippets' ), |
| 105 |
'type' => 'checkbox', |
| 106 |
'label' => __( 'Enable all features of the visual editor', 'code-snippets' ), |
| 107 |
'default' => false, |
| 108 |
), |
| 109 |
|
| 110 |
'media_buttons' => array( |
| 111 |
'name' => __( 'Media Buttons', 'code-snippets' ), |
| 112 |
'type' => 'checkbox', |
| 113 |
'label' => __( 'Enable the add media buttons', 'code-snippets' ), |
| 114 |
'default' => false, |
| 115 |
), |
| 116 |
); |
| 117 |
|
| 118 |
/* Code Editor settings section */ |
| 119 |
|
| 120 |
$fields['editor'] = array( |
| 121 |
'theme' => array( |
| 122 |
'name' => __( 'Theme', 'code-snippets' ), |
| 123 |
'type' => 'codemirror_theme_select', |
| 124 |
'default' => 'default', |
| 125 |
'codemirror' => 'theme', |
| 126 |
), |
| 127 |
|
| 128 |
'indent_with_tabs' => array( |
| 129 |
'name' => __( 'Indent With Tabs', 'code-snippets' ), |
| 130 |
'type' => 'checkbox', |
| 131 |
'label' => __( 'Use hard tabs (not spaces) for indentation.', 'code-snippets' ), |
| 132 |
'default' => true, |
| 133 |
'codemirror' => 'indentWithTabs', |
| 134 |
), |
| 135 |
|
| 136 |
'tab_size' => array( |
| 137 |
'name' => __( 'Tab Size', 'code-snippets' ), |
| 138 |
'type' => 'number', |
| 139 |
'desc' => __( 'The width of a tab character.', 'code-snippets' ), |
| 140 |
'default' => 4, |
| 141 |
'codemirror' => 'tabSize', |
| 142 |
'min' => 0, |
| 143 |
), |
| 144 |
|
| 145 |
'indent_unit' => array( |
| 146 |
'name' => __( 'Indent Unit', 'code-snippets' ), |
| 147 |
'type' => 'number', |
| 148 |
'desc' => __( 'How many spaces a block should be indented.', 'code-snippets' ), |
| 149 |
'default' => 2, |
| 150 |
'codemirror' => 'indentUnit', |
| 151 |
'min' => 0, |
| 152 |
), |
| 153 |
|
| 154 |
'wrap_lines' => array( |
| 155 |
'name' => __( 'Wrap Lines', 'code-snippets' ), |
| 156 |
'type' => 'checkbox', |
| 157 |
'label' => __( 'Whether the editor should scroll or wrap for long lines.', 'code-snippets' ), |
| 158 |
'default' => true, |
| 159 |
'codemirror' => 'lineWrapping', |
| 160 |
), |
| 161 |
|
| 162 |
'line_numbers' => array( |
| 163 |
'name' => __( 'Line Numbers', 'code-snippets' ), |
| 164 |
'type' => 'checkbox', |
| 165 |
'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ), |
| 166 |
'default' => true, |
| 167 |
'codemirror' => 'lineNumbers', |
| 168 |
), |
| 169 |
|
| 170 |
'auto_close_brackets' => array( |
| 171 |
'name' => __( 'Auto Close Brackets', 'code-snippets' ), |
| 172 |
'type' => 'checkbox', |
| 173 |
'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ), |
| 174 |
'default' => true, |
| 175 |
'codemirror' => 'autoCloseBrackets', |
| 176 |
), |
| 177 |
|
| 178 |
'highlight_selection_matches' => array( |
| 179 |
'name' => __( 'Highlight Selection Matches', 'code-snippets' ), |
| 180 |
'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ), |
| 181 |
'type' => 'checkbox', |
| 182 |
'default' => true, |
| 183 |
'codemirror' => 'highlightSelectionMatches', |
| 184 |
), |
| 185 |
); |
| 186 |
|
| 187 |
$fields = apply_filters( 'code_snippets_settings_fields', $fields ); |
| 188 |
|
| 189 |
return $fields; |
| 190 |
} |
| 191 |
|