PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 1.5.2
bBlocks – Essential Gutenberg Blocks & Patterns Collection v1.5.2
2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 All 108 releases
b-blocks / inc / button-group.php

button-group.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 1.5.2, at inc/button-group.php

123 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class BBlocksButtonGroup extends BBlocks{
3 public function __construct(){
4 add_action( 'init', [$this, 'register'] );
5 }
6
7 function register(){
8 $this::registerScripts( 'button-group', array(
9 'render_callback' => [$this, 'render']
10 ) );
11 }
12
13 function render( $attributes ){
14 extract( $attributes );
15 $align = $align ?? '';
16 $cId = $cId ?? '';
17 $width = $width ?? '0px';
18 $btnAlign = $btnAlign ?? 'center';
19 $btnType = $btnType ?? 'fill';
20 $btnTypo = $btnTypo ?? array( 'fontSize' => 16 );
21 $btnPadding = $btnPadding ?? array( 'vertical' => '12px', 'horizontal' => '30px' );
22 $btnOne = $btnOne ?? 'First Button';
23 $btnOneLink = $btnOneLink ?? '#';
24 $btnOneBorder = $btnOneBorder ?? array( 'radius' => '50px' );
25 $btnOneColors = $btnOneColors ?? array( 'color' => '#fff', 'bg' => '#4527a4' );
26 $btnOneHovColors = $btnOneHovColors ?? array( 'color' => '#fff', 'bg' => '#8344c5' );
27 $btnTwo = $btnTwo ?? 'Second Button';
28 $btnTwoLink = $btnTwoLink ?? '#';
29 $btnTwoBorder = $btnTwoBorder ?? array( 'radius' => '50px' );
30 $btnTwoColors = $btnTwoColors ?? array( 'color' => '#fff', 'bg' => '#8344c5' );
31 $btnTwoHovColors = $btnTwoHovColors ?? array( 'color' => '#fff', 'bg' => '#4527a4' );
32 $isSep = $isSep ?? true;
33 $sepType = $sepType ?? 'icon';
34 $sepText = $sepText ?? 'or';
35 $sepTextTypo = $sepTextTypo ?? array( 'fontSize' => 15 );
36 $sepTextColor = $sepTextColor ?? '#333';
37 $sepIcon = $sepIcon ?? array( 'class' => 'fa fa fa-arrows-alt-h', 'fontSize' => 20, 'color' => '#333' );
38 $sepBGColor = $sepBGColor ?? '#fff';
39
40 // Generate Styles
41 $btnBorderRadiusCSS = $btnBorder['radius'] ?? '50px';
42
43 $buttonGroupStyle = new BBlocksStyleGenerator();
44 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId", array(
45 'text-align' => $btnAlign,
46 ) );
47 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup", array(
48 'width' => '0px' !== $width && '0%' !== $width && '0em' !== $width ? $width : 'auto'
49 ) );
50 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .bBlocksBtn", array(
51 'min-width' => '0px' !== $width && '0%' !== $width && '0em' !== $width ? '50%' : 'auto'
52 ) );
53 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .bBlocksBtn a", array(
54 $btnTypo['styles'] ?? 'font-size: 16px;' => '',
55 'padding' => $btnPadding['styles'] ?? '12px 30px',
56 ) );
57
58 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .btnOne", array(
59 $btnOneBorder['styles'] ?? 'border-radius: 50px;' => '',
60 $btnOneColors['styles'] ?? 'color: #fff; background: #4527a4;' => '',
61 'border-radius' => "$btnBorderRadiusCSS 0 0 $btnBorderRadiusCSS"
62 ) );
63 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .btnOne:hover", array(
64 $btnOneHovColors['styles'] ?? 'color: #fff; background: #8344c5;' => ''
65 ) );
66
67 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .btnTwo", array(
68 $btnTwoBorder['styles'] ?? 'border-radius: 50px;' => '',
69 $btnTwoColors['styles'] ?? 'color: #fff; background: #8344c5;' => '',
70 'border-radius' => "0 $btnBorderRadiusCSS $btnBorderRadiusCSS 0"
71 ) );
72 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .btnTwo:hover", array(
73 $btnTwoHovColors['styles'] ?? 'color: #fff; background: #4527a4;' => ''
74 ) );
75
76 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .btnSeparator", array(
77 'width' => 'text' === $sepType ? $sepTextTypo['fontSize'] * 1.75 .'px' : $sepIcon['fontSize'] * 1.65 .'px',
78 'height' => 'text' === $sepType ? $sepTextTypo['fontSize'] * 1.75 .'px' : $sepIcon['fontSize'] * 1.65 .'px',
79 'background-color' => $sepBGColor
80 ) );
81 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .btnSeparator span", array(
82 $sepTextTypo['styles'] ?? 'font-size: 15px;' => '',
83 'color' => $sepTextColor
84 ) );
85 $buttonGroupStyle::addStyle( "#bBlocksButtonGroup-$cId .bBlocksButtonGroup .btnSeparator i", array(
86 $sepIcon['styles'] ?? 'font-size: 20px; color: #333;' => ''
87 ) );
88
89 // Components
90 $sepIconEl = 'icon' === $sepType && $sepIcon['class'] ? "<i class='". $sepIcon['class'] ."'></i>" : '';
91 $sepTextEl = 'text' === $sepType ? "<span>$sepText</span>" : '';
92 $sepContainerEl = $isSep ? "<div class='btnSeparator'>$sepIconEl $sepTextEl</div>" : '';
93
94 ob_start(); ?>
95 <div class='wp-block-b-blocks-button-group <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksButtonGroup-<?php echo esc_attr( $cId ); ?>'>
96 <style>
97 @import url(<?php echo esc_url( $btnTypo['googleFontLink'] ?? '' ); ?>);
98 @import url(<?php echo esc_url( $sepTextTypo['googleFontLink'] ?? '' ); ?>);
99 <?php echo wp_kses( $buttonGroupStyle::renderStyle(), array() ); ?>
100 </style>
101
102 <div class='bBlocksButtonGroup'>
103 <div class='bBlocksBtn firstBtn'>
104 <?php echo $btnOne ? "<a class='btnOne btn-". esc_attr( $btnType ) ."' href='". esc_url( $btnOneLink ) ."'>". wp_kses_post( $btnOne ) ."</a>" : ''; ?>
105
106 <?php echo wp_kses( $sepContainerEl, array(
107 'div' => array( 'class' => array() ),
108 'i' => array( 'class' => array() ),
109 'span' => array()
110 ) ); ?>
111 </div>
112
113 <div class='bBlocksBtn secondBtn'>
114 <?php echo $btnTwo ? "<a class='btnTwo btn-". esc_attr( $btnType ) ."' href='". esc_url( $btnTwoLink ) ."'>". wp_kses_post( $btnTwo ) ."</a>" : ''; ?>
115 </div>
116 </div>
117 </div>
118
119 <?php $buttonGroupStyle::$styles = array(); // Empty styles
120 return ob_get_clean();
121 }
122 }
123 new BBlocksButtonGroup();