class-acf-field-accordion.php
5 months ago
class-acf-field-button-group.php
5 months ago
class-acf-field-checkbox.php
2 months ago
class-acf-field-color_picker.php
5 months ago
class-acf-field-date_picker.php
5 months ago
class-acf-field-date_time_picker.php
5 months ago
class-acf-field-email.php
5 months ago
class-acf-field-file.php
5 months ago
class-acf-field-google-map.php
5 months ago
class-acf-field-group.php
5 months ago
class-acf-field-icon_picker.php
6 months ago
class-acf-field-image.php
1 month ago
class-acf-field-link.php
5 months ago
class-acf-field-message.php
6 months ago
class-acf-field-number.php
5 months ago
class-acf-field-oembed.php
2 months ago
class-acf-field-output.php
6 months ago
class-acf-field-page_link.php
1 month ago
class-acf-field-password.php
5 months ago
class-acf-field-post_object.php
1 month ago
class-acf-field-radio.php
2 months ago
class-acf-field-range.php
5 months ago
class-acf-field-relationship.php
1 month ago
class-acf-field-select.php
2 months ago
class-acf-field-separator.php
6 months ago
class-acf-field-tab.php
6 months ago
class-acf-field-taxonomy.php
2 months ago
class-acf-field-text.php
5 months ago
class-acf-field-textarea.php
5 months ago
class-acf-field-time_picker.php
5 months ago
class-acf-field-true_false.php
5 months ago
class-acf-field-url.php
5 months ago
class-acf-field-user.php
2 months ago
class-acf-field-wysiwyg.php
5 months ago
class-acf-field.php
5 months ago
index.php
2 years ago
class-acf-field-tab.php
176 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package ACF |
| 4 | * @author WP Engine |
| 5 | * |
| 6 | * © 2026 Advanced Custom Fields (ACF®). All rights reserved. |
| 7 | * "ACF" is a trademark of WP Engine. |
| 8 | * Licensed under the GNU General Public License v2 or later. |
| 9 | * https://www.gnu.org/licenses/gpl-2.0.html |
| 10 | */ |
| 11 | |
| 12 | if ( ! class_exists( 'acf_field_tab' ) ) : |
| 13 | |
| 14 | class acf_field_tab extends acf_field { |
| 15 | |
| 16 | public $show_in_rest = false; |
| 17 | |
| 18 | /** |
| 19 | * This function will setup the field type data |
| 20 | * |
| 21 | * @type function |
| 22 | * @date 5/03/2014 |
| 23 | * @since 5.0.0 |
| 24 | * |
| 25 | * @param n/a |
| 26 | * @return n/a |
| 27 | */ |
| 28 | function initialize() { |
| 29 | |
| 30 | // vars |
| 31 | $this->name = 'tab'; |
| 32 | $this->label = __( 'Tab', 'acf' ); |
| 33 | $this->category = 'layout'; |
| 34 | $this->description = __( 'Allows you to group fields into tabbed sections in the edit screen. Useful for keeping fields organized and structured.', 'acf' ); |
| 35 | $this->preview_image = acf_get_url() . '/assets/images/field-type-previews/field-preview-tabs.png'; |
| 36 | $this->doc_url = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/tab/', 'docs', 'field-type-selection' ); |
| 37 | $this->supports = array( |
| 38 | 'required' => false, |
| 39 | 'bindings' => false, |
| 40 | ); |
| 41 | $this->defaults = array( |
| 42 | 'placement' => 'top', |
| 43 | 'endpoint' => 0, // added in 5.2.8 |
| 44 | 'selected' => 0, // added in 6.3 |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Output the HTML required for a tab. |
| 50 | * |
| 51 | * @since 3.6 |
| 52 | * |
| 53 | * @param array $field An array of the field data. |
| 54 | */ |
| 55 | public function render_field( $field ) { |
| 56 | $atts = array( |
| 57 | 'href' => '', |
| 58 | 'class' => 'acf-tab-button', |
| 59 | 'data-placement' => $field['placement'], |
| 60 | 'data-endpoint' => $field['endpoint'], |
| 61 | 'data-key' => $field['key'], |
| 62 | 'data-selected' => $field['selected'], |
| 63 | ); |
| 64 | |
| 65 | if ( isset( $field['unique_tab_key'] ) && ! empty( $field['unique_tab_key'] ) ) { |
| 66 | $atts['data-unique-tab-key'] = $field['unique_tab_key']; |
| 67 | } |
| 68 | |
| 69 | if ( isset( $field['settings-type'] ) ) { |
| 70 | $atts['data-settings-type'] = acf_slugify( $field['settings-type'] ); |
| 71 | $atts['class'] .= ' acf-settings-type-' . acf_slugify( $field['settings-type'] ); |
| 72 | } |
| 73 | |
| 74 | if ( isset( $field['class'] ) && ! empty( $field['class'] ) ) { |
| 75 | $atts['class'] .= ' ' . $field['class']; |
| 76 | } |
| 77 | |
| 78 | ?> |
| 79 | <a <?php echo acf_esc_attrs( $atts ); ?>><?php echo acf_esc_html( $field['label'] ); ?></a> |
| 80 | <?php |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Create extra options for your field. This is rendered when editing a field. |
| 85 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
| 86 | * |
| 87 | * @param $field - an array holding all the field's data |
| 88 | * |
| 89 | * @type action |
| 90 | * @since 3.6 |
| 91 | * @date 23/01/13 |
| 92 | */ |
| 93 | function render_field_settings( $field ) { |
| 94 | |
| 95 | /* |
| 96 | // message |
| 97 | $message = ''; |
| 98 | $message .= '<p>' . __( 'Use "Tab Fields" to better organize your edit screen by grouping fields together.', 'acf') . '</p>'; |
| 99 | $message .= '<p>' . __( 'All fields following this "tab field" (or until another "tab field" is defined) will be grouped together using this field\'s label as the tab heading.','acf') . '</p>'; |
| 100 | |
| 101 | |
| 102 | // default_value |
| 103 | acf_render_field_setting( $field, array( |
| 104 | 'label' => __('Instructions','acf'), |
| 105 | 'instructions' => '', |
| 106 | 'name' => 'notes', |
| 107 | 'type' => 'message', |
| 108 | 'message' => $message, |
| 109 | )); |
| 110 | */ |
| 111 | |
| 112 | // preview_size |
| 113 | acf_render_field_setting( |
| 114 | $field, |
| 115 | array( |
| 116 | 'label' => __( 'Placement', 'acf' ), |
| 117 | 'type' => 'select', |
| 118 | 'name' => 'placement', |
| 119 | 'choices' => array( |
| 120 | 'top' => __( 'Top aligned', 'acf' ), |
| 121 | 'left' => __( 'Left aligned', 'acf' ), |
| 122 | ), |
| 123 | ) |
| 124 | ); |
| 125 | |
| 126 | // endpoint |
| 127 | acf_render_field_setting( |
| 128 | $field, |
| 129 | array( |
| 130 | 'label' => __( 'New Tab Group', 'acf' ), |
| 131 | 'instructions' => __( 'Start a new group of tabs at this tab.', 'acf' ), |
| 132 | 'name' => 'endpoint', |
| 133 | 'type' => 'true_false', |
| 134 | 'ui' => 1, |
| 135 | ) |
| 136 | ); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | /** |
| 141 | * This filter is appied to the $field after it is loaded from the database |
| 142 | * |
| 143 | * @type filter |
| 144 | * @since 3.6 |
| 145 | * @date 23/01/13 |
| 146 | * |
| 147 | * @param $field - the field array holding all the field options |
| 148 | * |
| 149 | * @return $field - the field array holding all the field options |
| 150 | */ |
| 151 | function load_field( $field ) { |
| 152 | |
| 153 | // remove name to avoid caching issue |
| 154 | $field['name'] = ''; |
| 155 | |
| 156 | // remove instructions |
| 157 | $field['instructions'] = ''; |
| 158 | |
| 159 | // remove required to avoid JS issues |
| 160 | $field['required'] = 0; |
| 161 | |
| 162 | // set value other than 'null' to avoid ACF loading / caching issue |
| 163 | $field['value'] = false; |
| 164 | |
| 165 | // return |
| 166 | return $field; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | |
| 171 | // initialize |
| 172 | acf_register_field_type( 'acf_field_tab' ); |
| 173 | endif; // class_exists check |
| 174 | |
| 175 | ?> |
| 176 |