advanced-settings.php
1 year ago
basic-settings.php
1 year ago
create-options-page-modal.php
1 year ago
list-empty.php
1 year ago
advanced-settings.php
309 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Advanced Settings for Options Pages |
| 4 | * |
| 5 | * Renders the advanced settings tabs for options page configuration. |
| 6 | * |
| 7 | * @package wordpress/secure-custom-fields |
| 8 | */ |
| 9 | |
| 10 | global $acf_ui_options_page; |
| 11 | |
| 12 | foreach ( acf_get_combined_options_page_settings_tabs() as $tab_key => $tab_label ) { |
| 13 | acf_render_field_wrap( |
| 14 | array( |
| 15 | 'type' => 'tab', |
| 16 | 'label' => $tab_label, |
| 17 | 'key' => 'acf_ui_options_page_tabs', |
| 18 | ) |
| 19 | ); |
| 20 | |
| 21 | $wrapper_class = str_replace( '_', '-', $tab_key ); |
| 22 | |
| 23 | echo '<div class="acf-ui-options-page-advanced-settings acf-ui-options-page-' . esc_attr( $wrapper_class ) . '-settings">'; |
| 24 | |
| 25 | switch ( $tab_key ) { |
| 26 | case 'visibility': |
| 27 | $acf_dashicon_class_name = __( 'Dashicon class name', 'secure-custom-fields' ); |
| 28 | $acf_dashicon_link = '<a href="https://developer.wordpress.org/resource/dashicons/" target="_blank">' . $acf_dashicon_class_name . '</a>'; |
| 29 | |
| 30 | $acf_menu_icon_instructions = sprintf( |
| 31 | /* translators: %s = "dashicon class name", link to the WordPress dashicon documentation. */ |
| 32 | __( 'The icon used for the options page menu item in the admin dashboard. Can be a URL or %s to use for the icon.', 'secure-custom-fields' ), |
| 33 | $acf_dashicon_link |
| 34 | ); |
| 35 | |
| 36 | // Set the default value for the icon field. |
| 37 | $acf_default_icon_value = array( |
| 38 | 'type' => 'dashicons', |
| 39 | 'value' => 'dashicons-admin-generic', |
| 40 | ); |
| 41 | |
| 42 | $acf_icon_value = $acf_default_icon_value; |
| 43 | |
| 44 | // Override the value for backwards compatibility, if it was saved with the key 'icon_url' as a string. |
| 45 | if ( ! empty( $acf_ui_options_page['icon_url'] ) ) { |
| 46 | if ( strpos( $acf_ui_options_page['icon_url'], 'dashicons-' ) === 0 ) { |
| 47 | $acf_icon_value = array( |
| 48 | 'type' => 'dashicons', |
| 49 | 'value' => $acf_ui_options_page['icon_url'], |
| 50 | ); |
| 51 | } else { |
| 52 | $acf_icon_value = array( |
| 53 | 'type' => 'url', |
| 54 | 'value' => $acf_ui_options_page['icon_url'], |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Override the above value if a 'menu_icon' key exists, and is not empty, which is the new key for storing the icon. |
| 60 | if ( ! empty( $acf_ui_options_page['menu_icon'] ) ) { |
| 61 | $acf_icon_value = $acf_ui_options_page['menu_icon']; |
| 62 | } |
| 63 | |
| 64 | acf_render_field_wrap( |
| 65 | array( |
| 66 | 'label' => __( 'Menu Icon', 'secure-custom-fields' ), |
| 67 | 'type' => 'icon_picker', |
| 68 | 'name' => 'menu_icon', |
| 69 | 'key' => 'menu_icon', |
| 70 | 'class' => 'acf-options-page-menu_icon', |
| 71 | 'prefix' => 'acf_ui_options_page', |
| 72 | 'required' => false, |
| 73 | 'value' => $acf_icon_value, |
| 74 | 'default_value' => $acf_default_icon_value, |
| 75 | 'conditions' => array( |
| 76 | 'field' => 'parent_slug', |
| 77 | 'operator' => '==', |
| 78 | 'value' => 'none', |
| 79 | ), |
| 80 | ), |
| 81 | 'div', |
| 82 | 'field' |
| 83 | ); |
| 84 | |
| 85 | acf_render_field_wrap( |
| 86 | array( |
| 87 | 'label' => __( 'Menu Title', 'secure-custom-fields' ), |
| 88 | 'type' => 'text', |
| 89 | 'name' => 'menu_title', |
| 90 | 'key' => 'menu_title', |
| 91 | 'class' => 'acf-options-page-menu_title', |
| 92 | 'prefix' => 'acf_ui_options_page', |
| 93 | 'value' => $acf_ui_options_page['menu_title'], |
| 94 | ), |
| 95 | 'div', |
| 96 | 'field' |
| 97 | ); |
| 98 | |
| 99 | $acf_menu_position_link = sprintf( |
| 100 | '<a href="https://developer.wordpress.org/reference/functions/add_menu_page/#default-bottom-of-menu-structure" target="_blank">%s</a>', |
| 101 | __( 'Learn more about menu positions.', 'secure-custom-fields' ) |
| 102 | ); |
| 103 | $acf_menu_position_desc = sprintf( |
| 104 | /* translators: %s - link to WordPress docs to learn more about menu positions. */ |
| 105 | __( 'The position in the menu where this page should appear. %s', 'secure-custom-fields' ), |
| 106 | $acf_menu_position_link |
| 107 | ); |
| 108 | |
| 109 | $acf_menu_position_desc_parent = sprintf( |
| 110 | /* translators: %s - link to WordPress docs to learn more about menu positions. */ |
| 111 | __( 'The position in the menu where this page should appear. %s', 'secure-custom-fields' ), |
| 112 | $acf_menu_position_link |
| 113 | ); |
| 114 | |
| 115 | $acf_menu_position_desc_child = __( 'The position in the menu where this child page should appear. The first child page is 0, the next is 1, etc.', 'secure-custom-fields' ); |
| 116 | |
| 117 | $acf_menu_position_desc = '<span class="acf-menu-position-desc-parent">' . $acf_menu_position_desc_parent . '</span>'; |
| 118 | $acf_menu_position_desc .= '<span class="acf-menu-position-desc-child">' . $acf_menu_position_desc_child . '</span>'; |
| 119 | |
| 120 | acf_render_field_wrap( |
| 121 | array( |
| 122 | 'label' => __( 'Menu Position', 'secure-custom-fields' ), |
| 123 | 'type' => 'text', |
| 124 | 'name' => 'position', |
| 125 | 'key' => 'position', |
| 126 | 'prefix' => 'acf_ui_options_page', |
| 127 | 'value' => $acf_ui_options_page['position'], |
| 128 | 'instructions' => $acf_menu_position_desc, |
| 129 | ), |
| 130 | 'div', |
| 131 | 'field' |
| 132 | ); |
| 133 | |
| 134 | acf_render_field_wrap( |
| 135 | array( |
| 136 | 'label' => __( 'Redirect to Child Page', 'secure-custom-fields' ), |
| 137 | 'instructions' => __( 'When child pages exist for this parent page, this page will redirect to the first child page.', 'secure-custom-fields' ), |
| 138 | 'type' => 'true_false', |
| 139 | 'name' => 'redirect', |
| 140 | 'key' => 'redirect', |
| 141 | 'prefix' => 'acf_ui_options_page', |
| 142 | 'value' => $acf_ui_options_page['redirect'], |
| 143 | 'ui' => 1, |
| 144 | 'default' => 1, |
| 145 | 'conditions' => array( |
| 146 | 'field' => 'parent_slug', |
| 147 | 'operator' => '==', |
| 148 | 'value' => 'none', |
| 149 | ), |
| 150 | ) |
| 151 | ); |
| 152 | |
| 153 | acf_render_field_wrap( |
| 154 | array( |
| 155 | 'type' => 'text', |
| 156 | 'name' => 'description', |
| 157 | 'key' => 'description', |
| 158 | 'prefix' => 'acf_ui_options_page', |
| 159 | 'value' => $acf_ui_options_page['description'], |
| 160 | 'label' => __( 'Description', 'secure-custom-fields' ), |
| 161 | 'instructions' => __( 'A descriptive summary of the options page.', 'secure-custom-fields' ), |
| 162 | ), |
| 163 | 'div', |
| 164 | 'field' |
| 165 | ); |
| 166 | break; |
| 167 | case 'labels': |
| 168 | acf_render_field_wrap( |
| 169 | array( |
| 170 | 'label' => __( 'Update Button Label', 'secure-custom-fields' ), |
| 171 | 'instructions' => __( 'The label used for the submit button which updates the fields on the options page.', 'secure-custom-fields' ), |
| 172 | 'placeholder' => __( 'Update', 'secure-custom-fields' ), |
| 173 | 'type' => 'text', |
| 174 | 'name' => 'update_button', |
| 175 | 'key' => 'update_button', |
| 176 | 'prefix' => 'acf_ui_options_page', |
| 177 | 'value' => $acf_ui_options_page['update_button'], |
| 178 | ), |
| 179 | 'div', |
| 180 | 'field' |
| 181 | ); |
| 182 | |
| 183 | acf_render_field_wrap( |
| 184 | array( |
| 185 | 'label' => __( 'Updated Message', 'secure-custom-fields' ), |
| 186 | 'instructions' => __( 'The message that is displayed after successfully updating the options page.', 'secure-custom-fields' ), |
| 187 | 'placeholder' => __( 'Updated Options', 'secure-custom-fields' ), |
| 188 | 'type' => 'text', |
| 189 | 'name' => 'updated_message', |
| 190 | 'key' => 'updated_message', |
| 191 | 'prefix' => 'acf_ui_options_page', |
| 192 | 'value' => $acf_ui_options_page['updated_message'], |
| 193 | ), |
| 194 | 'div', |
| 195 | 'field' |
| 196 | ); |
| 197 | |
| 198 | break; |
| 199 | case 'permissions': |
| 200 | $acf_all_caps = array(); |
| 201 | |
| 202 | foreach ( wp_roles()->roles as $acf_role ) { |
| 203 | $acf_all_caps = array_merge( $acf_all_caps, $acf_role['capabilities'] ); |
| 204 | } |
| 205 | |
| 206 | // Get rid of duplicates and set the keys equal to the values. |
| 207 | $acf_all_caps = array_unique( array_keys( $acf_all_caps ) ); |
| 208 | $acf_all_caps = array_combine( $acf_all_caps, $acf_all_caps ); |
| 209 | |
| 210 | // Move the "edit_posts" to the first select option. |
| 211 | if ( in_array( 'edit_posts', $acf_all_caps, true ) ) { |
| 212 | $acf_all_caps = array_diff( $acf_all_caps, array( 'edit_posts' ) ); |
| 213 | $acf_all_caps = array_merge( array( 'edit_posts' => 'edit_posts' ), $acf_all_caps ); |
| 214 | } |
| 215 | |
| 216 | // TODO: Should we AJAX load this? Seems to require UI = true, which breaks our custom template. |
| 217 | acf_render_field_wrap( |
| 218 | array( |
| 219 | 'type' => 'select', |
| 220 | 'name' => 'capability', |
| 221 | 'key' => 'capability', |
| 222 | 'prefix' => 'acf_ui_options_page', |
| 223 | 'value' => $acf_ui_options_page['capability'], |
| 224 | 'label' => __( 'Capability', 'secure-custom-fields' ), |
| 225 | 'instructions' => __( 'The capability required for this menu to be displayed to the user.', 'secure-custom-fields' ), |
| 226 | 'choices' => $acf_all_caps, |
| 227 | 'default' => 'edit_posts', |
| 228 | 'class' => 'acf-options-page-capability', |
| 229 | ), |
| 230 | 'div', |
| 231 | 'field' |
| 232 | ); |
| 233 | |
| 234 | acf_render_field_wrap( |
| 235 | array( |
| 236 | 'type' => 'select', |
| 237 | 'name' => 'data_storage', |
| 238 | 'key' => 'data_storage', |
| 239 | 'prefix' => 'acf_ui_options_page', |
| 240 | 'value' => $acf_ui_options_page['data_storage'], |
| 241 | 'label' => __( 'Data Storage', 'secure-custom-fields' ), |
| 242 | 'instructions' => __( 'By default, the option page stores field data in the options table. You can make the page load field data from a post, user, or term.', 'secure-custom-fields' ), |
| 243 | 'choices' => array( |
| 244 | 'options' => __( 'Options', 'secure-custom-fields' ), |
| 245 | 'post_id' => __( 'Custom Storage', 'secure-custom-fields' ), |
| 246 | ), |
| 247 | 'default' => 'options', |
| 248 | 'hide_search' => true, |
| 249 | 'class' => 'acf-options-page-data_storage', |
| 250 | ), |
| 251 | 'div', |
| 252 | 'field' |
| 253 | ); |
| 254 | |
| 255 | $acf_custom_storage_url = 'https://www.advancedcustomfields.com/resources/get_field/'; |
| 256 | |
| 257 | $acf_custom_storage_link = sprintf( |
| 258 | '<a href="%1$s" target="_blank">%2$s</a>', |
| 259 | $acf_custom_storage_url, |
| 260 | __( 'Learn more about available settings.', 'secure-custom-fields' ) |
| 261 | ); |
| 262 | |
| 263 | $acf_custom_storage_desc = sprintf( |
| 264 | /* translators: %s = link to learn more about storage locations. */ |
| 265 | __( 'Set a custom storage location. Can be a numeric post ID (123), or a string (`user_2`). %s', 'secure-custom-fields' ), |
| 266 | $acf_custom_storage_link |
| 267 | ); |
| 268 | |
| 269 | acf_render_field_wrap( |
| 270 | array( |
| 271 | 'label' => __( 'Custom Storage', 'secure-custom-fields' ), |
| 272 | 'instructions' => $acf_custom_storage_desc, |
| 273 | 'type' => 'text', |
| 274 | 'name' => 'post_id', |
| 275 | 'key' => 'post_id', |
| 276 | 'prefix' => 'acf_ui_options_page', |
| 277 | 'value' => $acf_ui_options_page['post_id'], |
| 278 | 'conditions' => array( |
| 279 | 'field' => 'data_storage', |
| 280 | 'operator' => '==', |
| 281 | 'value' => 'post_id', |
| 282 | ), |
| 283 | ), |
| 284 | 'div', |
| 285 | 'field' |
| 286 | ); |
| 287 | |
| 288 | acf_render_field_wrap( |
| 289 | array( |
| 290 | 'label' => __( 'Autoload Options', 'secure-custom-fields' ), |
| 291 | 'instructions' => __( 'Improve performance by loading the fields in the option records automatically when WordPress loads.', 'secure-custom-fields' ), |
| 292 | 'type' => 'true_false', |
| 293 | 'name' => 'autoload', |
| 294 | 'key' => 'autoload', |
| 295 | 'prefix' => 'acf_ui_options_page', |
| 296 | 'value' => $acf_ui_options_page['autoload'], |
| 297 | 'ui' => 1, |
| 298 | 'default' => 0, |
| 299 | ) |
| 300 | ); |
| 301 | break; |
| 302 | default: |
| 303 | } |
| 304 | |
| 305 | do_action( "acf/ui_options_page/render_settings_tab/{$tab_key}", $acf_ui_options_page ); |
| 306 | |
| 307 | echo '</div>'; |
| 308 | } |
| 309 |