settings.php
278 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | add_action('admin_menu', 'acfe_admin_settings_menu'); |
| 7 | function acfe_admin_settings_menu(){ |
| 8 | if(!acf_get_setting('show_admin')) |
| 9 | return; |
| 10 | |
| 11 | $submenu_page = add_submenu_page('edit.php?post_type=acf-field-group', __('Settings'), __('Settings'), acf_get_setting('capability'), 'acfe-settings', 'acfe_admin_settings_html'); |
| 12 | |
| 13 | add_action('admin_print_scripts-' . $submenu_page, function(){ |
| 14 | wp_enqueue_style('acf-input'); |
| 15 | wp_enqueue_script('acf-input'); |
| 16 | }); |
| 17 | } |
| 18 | |
| 19 | add_action('admin_menu', 'acfe_admin_settings_submenu_swap', 999); |
| 20 | function acfe_admin_settings_submenu_swap(){ |
| 21 | global $submenu; |
| 22 | |
| 23 | if(!isset($submenu['edit.php?post_type=acf-field-group']) || empty($submenu['edit.php?post_type=acf-field-group'])) |
| 24 | return; |
| 25 | |
| 26 | foreach($submenu['edit.php?post_type=acf-field-group'] as $ikey => $item){ |
| 27 | |
| 28 | // ACFE: Field Group Category |
| 29 | if($item[2] == 'edit-tags.php?taxonomy=acf-field-group-category'){ |
| 30 | $temp_category = $submenu['edit.php?post_type=acf-field-group'][$ikey]; |
| 31 | $temp_category_key = $ikey; |
| 32 | } |
| 33 | |
| 34 | // ACFE: Settings |
| 35 | elseif($item[2] == 'acfe-settings'){ |
| 36 | $temp_settings = $submenu['edit.php?post_type=acf-field-group'][$ikey]; |
| 37 | $temp_settings_key = $ikey; |
| 38 | } |
| 39 | |
| 40 | // Tools |
| 41 | elseif($item[2] == 'acf-tools'){ |
| 42 | $temp_tools = $submenu['edit.php?post_type=acf-field-group'][$ikey]; |
| 43 | $temp_tools_key = $ikey; |
| 44 | } |
| 45 | |
| 46 | // Infos |
| 47 | elseif($item[2] == 'acf-settings-info'){ |
| 48 | $temp_infos = $submenu['edit.php?post_type=acf-field-group'][$ikey]; |
| 49 | $temp_infos_key = $ikey; |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | // Swapping |
| 55 | $submenu['edit.php?post_type=acf-field-group'][$temp_tools_key] = $temp_category; |
| 56 | $submenu['edit.php?post_type=acf-field-group'][$temp_infos_key] = $temp_settings; |
| 57 | $submenu['edit.php?post_type=acf-field-group'][$temp_category_key] = $temp_tools; |
| 58 | $submenu['edit.php?post_type=acf-field-group'][$temp_settings_key] = $temp_infos; |
| 59 | } |
| 60 | |
| 61 | function acfe_admin_settings_html(){ |
| 62 | ?> |
| 63 | <div class="wrap" id="acfe-admin-settings"> |
| 64 | |
| 65 | <h1><?php _e('Settings'); ?></h1> |
| 66 | |
| 67 | <div id="poststuff"> |
| 68 | <?php |
| 69 | |
| 70 | $load_json = acf_get_setting('load_json'); |
| 71 | $load_json_text = ''; |
| 72 | if(!empty($load_json)) |
| 73 | $load_json_text = implode("<br />", $load_json); |
| 74 | |
| 75 | $settings = array( |
| 76 | array( |
| 77 | 'name' => 'path', |
| 78 | 'label' => 'Path', |
| 79 | 'value' => '<code>' . acf_get_setting('path') . '</code>', |
| 80 | 'description' => 'Absolute path to ACF plugin folder including trailing slash.<br />Defaults to plugin_dir_path' |
| 81 | ), |
| 82 | array( |
| 83 | 'name' => 'dir', |
| 84 | 'label' => 'Directory', |
| 85 | 'value' => '<code>' . acf_get_setting('dir') . '</code>', |
| 86 | 'description' => 'URL to ACF plugin folder including trailing slash. Defaults to plugin_dir_url' |
| 87 | ), |
| 88 | array( |
| 89 | 'name' => 'show_admin', |
| 90 | 'label' => 'Show menu', |
| 91 | 'value' => '<code>' . (acf_get_setting('show_admin') ? __('True'): __('False')) . '</code>', |
| 92 | 'description' => 'Show/hide ACF menu item. Defaults to true' |
| 93 | ), |
| 94 | array( |
| 95 | 'name' => 'stripslashes', |
| 96 | 'label' => 'Strip slashes', |
| 97 | 'value' => '<code>' . (acf_get_setting('stripslashes') ? __('True'): __('False')) . '</code>', |
| 98 | 'description' => 'Runs the function stripslashes on all $_POST data. Some servers / WP instals may require this extra functioanlity. Defaults to false' |
| 99 | ), |
| 100 | array( |
| 101 | 'name' => 'local', |
| 102 | 'label' => 'PHP/Json', |
| 103 | 'value' => '<code>' . (acf_get_setting('local') ? __('True'): __('False')) . '</code>', |
| 104 | 'description' => 'Enable/Disable local (PHP/json) fields. Defaults to true' |
| 105 | ), |
| 106 | array( |
| 107 | 'name' => 'json', |
| 108 | 'label' => 'Json', |
| 109 | 'value' => '<code>' . (acf_get_setting('json') ? __('True'): __('False')) . '</code>', |
| 110 | 'description' => 'Enable/Disable json fields. Defaults to true' |
| 111 | ), |
| 112 | array( |
| 113 | 'name' => 'save_json', |
| 114 | 'label' => 'Json folder (save)', |
| 115 | 'value' => '<code>' . acf_get_setting('dir') . '</code>', |
| 116 | 'description' => 'Absolute path to folder where json files will be created when field groups are saved.<br />Defaults to ‘acf-json’ folder within current theme' |
| 117 | ), |
| 118 | array( |
| 119 | 'name' => 'load_json', |
| 120 | 'label' => 'Json folder (load)', |
| 121 | 'value' => '<code>' . $load_json_text . '</code>', |
| 122 | 'description' => 'Array of absolutes paths to folders where field group json files can be read.<br />Defaults to an array containing at index 0, the ‘acf-json’ folder within current theme' |
| 123 | ), |
| 124 | array( |
| 125 | 'name' => 'default_language', |
| 126 | 'label' => 'Default language', |
| 127 | 'value' => '<code>' . acf_get_setting('default_language') . '</code>', |
| 128 | 'description' => 'Language code of the default language. Defaults to ”.<br />If WPML is active, ACF will default this to the WPML default language setting' |
| 129 | ), |
| 130 | array( |
| 131 | 'name' => 'current_language', |
| 132 | 'label' => 'Current language', |
| 133 | 'value' => '<code>' . acf_get_setting('current_language') . '</code>', |
| 134 | 'description' => 'Language code of the current post’s language. Defaults to ”.<br />If WPML is active, ACF will default this to the WPML current language' |
| 135 | ), |
| 136 | array( |
| 137 | 'name' => 'capability', |
| 138 | 'label' => 'Capability', |
| 139 | 'value' => '<code>' . acf_get_setting('capability') . '</code>', |
| 140 | 'description' => 'Capability used for ACF post types and if the current user can see the ACF menu item.<br />Defaults to ‘manage_options’.' |
| 141 | ), |
| 142 | array( |
| 143 | 'name' => 'show_updates', |
| 144 | 'label' => 'Show updates', |
| 145 | 'value' => '<code>' . (acf_get_setting('show_updates') ? __('True'): __('False')) . '</code>', |
| 146 | 'description' => 'Enable/Disable updates to appear in plugin list and show/hide the ACF updates admin page.<br />Defaults to true.' |
| 147 | ), |
| 148 | array( |
| 149 | 'name' => 'export_textdomain', |
| 150 | 'label' => 'Export textdomain', |
| 151 | 'value' => '<code>' . (acf_get_setting('export_textdomain') ? __('True'): __('False')) . '</code>', |
| 152 | 'description' => 'Array of keys used during the ‘Export to PHP’ feature to wrap strings within the __() function.<br />Defaults to array(’title’, ’label’, ’instructions’). Depreciated in v5.3.4 – please see l10n_field and l10n_field_group' |
| 153 | ), |
| 154 | array( |
| 155 | 'name' => 'export_translate', |
| 156 | 'label' => 'Export translate', |
| 157 | 'value' => '<code>' . print_r(acf_get_setting('export_translate'), true) . '</code>', |
| 158 | 'description' => 'Used during the ‘Export to PHP’ feature to wrap strings within the __() function.<br />Depreciated in v5.4.4 – please see l10n_textdomain' |
| 159 | ), |
| 160 | array( |
| 161 | 'name' => 'autoload', |
| 162 | 'label' => 'Auto load', |
| 163 | 'value' => '<code>' . (acf_get_setting('autoload') ? __('True'): __('False')) . '</code>', |
| 164 | 'description' => 'Sets the text domain used when translating field and field group settings.<br />Defaults to ”. Strings will not be translated if this setting is empty' |
| 165 | ), |
| 166 | array( |
| 167 | 'name' => 'l10n', |
| 168 | 'label' => 'l10n', |
| 169 | 'value' => '<code>' . (acf_get_setting('l10n') ? __('True'): __('False')) . '</code>', |
| 170 | 'description' => 'Allows ACF to translate field and field group settings using the __() function.<br />Defaults to true. Useful to override translation without modifying the textdomain' |
| 171 | ), |
| 172 | array( |
| 173 | 'name' => 'l10n_textdomain', |
| 174 | 'label' => 'l10n Textdomain', |
| 175 | 'value' => '<code>' . (acf_get_setting('l10n') ? __('True'): __('False')) . '</code>', |
| 176 | 'description' => 'Sets the text domain used when translating field and field group settings.<br />Defaults to ”. Strings will not be translated if this setting is empty' |
| 177 | ), |
| 178 | array( |
| 179 | 'name' => 'l10n_field', |
| 180 | 'label' => 'l10n Field', |
| 181 | 'value' => '<code>' . print_r(acf_get_setting('l10n_field'), true) . '</code>', |
| 182 | 'description' => 'An array of settings to translate when loading and exporting a field.<br />Defaults to array(’label’, ’instructions’). Depreciated in v5.3.6 – please see acf/translate_field filter' |
| 183 | ), |
| 184 | array( |
| 185 | 'name' => 'l10n_field_group', |
| 186 | 'label' => 'l10n Field group', |
| 187 | 'value' => '<code>' . print_r(acf_get_setting('l10n_field_group'), true) . '</code>', |
| 188 | 'description' => 'An array of settings to translate when loading and exporting a field group.<br />Defaults to array(’title’). Depreciated in v5.3.6 – please see acf/translate_field_group filter' |
| 189 | ), |
| 190 | array( |
| 191 | 'name' => 'google_api_key', |
| 192 | 'label' => 'Google API Key', |
| 193 | 'value' => '<code>' . acf_get_setting('google_api_key') . '</code>', |
| 194 | 'description' => 'Specify a Google Maps API authentication key to prevent usage limits.<br />Defaults to ”' |
| 195 | ), |
| 196 | array( |
| 197 | 'name' => 'google_api_client', |
| 198 | 'label' => 'Google API Key', |
| 199 | 'value' => '<code>' . acf_get_setting('google_api_client') . '</code>', |
| 200 | 'description' => 'Specify a Google Maps API Client ID to prevent usage limits.<br />Not needed if using google_api_key. Defaults to ”' |
| 201 | ), |
| 202 | array( |
| 203 | 'name' => 'enqueue_google_maps', |
| 204 | 'label' => 'Enqueue Google Maps', |
| 205 | 'value' => '<code>' . (acf_get_setting('enqueue_google_maps') ? __('True'): __('False')) . '</code>', |
| 206 | 'description' => 'Allows ACF to enqueue and load the Google Maps API JS library.<br />Defaults to true' |
| 207 | ), |
| 208 | array( |
| 209 | 'name' => 'enqueue_select2', |
| 210 | 'label' => 'Enqueue Select2', |
| 211 | 'value' => '<code>' . (acf_get_setting('enqueue_select2') ? __('True'): __('False')) . '</code>', |
| 212 | 'description' => 'Allows ACF to enqueue and load the Select2 JS/CSS library.<br />Defaults to true' |
| 213 | ), |
| 214 | array( |
| 215 | 'name' => 'select2_version', |
| 216 | 'label' => 'Select2 version', |
| 217 | 'value' => '<code>' . acf_get_setting('select2_version') . '</code>', |
| 218 | 'description' => 'Defines which version of Select2 library to enqueue. Either 3 or 4.<br />Defaults to 4 since ACF 5.6.0' |
| 219 | ), |
| 220 | array( |
| 221 | 'name' => 'enqueue_datepicker', |
| 222 | 'label' => 'Enqueue Datepicker', |
| 223 | 'value' => '<code>' . (acf_get_setting('enqueue_datepicker') ? __('True'): __('False')) . '</code>', |
| 224 | 'description' => 'Allows ACF to enqueue and load the WP datepicker JS/CSS library.<br />Defaults to true' |
| 225 | ), |
| 226 | array( |
| 227 | 'name' => 'enqueue_datetimepicker', |
| 228 | 'label' => 'Enqueue Datepiker/time', |
| 229 | 'value' => '<code>' . (acf_get_setting('enqueue_datetimepicker') ? __('True'): __('False')) . '</code>', |
| 230 | 'description' => 'Allows ACF to enqueue and load the datetimepicker JS/CSS library.<br />Defaults to true' |
| 231 | ), |
| 232 | array( |
| 233 | 'name' => 'row_index_offset', |
| 234 | 'label' => 'Row index offset', |
| 235 | 'value' => '<code>' . acf_get_setting('row_index_offset') . '</code>', |
| 236 | 'description' => 'Defines the starting index used in all ‘loop’ and ‘row’ functions.<br />Defaults to 1 (1 is the first row), can be changed to 0 (0 is the first row)' |
| 237 | ), |
| 238 | array( |
| 239 | 'name' => 'remove_wp_meta_box', |
| 240 | 'label' => 'Remove WP meta box', |
| 241 | 'value' => '<code>' . (acf_get_setting('remove_wp_meta_box') ? __('True'): __('False')) . '</code>', |
| 242 | 'description' => 'Allows ACF to remove the default WP custom fields metabox. Defaults to true' |
| 243 | ), |
| 244 | ); |
| 245 | |
| 246 | ?> |
| 247 | <div class="postbox acf-postbox"> |
| 248 | <h2 class="hndle ui-sortable-handle"><span><?php _e('ACF Settings'); ?></span></h2> |
| 249 | <div class="inside acf-fields -left"> |
| 250 | |
| 251 | <?php foreach($settings as $setting){ ?> |
| 252 | <div class="acf-field"> |
| 253 | <div class="acf-label"> |
| 254 | <label><span class="acf-js-tooltip dashicons dashicons-info" style="float:right; font-size:16px; color:#ccc;" title="<?php echo $setting['description']; ?>"></span><?php echo $setting['label']; ?></label> |
| 255 | </div> |
| 256 | <div class="acf-input"> |
| 257 | <?php echo $setting['value']; ?> |
| 258 | </div> |
| 259 | </div> |
| 260 | <?php } ?> |
| 261 | |
| 262 | <script type="text/javascript"> |
| 263 | if( typeof acf !== 'undefined' ) { |
| 264 | |
| 265 | acf.newPostbox({ |
| 266 | 'id': 'acfe-settings', |
| 267 | 'label': 'left' |
| 268 | }); |
| 269 | |
| 270 | } |
| 271 | </script> |
| 272 | </div> |
| 273 | </div> |
| 274 | </div> |
| 275 | |
| 276 | </div> |
| 277 | <?php |
| 278 | } |