| 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 ); ?>"> |
| 13 |
<?php if ( $attributes[ 'linkTo' ] == 'post' ) { ?> |
| 14 |
<a href="<?php echo esc_url( get_permalink() ); ?>"> |
| 15 |
<?php } ?> |
| 16 |
<?php |
| 17 |
|
| 18 |
$field = get_field_object( $attributes[ 'customField' ], get_the_ID() ); |
| 19 |
|
| 20 |
if ( $field ) : |
| 21 |
$output = ''; |
| 22 |
$fieldType = $field[ 'type' ]; |
| 23 |
$filedFormat = $field[ 'return_format' ]; |
| 24 |
|
| 25 |
switch ( $fieldType ) { |
| 26 |
case 'image' : |
| 27 |
$image = get_field( $attributes[ 'customField' ], get_the_ID() ); |
| 28 |
|
| 29 |
switch ( $filedFormat ) { |
| 30 |
case 'id' : |
| 31 |
$output = wp_get_attachment_image( $image, $imageSize ); |
| 32 |
|
| 33 |
break; |
| 34 |
case 'url' : |
| 35 |
$img_id = attachment_url_to_postid( $image ); |
| 36 |
$output = wp_get_attachment_image( $img_id, $imageSize ); |
| 37 |
|
| 38 |
break; |
| 39 |
case 'array' : |
| 40 |
$img_id = $image[ 'ID' ]; |
| 41 |
$output = wp_get_attachment_image( $img_id, $imageSize ); |
| 42 |
|
| 43 |
break; |
| 44 |
} |
| 45 |
|
| 46 |
break; |
| 47 |
} |
| 48 |
|
| 49 |
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 50 |
endif; |
| 51 |
?> |
| 52 |
<?php if ($attributes['linkTo'] == 'post'){ ?> |
| 53 |
</a> |
| 54 |
<?php } ?> |
| 55 |
</div> |
| 56 |
|