| 1 |
<?php |
| 2 |
|
| 3 |
// extract styles & classes |
| 4 |
extract( $extra_attr ); |
| 5 |
|
| 6 |
if ( empty( $attributes[ 'customField' ] ) ) { |
| 7 |
return; |
| 8 |
} |
| 9 |
|
| 10 |
?> |
| 11 |
|
| 12 |
<div class="<?php echo esc_attr( $wrapper_class ); ?>" <?php if ( ! empty( $wrapper_style ) ) { ?> style="<?php echo esc_attr( $wrapper_style ); ?>" <?php } ?>> |
| 13 |
|
| 14 |
<?php |
| 15 |
$field = get_field_object( $attributes[ 'customField' ], get_the_ID() ); |
| 16 |
|
| 17 |
if ( $field ) : |
| 18 |
$output = ''; |
| 19 |
$fieldType = $field[ 'type' ]; |
| 20 |
|
| 21 |
if ( ! empty( $attributes[ 'labelName' ] ) ) { |
| 22 |
$output .= '<span class="' . esc_attr( 'wp-block-getwid-template-acf-select__label' ) . '">' . esc_html( $attributes[ 'labelName' ] ) . '</span>'; |
| 23 |
} |
| 24 |
|
| 25 |
switch ( $fieldType ) { |
| 26 |
case 'select' : |
| 27 |
$fieldIsMultiple = $field[ 'multiple' ]; |
| 28 |
$fieldReturnFormat = $field[ 'return_format' ]; |
| 29 |
$fieldValue = $field[ 'value' ]; |
| 30 |
|
| 31 |
switch ( $fieldReturnFormat ) { |
| 32 |
case 'value' : |
| 33 |
case 'label' : { |
| 34 |
if ( $fieldIsMultiple ) { |
| 35 |
$numCount = 0; |
| 36 |
$numOfItems = count( $fieldValue ); |
| 37 |
|
| 38 |
foreach ( $fieldValue as $value ) { |
| 39 |
$numCount = $numCount + 1; |
| 40 |
$getValue = $value; |
| 41 |
|
| 42 |
$output .= '<span class="wp-block-getwid-template-acf-select__value ' . esc_attr( 'option-' . strtolower( $getValue ) ) . '">'; |
| 43 |
$output .= esc_html( $getValue ); |
| 44 |
$output .= '</span>'; |
| 45 |
|
| 46 |
if ( $numCount < $numOfItems ) { |
| 47 |
$output .= esc_html( $attributes[ 'separator' ] ); |
| 48 |
} |
| 49 |
} |
| 50 |
} else { |
| 51 |
$output .= '<span class="wp-block-getwid-template-acf-select__value ' . esc_attr( 'option-' . strtolower( $fieldValue ) ) . '">'; |
| 52 |
$output .= esc_html( $fieldValue ); |
| 53 |
$output .= '</span>'; |
| 54 |
} |
| 55 |
|
| 56 |
break; |
| 57 |
} |
| 58 |
case 'array' : |
| 59 |
if ( $fieldIsMultiple ) { |
| 60 |
$numCount = 0; |
| 61 |
$numOfItems = count( $fieldValue ); |
| 62 |
|
| 63 |
foreach ( $fieldValue as $value ) { |
| 64 |
$numCount = $numCount + 1; |
| 65 |
$getBothArray = $value[ 'value' ] . ': ' . $value[ 'label' ]; |
| 66 |
$getValueArray = $value[ 'value' ]; |
| 67 |
|
| 68 |
$output .= '<span class="wp-block-getwid-template-acf-select__value ' . esc_attr( 'option-' . strtolower( $getValueArray ) ) . '">'; |
| 69 |
$output .= esc_html( $getBothArray ); |
| 70 |
$output .= '</span>'; |
| 71 |
|
| 72 |
if ( $numCount < $numOfItems ) { |
| 73 |
$output .= esc_html( $attributes[ 'separator' ] ); |
| 74 |
} |
| 75 |
} |
| 76 |
} else { |
| 77 |
$output .= '<span class="wp-block-getwid-template-acf-select__value ' . esc_attr( 'option-' . strtolower( $fieldValue[ 'value' ] ) ) . '">'; |
| 78 |
$output .= esc_html( $fieldValue[ 'value' ] . ': ' . $fieldValue[ 'label' ] ); |
| 79 |
$output .= '</span>'; |
| 80 |
} |
| 81 |
|
| 82 |
break; |
| 83 |
} |
| 84 |
|
| 85 |
break; |
| 86 |
} |
| 87 |
|
| 88 |
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 89 |
endif; |
| 90 |
?> |
| 91 |
</div> |
| 92 |
|