field-column.php
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')){ |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | if(!class_exists('acfe_field_column')): |
| 8 | |
| 9 | class acfe_field_column extends acfe_field{ |
| 10 | |
| 11 | /** |
| 12 | * initialize |
| 13 | */ |
| 14 | function initialize(){ |
| 15 | |
| 16 | $this->name = 'acfe_column'; |
| 17 | $this->label = __('Column', 'acfe'); |
| 18 | $this->category = 'layout'; |
| 19 | $this->defaults = array( |
| 20 | 'columns' => '6/12', |
| 21 | 'endpoint' => false, |
| 22 | ); |
| 23 | |
| 24 | } |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * render_field_settings |
| 29 | * |
| 30 | * @param $field |
| 31 | */ |
| 32 | function render_field_settings($field){ |
| 33 | |
| 34 | // columns |
| 35 | acf_render_field_setting($field, array( |
| 36 | 'label' => __('Columns', 'acfe'), |
| 37 | 'instructions' => '', |
| 38 | 'type' => 'select', |
| 39 | 'name' => 'columns', |
| 40 | 'choices' => array( |
| 41 | '1/12' => '1/12', |
| 42 | '2/12' => '2/12', |
| 43 | '3/12' => '3/12', |
| 44 | '4/12' => '4/12', |
| 45 | '5/12' => '5/12', |
| 46 | '6/12' => '6/12', |
| 47 | '7/12' => '7/12', |
| 48 | '8/12' => '8/12', |
| 49 | '9/12' => '9/12', |
| 50 | '10/12' => '10/12', |
| 51 | '11/12' => '11/12', |
| 52 | '12/12' => '12/12', |
| 53 | ), |
| 54 | 'class' => 'acfe-field-columns', |
| 55 | 'conditional_logic' => array( |
| 56 | array( |
| 57 | array( |
| 58 | 'field' => 'endpoint', |
| 59 | 'operator' => '!=', |
| 60 | 'value' => '1', |
| 61 | ) |
| 62 | ) |
| 63 | ) |
| 64 | )); |
| 65 | |
| 66 | // endpoint |
| 67 | acf_render_field_setting($field, array( |
| 68 | 'label' => __('Endpoint','acf'), |
| 69 | 'instructions' => __('Define an endpoint for the previous columns to stop.', 'acf'), |
| 70 | 'name' => 'endpoint', |
| 71 | 'type' => 'true_false', |
| 72 | 'ui' => 1, |
| 73 | 'class' => 'acfe-field-columns-endpoint', |
| 74 | )); |
| 75 | |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * load_field |
| 81 | * |
| 82 | * @param $field |
| 83 | * |
| 84 | * @return mixed |
| 85 | */ |
| 86 | function load_field($field){ |
| 87 | |
| 88 | $columns = ''; |
| 89 | |
| 90 | if($field['columns']){ |
| 91 | $columns = ucfirst($field['columns']); |
| 92 | } |
| 93 | |
| 94 | if($field['endpoint']){ |
| 95 | $columns = 'Endpoint'; |
| 96 | } |
| 97 | |
| 98 | $field['label'] = '(Column ' . $columns . ')'; |
| 99 | $field['name'] = ''; |
| 100 | $field['instructions'] = ''; |
| 101 | $field['required'] = 0; |
| 102 | $field['value'] = false; |
| 103 | |
| 104 | return $field; |
| 105 | |
| 106 | } |
| 107 | |
| 108 | |
| 109 | /** |
| 110 | * prepare_field |
| 111 | * |
| 112 | * @param $field |
| 113 | * |
| 114 | * @return false |
| 115 | */ |
| 116 | function prepare_field($field){ |
| 117 | |
| 118 | global $pagenow; |
| 119 | |
| 120 | // do not render on User/Term views without Enhanced UI module (because of Table render) |
| 121 | if((acf_is_screen(array('profile', 'user-edit')) || (acf_is_screen('user') && !is_multisite()) || $pagenow === 'term.php') && !acf_get_setting('acfe/modules/ui')){ |
| 122 | return false; |
| 123 | } |
| 124 | |
| 125 | // do not render on New Term page (forced to left) |
| 126 | if($pagenow === 'edit-tags.php'){ |
| 127 | return false; |
| 128 | } |
| 129 | |
| 130 | // hide label |
| 131 | $field['label'] = false; |
| 132 | |
| 133 | // return |
| 134 | return $field; |
| 135 | |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /** |
| 140 | * field_wrapper_attributes |
| 141 | * |
| 142 | * @param $wrapper |
| 143 | * @param $field |
| 144 | * |
| 145 | * @return mixed |
| 146 | */ |
| 147 | function field_wrapper_attributes($wrapper, $field){ |
| 148 | |
| 149 | if($field['endpoint']){ |
| 150 | $wrapper['data-endpoint'] = $field['endpoint']; |
| 151 | |
| 152 | }elseif($field['columns']){ |
| 153 | $wrapper['data-columns'] = $field['columns']; |
| 154 | } |
| 155 | |
| 156 | return $wrapper; |
| 157 | |
| 158 | } |
| 159 | |
| 160 | |
| 161 | /** |
| 162 | * render_field |
| 163 | * |
| 164 | * @param $field |
| 165 | */ |
| 166 | function render_field($field){ |
| 167 | |
| 168 | // vars |
| 169 | $atts = array( |
| 170 | 'class' => 'acf-fields', |
| 171 | ); |
| 172 | |
| 173 | ?> |
| 174 | <div <?php echo acf_esc_atts($atts); ?>></div> |
| 175 | <?php |
| 176 | |
| 177 | } |
| 178 | |
| 179 | } |
| 180 | |
| 181 | // initialize |
| 182 | acf_register_field_type('acfe_field_column'); |
| 183 | |
| 184 | endif; |