meta_box_fields.php
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * Html: Fields |
| 5 | * |
| 6 | * @description: |
| 7 | * @since: 3.6 |
| 8 | * @created: 26/01/13 |
| 9 | */ |
| 10 | |
| 11 | |
| 12 | // global |
| 13 | global $post, $field_types; |
| 14 | |
| 15 | |
| 16 | // get fields |
| 17 | $fields = apply_filters('acf/field_group/get_fields', array(), $post->ID); |
| 18 | |
| 19 | |
| 20 | // add clone |
| 21 | $fields[] = apply_filters('acf/load_field_defaults', array( |
| 22 | 'key' => 'field_clone', |
| 23 | 'label' => __("New Field",'acf'), |
| 24 | 'name' => __("new_field",'acf'), |
| 25 | 'type' => 'text', |
| 26 | )); |
| 27 | |
| 28 | |
| 29 | // get name of all fields for use in field type drop down |
| 30 | $field_types = apply_filters('acf/registered_fields', array()); |
| 31 | |
| 32 | |
| 33 | // helper function |
| 34 | function field_type_exists( $name ) |
| 35 | { |
| 36 | global $field_types; |
| 37 | |
| 38 | foreach( $field_types as $category ) |
| 39 | { |
| 40 | if( isset( $category[ $name ] ) ) |
| 41 | { |
| 42 | return $category[ $name ]; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | |
| 50 | // conditional logic dummy data |
| 51 | $conditional_logic_rule = array( |
| 52 | 'field' => '', |
| 53 | 'operator' => '==', |
| 54 | 'value' => '' |
| 55 | ); |
| 56 | |
| 57 | $error_field_type = '<b>' . __('Error', 'acf') . '</b> ' . __('Field type does not exist', 'acf'); |
| 58 | |
| 59 | ?> |
| 60 | |
| 61 | <!-- Hidden Fields --> |
| 62 | <div style="display:none;"> |
| 63 | <script type="text/javascript"> |
| 64 | acf.text.move_to_trash = "<?php _e("Move to trash. Are you sure?",'acf'); ?>"; |
| 65 | acf.text.checked = "<?php _e("checked",'acf'); ?>"; |
| 66 | acf.text.conditional_no_fields = "<?php _e('No toggle fields available','acf'); ?>"; |
| 67 | acf.text.copy = "<?php _e('copy','acf'); ?>"; |
| 68 | </script> |
| 69 | <input type="hidden" name="acf_nonce" value="<?php echo wp_create_nonce( 'field_group' ); ?>" /> |
| 70 | </div> |
| 71 | <!-- / Hidden Fields --> |
| 72 | |
| 73 | |
| 74 | <!-- Fields Header --> |
| 75 | <div class="fields_header"> |
| 76 | <table class="acf widefat"> |
| 77 | <thead> |
| 78 | <tr> |
| 79 | <th class="field_order"><?php _e('Field Order','acf'); ?></th> |
| 80 | <th class="field_label"><?php _e('Field Label','acf'); ?></th> |
| 81 | <th class="field_name"><?php _e('Field Name','acf'); ?></th> |
| 82 | <th class="field_type"><?php _e('Field Type','acf'); ?></th> |
| 83 | <th class="field_key"><?php _e('Field Key','acf'); ?></th> |
| 84 | </tr> |
| 85 | </thead> |
| 86 | </table> |
| 87 | </div> |
| 88 | <!-- / Fields Header --> |
| 89 | |
| 90 | |
| 91 | <div class="fields"> |
| 92 | |
| 93 | <!-- No Fields Message --> |
| 94 | <div class="no_fields_message" <?php if(count($fields) > 1){ echo 'style="display:none;"'; } ?>> |
| 95 | <?php _e("No fields. Click the <strong>+ Add Field</strong> button to create your first field.",'acf'); ?> |
| 96 | </div> |
| 97 | <!-- / No Fields Message --> |
| 98 | |
| 99 | <?php foreach($fields as $field): |
| 100 | $fake_name = $field['key']; |
| 101 | ?> |
| 102 | <div class="field field_type-<?php echo $field['type']; ?> field_key-<?php echo $field['key']; ?>" data-type="<?php echo $field['type']; ?>" data-id="<?php echo $field['key']; ?>"> |
| 103 | <input type="hidden" class="input-field_key" name="fields[<?php echo $field['key']; ?>][key]" value="<?php echo $field['key']; ?>" /> |
| 104 | <div class="field_meta"> |
| 105 | <table class="acf widefat"> |
| 106 | <tr> |
| 107 | <td class="field_order"><span class="circle"><?php echo (int)$field['order_no'] + 1; ?></span></td> |
| 108 | <td class="field_label"> |
| 109 | <strong> |
| 110 | <a class="acf_edit_field row-title" title="<?php _e("Edit this Field",'acf'); ?>" href="javascript:;"><?php echo $field['label']; ?></a> |
| 111 | </strong> |
| 112 | <div class="row_options"> |
| 113 | <span><a class="acf_edit_field" title="<?php _e("Edit this Field",'acf'); ?>" href="javascript:;"><?php _e("Edit",'acf'); ?></a> | </span> |
| 114 | <span><a title="<?php _e("Read documentation for this field",'acf'); ?>" href="http://www.advancedcustomfields.com/docs/field-types/" target="_blank"><?php _e("Docs",'acf'); ?></a> | </span> |
| 115 | <span><a class="acf_duplicate_field" title="<?php _e("Duplicate this Field",'acf'); ?>" href="javascript:;"><?php _e("Duplicate",'acf'); ?></a> | </span> |
| 116 | <span><a class="acf_delete_field" title="<?php _e("Delete this Field",'acf'); ?>" href="javascript:;"><?php _e("Delete",'acf'); ?></a></span> |
| 117 | </div> |
| 118 | </td> |
| 119 | <td class="field_name"><?php echo $field['name']; ?></td> |
| 120 | <td class="field_type"><?php $l = field_type_exists( $field['type'] ); if( $l ){ echo $l; }else{ echo $error_field_type; } ?></td> |
| 121 | <td class="field_key"><?php echo $field['key']; ?></td> |
| 122 | </tr> |
| 123 | </table> |
| 124 | </div> |
| 125 | <div class="field_form_mask"> |
| 126 | <div class="field_form"> |
| 127 | |
| 128 | <table class="acf_input widefat acf_field_form_table"> |
| 129 | <tbody> |
| 130 | <tr class="field_label"> |
| 131 | <td class="label"> |
| 132 | <label><span class="required">*</span><?php _e("Field Label",'acf'); ?></label> |
| 133 | <p class="description"><?php _e("This is the name which will appear on the EDIT page",'acf'); ?></p> |
| 134 | </td> |
| 135 | <td> |
| 136 | <?php |
| 137 | do_action('acf/create_field', array( |
| 138 | 'type' => 'text', |
| 139 | 'name' => 'fields[' .$fake_name . '][label]', |
| 140 | 'value' => $field['label'], |
| 141 | 'class' => 'label', |
| 142 | )); |
| 143 | ?> |
| 144 | </td> |
| 145 | </tr> |
| 146 | <tr class="field_name"> |
| 147 | <td class="label"> |
| 148 | <label><span class="required">*</span><?php _e("Field Name",'acf'); ?></label> |
| 149 | <p class="description"><?php _e("Single word, no spaces. Underscores and dashes allowed",'acf'); ?></p> |
| 150 | </td> |
| 151 | <td> |
| 152 | <?php |
| 153 | do_action('acf/create_field', array( |
| 154 | 'type' => 'text', |
| 155 | 'name' => 'fields[' .$fake_name . '][name]', |
| 156 | 'value' => $field['name'], |
| 157 | 'class' => 'name', |
| 158 | )); |
| 159 | ?> |
| 160 | </td> |
| 161 | </tr> |
| 162 | <tr class="field_type"> |
| 163 | <td class="label"><label><span class="required">*</span><?php _e("Field Type",'acf'); ?></label></td> |
| 164 | <td> |
| 165 | <?php |
| 166 | do_action('acf/create_field', array( |
| 167 | 'type' => 'select', |
| 168 | 'name' => 'fields[' .$fake_name . '][type]', |
| 169 | 'value' => $field['type'], |
| 170 | 'choices' => $field_types, |
| 171 | )); |
| 172 | ?> |
| 173 | </td> |
| 174 | </tr> |
| 175 | <tr class="field_instructions"> |
| 176 | <td class="label"><label><?php _e("Field Instructions",'acf'); ?></label> |
| 177 | <p class="description"><?php _e("Instructions for authors. Shown when submitting data",'acf'); ?></p></td> |
| 178 | <td> |
| 179 | <?php |
| 180 | do_action('acf/create_field', array( |
| 181 | 'type' => 'textarea', |
| 182 | 'name' => 'fields[' .$fake_name . '][instructions]', |
| 183 | 'value' => $field['instructions'], |
| 184 | )); |
| 185 | ?> |
| 186 | </td> |
| 187 | </tr> |
| 188 | <tr class="required"> |
| 189 | <td class="label"><label><?php _e("Required?",'acf'); ?></label></td> |
| 190 | <td> |
| 191 | <?php |
| 192 | do_action('acf/create_field', array( |
| 193 | 'type' => 'radio', |
| 194 | 'name' => 'fields[' .$fake_name . '][required]', |
| 195 | 'value' => $field['required'], |
| 196 | 'choices' => array( |
| 197 | 1 => __("Yes",'acf'), |
| 198 | 0 => __("No",'acf'), |
| 199 | ), |
| 200 | 'layout' => 'horizontal', |
| 201 | )); |
| 202 | ?> |
| 203 | </td> |
| 204 | </tr> |
| 205 | <?php |
| 206 | |
| 207 | $field['name'] = $fake_name; |
| 208 | do_action('acf/create_field_options', $field ); |
| 209 | |
| 210 | ?> |
| 211 | <tr class="conditional-logic" data-field_name="<?php echo $field['key']; ?>"> |
| 212 | <td class="label"><label><?php _e("Conditional Logic",'acf'); ?></label></td> |
| 213 | <td> |
| 214 | <?php |
| 215 | do_action('acf/create_field', array( |
| 216 | 'type' => 'radio', |
| 217 | 'name' => 'fields['.$field['key'].'][conditional_logic][status]', |
| 218 | 'value' => $field['conditional_logic']['status'], |
| 219 | 'choices' => array( |
| 220 | 1 => __("Yes",'acf'), |
| 221 | 0 => __("No",'acf'), |
| 222 | ), |
| 223 | 'layout' => 'horizontal', |
| 224 | )); |
| 225 | |
| 226 | |
| 227 | // no rules? |
| 228 | if( ! $field['conditional_logic']['rules'] ) |
| 229 | { |
| 230 | $field['conditional_logic']['rules'] = array( |
| 231 | array() // this will get merged with $conditional_logic_rule |
| 232 | ); |
| 233 | } |
| 234 | |
| 235 | ?> |
| 236 | <div class="contional-logic-rules-wrapper" <?php if( ! $field['conditional_logic']['status'] ) echo 'style="display:none"'; ?>> |
| 237 | <table class="conditional-logic-rules widefat acf-rules <?php if( count($field['conditional_logic']['rules']) == 1) echo 'remove-disabled'; ?>"> |
| 238 | <tbody> |
| 239 | <?php foreach( $field['conditional_logic']['rules'] as $rule_i => $rule ): |
| 240 | |
| 241 | // validate |
| 242 | $rule = array_merge($conditional_logic_rule, $rule); |
| 243 | |
| 244 | |
| 245 | // fix PHP error in 3.5.4.1 |
| 246 | if( strpos($rule['value'],'Undefined index: value in') !== false ) |
| 247 | { |
| 248 | $rule['value'] = ''; |
| 249 | } |
| 250 | |
| 251 | ?> |
| 252 | <tr data-i="<?php echo $rule_i; ?>"> |
| 253 | <td> |
| 254 | <input class="conditional-logic-field" type="hidden" name="fields[<?php echo $field['key']; ?>][conditional_logic][rules][<?php echo $rule_i; ?>][field]" value="<?php echo $rule['field']; ?>" /> |
| 255 | </td> |
| 256 | <td width="25%"> |
| 257 | <?php |
| 258 | do_action('acf/create_field', array( |
| 259 | 'type' => 'select', |
| 260 | 'name' => 'fields['.$field['key'].'][conditional_logic][rules][' . $rule_i . '][operator]', |
| 261 | 'value' => $rule['operator'], |
| 262 | 'choices' => array( |
| 263 | '==' => __("is equal to",'acf'), |
| 264 | '!=' => __("is not equal to",'acf'), |
| 265 | ), |
| 266 | )); |
| 267 | ?> |
| 268 | </td> |
| 269 | <td><input class="conditional-logic-value" type="hidden" name="fields[<?php echo $field['key']; ?>][conditional_logic][rules][<?php echo $rule_i; ?>][value]" value="<?php echo $rule['value']; ?>" /></td> |
| 270 | <td class="buttons"> |
| 271 | <ul class="hl clearfix"> |
| 272 | <li><a class="acf-button-remove" href="javascript:;"></a></li> |
| 273 | <li><a class="acf-button-add" href="javascript:;"></a></li> |
| 274 | </ul> |
| 275 | </td> |
| 276 | </tr> |
| 277 | <?php endforeach; ?> |
| 278 | </tbody> |
| 279 | </table> |
| 280 | |
| 281 | <ul class="hl clearfix"> |
| 282 | <li style="padding:4px 4px 0 0;"><?php _e("Show this field when",'acf'); ?></li> |
| 283 | <li><?php do_action('acf/create_field', array( |
| 284 | 'type' => 'select', |
| 285 | 'name' => 'fields['.$field['key'].'][conditional_logic][allorany]', |
| 286 | 'value' => $field['conditional_logic']['allorany'], |
| 287 | 'choices' => array( |
| 288 | 'all' => __("all",'acf'), |
| 289 | 'any' => __("any",'acf'), |
| 290 | ), |
| 291 | )); ?></li> |
| 292 | <li style="padding:4px 0 0 4px;"><?php _e("these rules are met",'acf'); ?></li> |
| 293 | </ul> |
| 294 | |
| 295 | </div> |
| 296 | |
| 297 | |
| 298 | |
| 299 | </td> |
| 300 | </tr> |
| 301 | <tr class="field_save"> |
| 302 | <td class="label"></td> |
| 303 | <td> |
| 304 | <ul class="hl clearfix"> |
| 305 | <li> |
| 306 | <a class="acf_edit_field acf-button grey" title="<?php _e("Close Field",'acf'); ?>" href="javascript:;"><?php _e("Close Field",'acf'); ?></a> |
| 307 | </li> |
| 308 | </ul> |
| 309 | </td> |
| 310 | </tr> |
| 311 | </tbody> |
| 312 | </table> |
| 313 | </div> |
| 314 | </div> |
| 315 | </div> |
| 316 | <?php endforeach; ?> |
| 317 | </div> |
| 318 | <div class="table_footer"> |
| 319 | <div class="order_message"><?php _e('Drag and drop to reorder','acf'); ?></div> |
| 320 | <a href="javascript:;" id="add_field" class="acf-button"><?php _e('+ Add Field','acf'); ?></a> |
| 321 | </div> |