Exemplo n.º 1
0
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 
}
Exemplo n.º 2
0
 function get_valid_field($field)
 {
     // conditional logic has changed
     if (isset($field['conditional_logic']['status'])) {
         // extract logic
         $logic = acf_extract_var($field, 'conditional_logic');
         // disabled
         if (!empty($logic['status'])) {
             // reset
             $field['conditional_logic'] = array();
             // vars
             $group = 0;
             $all_or_any = $logic['allorany'];
             // loop over rules
             if (!empty($logic['rules'])) {
                 foreach ($logic['rules'] as $rule) {
                     // sperate groups?
                     if ($all_or_any == 'any') {
                         $group++;
                     }
                     // add to group
                     $field['conditional_logic'][$group][] = $rule;
                 }
             }
             // reset keys
             $field['conditional_logic'] = array_values($field['conditional_logic']);
         } else {
             $field['conditional_logic'] = 0;
         }
     }
     // wrap classes have changed (5.2.7)
     if (acf_get_compatibility('field_wrapper_class')) {
         $field['wrapper']['class'] .= " field_type-{$field['type']}";
         if ($field['key']) {
             $field['wrapper']['class'] .= " field_key-{$field['key']}";
         }
     }
     // return
     return $field;
 }