| 1 |
<?php |
| 2 |
namespace gutenify; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Info_Box |
| 7 |
{ |
| 8 |
public static function init() |
| 9 |
{ |
| 10 |
add_action('init', array(__CLASS__, 'register_block')); |
| 11 |
add_filter('gutenify_render_block_gutenify/info-box', array(__CLASS__, 'render_block'), 10, 4); |
| 12 |
} |
| 13 |
|
| 14 |
public static function register_block() |
| 15 |
{ |
| 16 |
register_block_type(__DIR__); |
| 17 |
} |
| 18 |
|
| 19 |
public static function render_block($block_content, $block, $instance, $block_id) |
| 20 |
{ |
| 21 |
$root_selector = '.' . $block_id; |
| 22 |
$css = ''; |
| 23 |
|
| 24 |
$css_chunk = ''; |
| 25 |
|
| 26 |
//text |
| 27 |
if (!empty($block['attrs']['blockAdvanceOptions']['textColor'])) { |
| 28 |
$css_chunk .= 'color: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['textColor'] ) . ';'; |
| 29 |
} |
| 30 |
|
| 31 |
//background |
| 32 |
if (!empty($block['attrs']['backgroundGradient'])) { |
| 33 |
$css_chunk .= 'background:' . esc_attr( $block['attrs']['backgroundGradient'] ) . ';'; |
| 34 |
} elseif (!empty($block['attrs']['backgroundColor'])) { |
| 35 |
$css_chunk .= 'background: ' . esc_attr( $block['attrs']['backgroundColor'] ) . ';'; |
| 36 |
} elseif (!empty($block['attrs']['blockAdvanceOptions']['backgroundGradient'])) { |
| 37 |
$css_chunk .= 'background: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['backgroundGradient'] ) . ';'; |
| 38 |
} elseif (!empty($block['attrs']['blockAdvanceOptions']['backgroundColor'])) { |
| 39 |
$css_chunk .= 'background: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['backgroundColor'] ) . ';'; |
| 40 |
} |
| 41 |
|
| 42 |
//border |
| 43 |
//border width |
| 44 |
|
| 45 |
if ( ! empty( $block['attrs']['borderWidth'] ) ) { |
| 46 |
$css_chunk .= 'border-style:solid;'; |
| 47 |
$css_chunk .= \gutenify\Style_Helpers::box_control( $block['attrs']['borderWidth'], 'border-', '-width'); |
| 48 |
} |
| 49 |
|
| 50 |
if ( ! empty( $block['attrs']['blockAdvanceOptions']['borderWidth'] ) ) { |
| 51 |
$css_chunk .= 'border-style:solid;'; |
| 52 |
$css_chunk .= \gutenify\Style_Helpers::box_control( $block['attrs']['blockAdvanceOptions']['borderWidth'], 'border-', '-width'); |
| 53 |
} |
| 54 |
|
| 55 |
if ( ! empty( $block['attrs']['blockAdvanceOptions']['borderRadius'] ) ) { |
| 56 |
$css_chunk .= \gutenify\Style_Helpers::border_radius_control( $block['attrs']['blockAdvanceOptions']['borderRadius'] ); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
//border color |
| 61 |
if (!empty($block['attrs']['blockAdvanceOptions']['borderColor'])) { |
| 62 |
$css_chunk .= 'border-color: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['borderColor'] ) . ';'; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
//border radius |
| 67 |
if ( ! empty( $block['attrs']['borderRadius'] ) ) { |
| 68 |
$css_chunk .= \gutenify\Style_Helpers::border_radius_control( $block['attrs']['borderRadius'] ); |
| 69 |
} |
| 70 |
|
| 71 |
if ( ! empty( $block['attrs']['blockAdvanceOptions']['borderRadius'] ) ) { |
| 72 |
$css_chunk .= \gutenify\Style_Helpers::border_radius_control( $block['attrs']['blockAdvanceOptions']['borderRadius'] ); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
if (!empty($css_chunk)) { |
| 77 |
$css .= $root_selector . ' {' . $css_chunk . '}'; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Hover |
| 82 |
*/ |
| 83 |
$css_chunk = ''; |
| 84 |
|
| 85 |
//hover color |
| 86 |
if (!empty($block['attrs']['blockAdvanceOptions']['hoverTextColor'])) { |
| 87 |
$css_chunk .= 'color: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverTextColor'] ) . ';'; |
| 88 |
} |
| 89 |
|
| 90 |
//hover background |
| 91 |
if (!empty($block['attrs']['hoverBackgroundGradient'])) { |
| 92 |
$css_chunk .= 'background: ' . esc_attr( $block['attrs']['hoverBackgroundGradient'] ) . ';'; |
| 93 |
} elseif (!empty($block['attrs']['blockAdvanceOptions']['hoverBackgroundGradient'])) { |
| 94 |
$css_chunk .= 'background: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverBackgroundGradient'] ) . ';'; |
| 95 |
} elseif (!empty($block['attrs']['hoverBackgroundColor'])) { |
| 96 |
$css_chunk .= 'background:' . esc_attr( $block['attrs']['hoverBackgroundColor'] ) . ';'; |
| 97 |
} elseif (!empty($block['attrs']['blockAdvanceOptions']['hoverBackgroundColor'])) { |
| 98 |
$css_chunk .= 'background:' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverBackgroundColor'] ) . ';'; |
| 99 |
} else { |
| 100 |
$css_chunk .= ''; |
| 101 |
} |
| 102 |
|
| 103 |
//hover border |
| 104 |
if (!empty($block['attrs']['blockAdvanceOptions']['hoverBorderColor'])) { |
| 105 |
$css_chunk .= 'border-color:' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverBorderColor'] ) . ';'; |
| 106 |
} |
| 107 |
if (!empty($css_chunk)) { |
| 108 |
$css .= $root_selector . ':hover {' . $css_chunk . '}'; |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Heading |
| 113 |
*/ |
| 114 |
$css_chunk = ''; |
| 115 |
if (!empty($block['attrs']['blockAdvanceOptions']['textColor'])) { |
| 116 |
$css_chunk .= 'color: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['textColor'] ) . ';'; |
| 117 |
} |
| 118 |
if (!empty($css_chunk)) { |
| 119 |
$css .= $root_selector . ' :where(h1,h2,h3,h4,h5,h6){' . $css_chunk . '}'; |
| 120 |
} |
| 121 |
|
| 122 |
// Hover Heading |
| 123 |
$css_chunk = ''; |
| 124 |
if (!empty($block['attrs']['blockAdvanceOptions']['hoverTextColor'])) { |
| 125 |
$css_chunk .= 'color: ' . esc_attr( $block['attrs']['blockAdvanceOptions']['hoverTextColor'] ) . ';'; |
| 126 |
} |
| 127 |
if (!empty($css_chunk)) { |
| 128 |
$css .= $root_selector . ':hover .wp-block-heading{' . $css_chunk . '}'; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
$handle = 'gutenify_' . str_replace('/', '_', $block['blockName']) . '_' . $block_id; |
| 133 |
wp_add_inline_style($handle, $css); |
| 134 |
return $block_content; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
Info_Box::init(); |
| 139 |
|