| 1 |
<?php |
| 2 |
$id = wp_unique_id( 'bBlocksTableHead-' ); |
| 3 |
$wrapper_attributes = get_block_wrapper_attributes(); |
| 4 |
$colSpan= $attributes['settings']['colSpan']; |
| 5 |
$rowSpan= $attributes['settings']['rowSpan']; |
| 6 |
$styles = $attributes['styles']; |
| 7 |
$alignment = $styles['alignment']; |
| 8 |
$normal = $styles['normal']; |
| 9 |
$hover = $styles['hover']; |
| 10 |
|
| 11 |
if ( ! function_exists( 'b_blocks_table_cell_isValidCSS' ) ) { |
| 12 |
function b_blocks_table_cell_isValidCSS($property, $value) { |
| 13 |
if ( empty( $value ) && $value !== '0' && $value !== 0 ) { |
| 14 |
return ''; |
| 15 |
} |
| 16 |
return "$property: $value;"; |
| 17 |
} |
| 18 |
|
| 19 |
function b_blocks_table_cell_getBackgroundCSS( $bg, $isSolid = true, $isGradient = true, $isImage = true ) { |
| 20 |
if ( ! is_array( $bg ) ) { |
| 21 |
$bg = array(); |
| 22 |
} |
| 23 |
extract( $bg ); |
| 24 |
$type = $type ?? 'solid'; |
| 25 |
$color = $color ?? ''; |
| 26 |
$gradient = $gradient ?? 'linear-gradient(135deg, #0040E3, #18D4FD)'; |
| 27 |
$image = $image ?? []; |
| 28 |
$position = $position ?? 'center center'; |
| 29 |
$attachment = $attachment ?? ''; |
| 30 |
$repeat = $repeat ?? ''; |
| 31 |
$size = $size ?? ''; |
| 32 |
$overlayColor = $overlayColor ?? ''; |
| 33 |
|
| 34 |
if ( 'gradient' === $type && $isGradient ) { |
| 35 |
$styles = b_blocks_table_cell_isValidCSS('background', $gradient); |
| 36 |
} elseif ( 'image' === $type && $isImage ) { |
| 37 |
$imgUrl = $image['url'] ?? ''; |
| 38 |
$styles = "background: url($imgUrl);" |
| 39 |
. b_blocks_table_cell_isValidCSS('background-color', $overlayColor) |
| 40 |
. b_blocks_table_cell_isValidCSS('background-position', $position) |
| 41 |
. b_blocks_table_cell_isValidCSS('background-size', $size) |
| 42 |
. b_blocks_table_cell_isValidCSS('background-repeat', $repeat) |
| 43 |
. b_blocks_table_cell_isValidCSS('background-attachment', $attachment) |
| 44 |
. b_blocks_table_cell_isValidCSS('background-repeat', $repeat) |
| 45 |
. "background-blend-mode: overlay;"; |
| 46 |
} else { |
| 47 |
$styles = $isSolid ? b_blocks_table_cell_isValidCSS('background', $color) : ''; |
| 48 |
} |
| 49 |
|
| 50 |
return $styles; |
| 51 |
} |
| 52 |
} |
| 53 |
?> |
| 54 |
<style> |
| 55 |
#<?php echo esc_attr( $id ); ?> { |
| 56 |
<?php |
| 57 |
echo b_blocks_table_cell_getBackgroundCSS($normal['bg']); |
| 58 |
echo $hover['transition']? "transition: background " . $hover['transition'] . "s ease-in-out;": ""; |
| 59 |
?> |
| 60 |
} |
| 61 |
#<?php echo esc_attr( $id ); ?>:hover { |
| 62 |
<?php |
| 63 |
echo b_blocks_table_cell_getBackgroundCSS($hover['bg']); |
| 64 |
?> |
| 65 |
} |
| 66 |
|
| 67 |
</style> |
| 68 |
|
| 69 |
<thead <?php echo wp_kses_post(get_block_wrapper_attributes()); ?> id='<?php echo esc_attr( $id ); ?>'> |
| 70 |
<?php echo $content; ?> |
| 71 |
</thead> |
| 72 |
|
| 73 |
|