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