class-acf-field-tab.php
| 1 | <?php |
| 2 | |
| 3 | if( ! class_exists('acf_field_tab') ) : |
| 4 | |
| 5 | class acf_field_tab extends acf_field { |
| 6 | |
| 7 | |
| 8 | /* |
| 9 | * __construct |
| 10 | * |
| 11 | * This function will setup the field type data |
| 12 | * |
| 13 | * @type function |
| 14 | * @date 5/03/2014 |
| 15 | * @since 5.0.0 |
| 16 | * |
| 17 | * @param n/a |
| 18 | * @return n/a |
| 19 | */ |
| 20 | |
| 21 | function initialize() { |
| 22 | |
| 23 | // vars |
| 24 | $this->name = 'tab'; |
| 25 | $this->label = __("Tab",'acf'); |
| 26 | $this->category = 'layout'; |
| 27 | $this->defaults = array( |
| 28 | 'placement' => 'top', |
| 29 | 'endpoint' => 0 // added in 5.2.8 |
| 30 | ); |
| 31 | |
| 32 | } |
| 33 | |
| 34 | |
| 35 | /* |
| 36 | * render_field() |
| 37 | * |
| 38 | * Create the HTML interface for your field |
| 39 | * |
| 40 | * @param $field - an array holding all the field's data |
| 41 | * |
| 42 | * @type action |
| 43 | * @since 3.6 |
| 44 | * @date 23/01/13 |
| 45 | */ |
| 46 | |
| 47 | function render_field( $field ) { |
| 48 | |
| 49 | // vars |
| 50 | $atts = array( |
| 51 | 'href' => '', |
| 52 | 'class' => 'acf-tab-button', |
| 53 | 'data-placement' => $field['placement'], |
| 54 | 'data-endpoint' => $field['endpoint'], |
| 55 | 'data-key' => $field['key'] |
| 56 | ); |
| 57 | |
| 58 | ?> |
| 59 | <a <?php acf_esc_attr_e( $atts ); ?>><?php echo acf_esc_html($field['label']); ?></a> |
| 60 | <?php |
| 61 | |
| 62 | |
| 63 | } |
| 64 | |
| 65 | |
| 66 | |
| 67 | /* |
| 68 | * render_field_settings() |
| 69 | * |
| 70 | * Create extra options for your field. This is rendered when editing a field. |
| 71 | * The value of $field['name'] can be used (like bellow) to save extra data to the $field |
| 72 | * |
| 73 | * @param $field - an array holding all the field's data |
| 74 | * |
| 75 | * @type action |
| 76 | * @since 3.6 |
| 77 | * @date 23/01/13 |
| 78 | */ |
| 79 | |
| 80 | function render_field_settings( $field ) { |
| 81 | |
| 82 | /* |
| 83 | // message |
| 84 | $message = ''; |
| 85 | $message .= '<p>' . __( 'Use "Tab Fields" to better organize your edit screen by grouping fields together.', 'acf') . '</p>'; |
| 86 | $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>'; |
| 87 | |
| 88 | |
| 89 | // default_value |
| 90 | acf_render_field_setting( $field, array( |
| 91 | 'label' => __('Instructions','acf'), |
| 92 | 'instructions' => '', |
| 93 | 'name' => 'notes', |
| 94 | 'type' => 'message', |
| 95 | 'message' => $message, |
| 96 | )); |
| 97 | */ |
| 98 | |
| 99 | |
| 100 | // preview_size |
| 101 | acf_render_field_setting( $field, array( |
| 102 | 'label' => __('Placement','acf'), |
| 103 | 'type' => 'select', |
| 104 | 'name' => 'placement', |
| 105 | 'choices' => array( |
| 106 | 'top' => __("Top aligned", 'acf'), |
| 107 | 'left' => __("Left aligned", 'acf'), |
| 108 | ) |
| 109 | )); |
| 110 | |
| 111 | |
| 112 | // endpoint |
| 113 | acf_render_field_setting( $field, array( |
| 114 | 'label' => __('Endpoint','acf'), |
| 115 | 'instructions' => __('Define an endpoint for the previous tabs to stop. This will start a new group of tabs.', 'acf'), |
| 116 | 'name' => 'endpoint', |
| 117 | 'type' => 'true_false', |
| 118 | 'ui' => 1, |
| 119 | )); |
| 120 | |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /* |
| 125 | * load_field() |
| 126 | * |
| 127 | * This filter is appied to the $field after it is loaded from the database |
| 128 | * |
| 129 | * @type filter |
| 130 | * @since 3.6 |
| 131 | * @date 23/01/13 |
| 132 | * |
| 133 | * @param $field - the field array holding all the field options |
| 134 | * |
| 135 | * @return $field - the field array holding all the field options |
| 136 | */ |
| 137 | function load_field( $field ) { |
| 138 | |
| 139 | // remove name to avoid caching issue |
| 140 | $field['name'] = ''; |
| 141 | |
| 142 | // remove instructions |
| 143 | $field['instructions'] = ''; |
| 144 | |
| 145 | // remove required to avoid JS issues |
| 146 | $field['required'] = 0; |
| 147 | |
| 148 | // set value other than 'null' to avoid ACF loading / caching issue |
| 149 | $field['value'] = false; |
| 150 | |
| 151 | // return |
| 152 | return $field; |
| 153 | |
| 154 | } |
| 155 | |
| 156 | } |
| 157 | |
| 158 | |
| 159 | // initialize |
| 160 | acf_register_field_type( 'acf_field_tab' ); |
| 161 | |
| 162 | endif; // class_exists check |
| 163 | |
| 164 | ?> |