function acf_render_field_wrap($field, $el = 'div', $instruction = 'label') { // get valid field $field = acf_get_valid_field($field); // prepare field for input $field = acf_prepare_field($field); // el $elements = apply_filters('acf/render_field_wrap/elements', array('div' => 'div', 'tr' => 'td', 'ul' => 'li', 'ol' => 'li', 'dl' => 'dt', 'td' => 'div')); // validate $el if (!array_key_exists($el, $elements)) { $el = 'div'; } // wrapper $wrapper = array('id' => '', 'class' => 'acf-field', 'width' => '', 'style' => '', 'data-name' => $field['name'], 'data-type' => $field['type'], 'data-key' => ''); // add required if ($field['required']) { $wrapper['data-required'] = 1; } // add type $wrapper['class'] .= " acf-field-{$field['type']}"; // add key if ($field['key']) { $wrapper['class'] .= " acf-field-{$field['key']}"; $wrapper['data-key'] = $field['key']; } // replace $wrapper['class'] = str_replace('_', '-', $wrapper['class']); $wrapper['class'] = str_replace('field-field-', 'field-', $wrapper['class']); // wrap classes have changed (5.2.7) if (acf_get_compatibility('field_wrapper_class')) { $wrapper['class'] .= " field_type-{$field['type']}"; if ($field['key']) { $wrapper['class'] .= " field_key-{$field['key']}"; } } // merge in atts $wrapper = acf_merge_atts($wrapper, $field['wrapper']); // add width $width = (int) acf_extract_var($wrapper, 'width'); if ($el == 'tr' || $el == 'td') { $width = 0; } elseif ($width > 0 && $width < 100) { $wrapper['data-width'] = $width; $wrapper['style'] .= " width:{$width}%;"; } // remove empty attributes foreach ($wrapper as $k => $v) { if ($v == '') { unset($wrapper[$k]); } } // vars $show_label = $el !== 'td' ? true : false; ?> <<?php echo $el; ?> <?php echo acf_esc_attr($wrapper); ?> > <?php if ($show_label) { ?> <<?php echo $elements[$el]; ?> class="acf-label"> <label for="<?php echo $field['id']; ?> "><?php echo acf_get_field_label($field); ?> </label> <?php if ($instruction == 'label' && $field['instructions']) { ?> <p class="description"><?php echo $field['instructions']; ?> </p> <?php } ?> </<?php echo $elements[$el]; ?> > <?php } ?> <<?php echo $elements[$el]; ?> class="acf-input"> <?php acf_render_field($field); if ($instruction == 'field' && $field['instructions']) { ?> <p class="description"><?php echo $field['instructions']; ?> </p> <?php } ?> </<?php echo $elements[$el]; ?> > <?php if (!empty($field['conditional_logic'])) { ?> <script type="text/javascript"> if(typeof acf !== 'undefined'){ acf.conditional_logic.add( '<?php echo $field['key']; ?> ', <?php echo json_encode($field['conditional_logic']); ?> ); } </script> <?php } ?> </<?php echo $el; ?> > <?php }
function acf_views_render_field_wrap($field, $el = 'div', $instruction = 'label') { // get valid field $field = acf_get_valid_field($field); // prepare field for input $field = acf_prepare_field($field); // el $elements = apply_filters('acf/render_field_wrap/elements', array('div' => 'div', 'tr' => 'td', 'ul' => 'li', 'ol' => 'li', 'dl' => 'dt', 'td' => 'div')); // validate $el if (!array_key_exists($el, $elements)) { $el = 'div'; } // wrapper $wrapper = array('id' => '', 'class' => 'acf-field', 'width' => '', 'style' => '', 'data-name' => $field['name'], 'data-type' => $field['type'], 'data-key' => ''); // add required if ($field['required']) { $wrapper['data-required'] = 1; } // add type $wrapper['class'] .= " acf-output-{$field['type']}"; // add key if ($field['key']) { $wrapper['class'] .= " acf-field-{$field['key']}"; $wrapper['data-key'] = $field['key']; } // replace $wrapper['class'] = str_replace('_', '-', $wrapper['class']); $wrapper['class'] = str_replace('field-field-', 'field-', $wrapper['class']); // merge in atts $wrapper = acf_merge_atts($wrapper, $field['wrapper']); // add width $width = (int) acf_extract_var($wrapper, 'width'); if ($el == 'tr' || $el == 'td') { $width = 0; } elseif ($width > 0 && $width < 100) { $wrapper['data-width'] = $width; $wrapper['style'] .= " width:{$width}%;"; } // remove empty attributes foreach ($wrapper as $k => $v) { if ($v == '') { unset($wrapper[$k]); } } // vars $show_label = true; if ($el == 'td') { $show_label = false; } ?> <<?php echo $el; ?> <?php echo acf_esc_attr($wrapper); ?> > <?php if ($show_label) { ?> <<?php echo $elements[$el]; ?> class="acf-label"> <label for="<?php echo $field['id']; ?> "><?php echo acf_get_field_label($field); ?> </label> <?php if ($instruction == 'label' && $field['instructions']) { ?> <p class="description"><?php echo $field['instructions']; ?> </p> <?php } ?> </<?php echo $elements[$el]; ?> > <?php } ?> <<?php echo $elements[$el]; ?> class="acf-input"> <?php acf_views_render_field($field); ?> <?php if ($instruction == 'field' && $field['instructions']) { ?> <p class="description"><?php echo $field['instructions']; ?> </p> <?php } ?> </<?php echo $elements[$el]; ?> > </<?php echo $el; ?> > <?php }