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