field-advanced-link.php
6 years ago
field-button.php
6 years ago
field-clone.php
6 years ago
field-column.php
6 years ago
field-dynamic-message.php
6 years ago
field-file.php
6 years ago
field-flexible-content.php
6 years ago
field-forms.php
6 years ago
field-group.php
6 years ago
field-hidden.php
6 years ago
field-image.php
6 years ago
field-post-statuses.php
6 years ago
field-post-types.php
6 years ago
field-recaptcha.php
6 years ago
field-repeater.php
6 years ago
field-select.php
6 years ago
field-slug.php
6 years ago
field-taxonomies.php
6 years ago
field-taxonomy-terms.php
6 years ago
field-textarea.php
6 years ago
field-user-roles.php
6 years ago
field-column.php
125 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | class acfe_field_column extends acf_field{ |
| 7 | |
| 8 | function __construct(){ |
| 9 | |
| 10 | $this->name = 'acfe_column'; |
| 11 | $this->label = __('Column', 'acfe'); |
| 12 | $this->category = 'layout'; |
| 13 | $this->defaults = array( |
| 14 | 'columns' => '3/6' |
| 15 | ); |
| 16 | |
| 17 | add_filter('acf/field_wrapper_attributes', array($this, 'field_wrapper_attributes'), 10, 2); |
| 18 | |
| 19 | parent::__construct(); |
| 20 | |
| 21 | } |
| 22 | |
| 23 | function render_field_settings($field){ |
| 24 | |
| 25 | // columns |
| 26 | acf_render_field_setting( $field, array( |
| 27 | 'label' => __('Columns', 'acfe'), |
| 28 | 'instructions' => '', |
| 29 | 'type' => 'select', |
| 30 | 'name' => 'columns', |
| 31 | 'choices' => array( |
| 32 | '1/6' => '1/6', |
| 33 | '2/6' => '2/6', |
| 34 | '3/6' => '3/6', |
| 35 | '4/6' => '4/6', |
| 36 | '5/6' => '5/6', |
| 37 | '6/6' => '6/6' |
| 38 | ), |
| 39 | 'conditional_logic' => array( |
| 40 | array( |
| 41 | array( |
| 42 | 'field' => 'endpoint', |
| 43 | 'operator' => '!=', |
| 44 | 'value' => '1', |
| 45 | ) |
| 46 | ) |
| 47 | ) |
| 48 | )); |
| 49 | |
| 50 | // endpoint |
| 51 | acf_render_field_setting( $field, array( |
| 52 | 'label' => __('Endpoint','acf'), |
| 53 | 'instructions' => __('Define an endpoint for the previous tabs to stop. This will start a new group of columns.', 'acf'), |
| 54 | 'name' => 'endpoint', |
| 55 | 'type' => 'true_false', |
| 56 | 'ui' => 1, |
| 57 | )); |
| 58 | |
| 59 | } |
| 60 | |
| 61 | function field_wrapper_attributes($wrapper, $field){ |
| 62 | |
| 63 | if($field['type'] !== 'acfe_column') |
| 64 | return $wrapper; |
| 65 | |
| 66 | if(isset($field['endpoint']) && !empty($field['endpoint'])){ |
| 67 | |
| 68 | $wrapper['data-endpoint'] = $field['endpoint']; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | elseif(isset($field['columns']) && !empty($field['columns'])){ |
| 73 | |
| 74 | $wrapper['data-columns'] = $field['columns']; |
| 75 | |
| 76 | } |
| 77 | |
| 78 | return $wrapper; |
| 79 | |
| 80 | } |
| 81 | |
| 82 | |
| 83 | function render_field($field){ |
| 84 | |
| 85 | // vars |
| 86 | $atts = array( |
| 87 | 'class' => 'acf-fields', |
| 88 | ); |
| 89 | |
| 90 | ?> |
| 91 | <div <?php acf_esc_attr_e($atts); ?>></div> |
| 92 | <?php |
| 93 | |
| 94 | } |
| 95 | |
| 96 | function load_field($field){ |
| 97 | |
| 98 | $columns = ''; |
| 99 | if(isset($field['columns'])) |
| 100 | $columns = ' ' . $field['columns']; |
| 101 | |
| 102 | if(isset($field['endpoint']) && !empty($field['endpoint'])) |
| 103 | $columns = ' endpoint'; |
| 104 | |
| 105 | $field['label'] = '(Column' . $columns .')'; |
| 106 | $field['name'] = ''; |
| 107 | $field['instructions'] = ''; |
| 108 | $field['required'] = 0; |
| 109 | $field['value'] = false; |
| 110 | |
| 111 | return $field; |
| 112 | |
| 113 | } |
| 114 | |
| 115 | function prepare_field($field){ |
| 116 | |
| 117 | $field['label'] = false; |
| 118 | |
| 119 | return $field; |
| 120 | |
| 121 | } |
| 122 | |
| 123 | } |
| 124 | |
| 125 | new acfe_field_column(); |