| 1 |
<?php |
| 2 |
class BBlocksSectionHeading extends BBlocks{ |
| 3 |
public function __construct(){ |
| 4 |
add_action( 'init', [$this, 'register'] ); |
| 5 |
} |
| 6 |
|
| 7 |
function register(){ |
| 8 |
$this::registerScripts( 'section-heading', array( |
| 9 |
'attributes' => $this->attributes(), |
| 10 |
'render_callback' => [$this, 'render'] |
| 11 |
) ); |
| 12 |
} |
| 13 |
|
| 14 |
function attributes(){ |
| 15 |
return array( |
| 16 |
'align' => array( 'type' => 'string', 'default' => '' ), |
| 17 |
'cId' => array( 'type' => 'string', 'default' => '' ), |
| 18 |
|
| 19 |
'textAlign' => array( 'type' => 'string', 'default' => 'left' ), |
| 20 |
|
| 21 |
'title' => array( 'type' => 'string', 'default' => 'Section Heading' ), |
| 22 |
'titleTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 25, 'fontWeight' => 600 ) ), |
| 23 |
'titleColor' => array( 'type' => 'string', 'default' => '#4527a4' ), |
| 24 |
'titleMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ), |
| 25 |
|
| 26 |
'isSep' => array( 'type' => 'boolean', 'default' => true ), |
| 27 |
'separator' => array( 'type' => 'object', 'default' => array( 'width' => '150px', 'height' => '3px', 'color' => '#8344c5' ) ), |
| 28 |
'sepMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '5px' ) ), |
| 29 |
|
| 30 |
'isDesc' => array( 'type' => 'boolean', 'default' => true ), |
| 31 |
'desc' => array( 'type' => 'string', 'default' => 'This content area describes section heading descriptions or details.' ), |
| 32 |
'descTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) ), |
| 33 |
'descColor' => array( 'type' => 'string', 'default' => '#333' ), |
| 34 |
'descMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '15px' ) ) |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
function render( $attributes ){ |
| 39 |
extract( $attributes ); |
| 40 |
|
| 41 |
// Generate Styles |
| 42 |
$sectionHeadingStyle = new BBlocksStyleGenerator(); |
| 43 |
$sectionHeadingStyle::addStyle( "#bBlocksSectionHeading-$cId .bBlocksSectionHeading", array( |
| 44 |
'text-align' => $textAlign |
| 45 |
) ); |
| 46 |
$sectionHeadingStyle::addStyle( "#bBlocksSectionHeading-$cId .bBlocksSectionHeading .sectionHeadingTitle", array( |
| 47 |
$titleTypo['styles'] ?? 'font-size: 25px; font-weight: 600;' => '', |
| 48 |
'color' => $titleColor, |
| 49 |
'margin' => $titleMargin['styles'] ?? '0 0 10px 0' |
| 50 |
) ); |
| 51 |
$sectionHeadingStyle::addStyle( "#bBlocksSectionHeading-$cId .bBlocksSectionHeading .sectionHeadingSeparator", array( |
| 52 |
$separator['styles'] ?? 'width: 150px; border-top: 3px solid #8344c5;' => '', |
| 53 |
'margin' => $sepMargin['styles'] ?? '0 0 5px 0' |
| 54 |
) ); |
| 55 |
$sectionHeadingStyle::addStyle( "#bBlocksSectionHeading-$cId .bBlocksSectionHeading .sectionHeadingDescription", array( |
| 56 |
$descTypo['styles'] ?? 'font-size: 15px;' => '', |
| 57 |
'color' => $descColor, |
| 58 |
'margin' => $descMargin['styles'] ?? '0 0 15px 0' |
| 59 |
) ); |
| 60 |
|
| 61 |
|
| 62 |
ob_start(); ?> |
| 63 |
<div class='wp-block-b-blocks-section-heading <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksSectionHeading-<?php echo esc_attr( $cId ); ?>'> |
| 64 |
<style> |
| 65 |
@import url(<?php echo esc_url( $titleTypo['googleFontLink'] ?? '' ); ?>); |
| 66 |
@import url(<?php echo esc_url( $descTypo['googleFontLink'] ?? '' ); ?>); |
| 67 |
<?php echo wp_kses( $sectionHeadingStyle::renderStyle(), array() ); ?> |
| 68 |
</style> |
| 69 |
|
| 70 |
<div class='bBlocksSectionHeading'> |
| 71 |
<h2 class='sectionHeadingTitle'><?php echo esc_html( $title ); ?></h2> |
| 72 |
<?php echo $isSep ? "<span class='sectionHeadingSeparator'></span>" : ''; ?> |
| 73 |
<?php echo $isDesc ? "<p class='sectionHeadingDescription'>". esc_html( $desc ) ."</p>" : ''; ?> |
| 74 |
</div> |
| 75 |
</div> |
| 76 |
<?php $sectionHeadingStyle::$styles = array(); // Empty styles |
| 77 |
return ob_get_clean(); |
| 78 |
} |
| 79 |
} |
| 80 |
new BBlocksSectionHeading(); |