PluginProbe
Services Section Block – present your services in clean grids and columns / 1.2.1
Services Section Block – present your services in clean grids and columns v1.2.1
1.4.6 1.4.5 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 trunk 1.0 1.1 1.1.1 All 33 releases
services-section / plugin.php

plugin.php in Services Section Block – present your services in clean grids and columns 1.2.1, at plugin.php

182 lines 10.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Services Section
4 * Description: Use Services Section Block to provide services of your business to clients with customizable settings.
5 * Version: 1.2.1
6 * Author: bPlugins LLC
7 * Author URI: http://bplugins.com
8 * License: GPLv3
9 * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
10 * Text Domain: services-section
11 */
12
13 // ABS PATH
14 if ( !defined( 'ABSPATH' ) ) { exit; }
15
16 // Constant
17 define( 'SSB_PLUGIN_VERSION', 'localhost' === $_SERVER['HTTP_HOST'] ? time() : '1.2.1' );
18 define( 'SSB_ASSETS_DIR', plugin_dir_url( __FILE__ ) . 'assets/' );
19
20 // Generate Styles
21 class SSBStyleGenerator {
22 public static $styles = [];
23 public static function addStyle( $selector, $styles ){
24 if( array_key_exists( $selector, self::$styles ) ){
25 self::$styles[$selector] = wp_parse_args( self::$styles[$selector], $styles );
26 }else { self::$styles[$selector] = $styles; }
27 }
28 public static function renderStyle(){
29 $output = '';
30 foreach( self::$styles as $selector => $style ){
31 $new = '';
32 foreach( $style as $property => $value ){
33 if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; }
34 }
35 $output .= "$selector { $new }";
36 }
37 return $output;
38 }
39 }
40
41 // Services Section Block
42 class ServicesSectionBlock{
43 protected static $_instance = null;
44
45 function __construct(){
46 add_action( 'enqueue_block_assets', [$this, 'enqueue_block_assets'] );
47 add_action( 'init', [$this, 'register'] );
48 }
49
50 public static function instance(){
51 if( self::$_instance === null ){
52 self::$_instance = new self();
53 }
54 return self::$_instance;
55 }
56
57 function enqueue_block_assets(){ wp_enqueue_script( 'font-awesome-kit', SSB_ASSETS_DIR . 'js/font-awesome-kit.js', array(), SSB_PLUGIN_VERSION, true ); }
58
59 function register_script( $block, $options = array() ){
60 register_block_type( 'services-section/' . $block, array_merge( array(
61 'editor_script' => 'ssb_editor_script',
62 'editor_style' => 'ssb_editor_style',
63 'script' => 'ssb_script',
64 'style' => 'ssb_style',
65 ), $options ) );
66 } // Register Script
67
68 function register(){
69 wp_register_script( 'ssb_editor_script', plugins_url( 'dist/editor.js', __FILE__ ), array( 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n', 'wp-rich-text' ), SSB_PLUGIN_VERSION, false ); // Backend Script
70 wp_register_style( 'ssb_editor_style', plugins_url( 'dist/editor.css', __FILE__ ), array( 'wp-edit-blocks' ), SSB_PLUGIN_VERSION ); // Backend Style
71 wp_register_script( 'ssb_script', plugins_url( 'dist/script.js', __FILE__ ), array( 'jquery' ), SSB_PLUGIN_VERSION, true ); // Frontend Script
72 wp_register_style( 'ssb_style', plugins_url( 'dist/style.css', __FILE__ ), array( 'wp-editor' ), SSB_PLUGIN_VERSION ); // Frontend Style
73
74 $this->register_script( 'services', array( 'render_callback' => [$this, 'render_services'] ) );
75 $this->register_script( 'service', array( 'render_callback' => [$this, 'render_service'] ) );
76
77 wp_set_script_translations( 'ssb_editor_script', 'services-section', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate
78 } // Register
79
80 function render_services( $attributes, $content ){
81 extract( $attributes );
82 $align = $align ?? '';
83 $cId = $cId ?? '';
84 $layout = $layout ?? 'default';
85 $columns = $columns ?? array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 );
86 $columnGap = $columnGap ?? '30px';
87 $rowGap = $rowGap ?? '30px';
88 $background = $background ?? '#0000';
89 $textAlign = $textAlign ?? 'left';
90 $itemHeight = $itemHeight ?? '375px';
91 $itemPadding = $itemPadding ?? array( 'top' => '50px', 'right' => '30px', 'bottom' => '50px', 'left' => '50px' );
92 $itemShadow = $itemShadow ?? array( 'blur' => '20px', 'color' => '#0000001a' );
93 $itemBorder = $itemBorder ?? array( 'radius' => '15px' );
94 $iconPadding = $iconPadding ?? array( 'bottom' => '10px' );
95 $iconMargin = $iconMargin ?? array( 'bottom' => '20px' );
96 $titleTypo = $titleTypo ?? array( 'fontSize' => 23 );
97 $titleMargin = $titleMargin ?? array( 'bottom' => '30px' );
98 $descTypo = $descTypo ?? array( 'fontSize' => 16 );
99
100 $servicesStyle = new SSBStyleGenerator(); // Generate Styles
101 $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices", array( 'grid-gap' => "$rowGap $columnGap", $background['styles'] ?? 'background-color: #0000;' => '' ) );
102 $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService", array(
103 'text-align' => $textAlign,
104 'min-height' => $itemHeight,
105 'padding' => $itemPadding['styles'] ?? '50px 30px 50px 50px',
106 'box-shadow' => $itemShadow['styles'] ?? '0 0 20px 0 #0000001a',
107 $itemBorder['styles'] ?? 'border-radius: 15px;' => ''
108 ) );
109 $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .bgLayer", array( 'border-radius' => $itemBorder['radius'] ?? '15px' ) );
110 $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .icon", array( 'padding' => $iconPadding['styles'] ?? '0 0 10px 0', 'margin' => $iconMargin['styles'] ?? '0 0 20px 0' ) );
111 $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .title", array( $titleTypo['styles'] ?? 'font-size: 23px' => '', 'margin' => $titleMargin['styles'] ?? '0 0 30px 0' ) );
112 $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .description", array( $descTypo['styles'] ?? 'font-size: 16px' => '' ) );
113
114 $titleFontLink = $titleTypo['googleFontLink'] ?? '';
115 $descFontLink = $descTypo['googleFontLink'] ?? '';
116
117 return "<div class='wp-block-services-section-services ". 'align' . esc_attr( $align ) ."' id='ssbServices-$cId'>
118 <style>@import url( $titleFontLink ); @import url( $descFontLink );". $servicesStyle::renderStyle() ."</style>
119
120 <div class='ssbServices $layout columns-". $columns['desktop'] ." columns-tablet-". $columns['tablet'] ." columns-mobile-". $columns['mobile'] ."'> $content </div>
121 </div>";
122 $servicesStyle::$styles = array(); // Empty styles
123 } // Render Services
124
125 function render_service( $attributes ){
126 extract( $attributes );
127 $cId = $cId ?? '';
128 $background = $background ?? array( 'color' => '#0000' );
129 $hoverBG = $hoverBG ?? array( 'type' => 'image', 'image' => array( 'url' => plugins_url( 'dist/src/img/service-pattern.png', __FILE__ ) ), 'overlayColor' => '#0000', 'position' => 'bottom left', 'size' => 'auto' );
130 $isIcon = $isIcon ?? true;
131 $isUpIcon = $isUpIcon ?? false;
132 $icon = $icon ?? array( 'class' => 'fa fa-wordpress', 'fontSize' => 70 );
133 $upIcon = $upIcon ?? array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' );
134 $iconWidth = $iconWidth ?? '70px';
135 $iconBorder = $iconBorder ?? array();
136 $isTitle = $isTitle ?? true;
137 $title = $title ?? 'Service title';
138 $titleColor = $titleColor ?? '#222';
139 $isDesc = $isDesc ?? true;
140 $desc = $desc ?? 'Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusamus, fuga.';
141 $descColor = $descColor ?? '#333';
142 $isLink = $isLink ?? true;
143 $link = $link ?? '#';
144 $linkIn = $linkIn ?? 'button';
145 $linkIconColor = $linkIconColor ?? '#fff';
146 $linkBGColor = $linkBGColor ?? '#d2d2d2';
147 $linkBGHovColor = $linkBGHovColor ?? '#fe6601';
148
149 $serviceStyle = new SSBStyleGenerator(); // Generate Styles
150 $serviceStyle::addStyle( "#ssbService-$cId .ssbService", array( $background['styles'] ?? 'background-color: #0000;' => '' ) );
151 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .bgLayer", array( $hoverBG['styles'] ?? 'background-image: url( '. plugins_url( 'dist/src/img/service-pattern.png', __FILE__ ) .' ); background-position: bottom left; background-size: auto; background-repeat: no-repeat; background-color: #0000;' => '' ) );
152 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .icon", array( $iconBorder['styles'] ?? '' => '' ) );
153 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .icon i", array( $icon['styles'] ?? 'font-size: 70px;' => '' ) );
154 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .icon img", array( 'width' => $iconWidth ) );
155 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .title", array( 'color' => $titleColor ) );
156 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .description", array( 'color' => $descColor ) );
157 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .link a", array( 'background-color' => $linkBGColor ) );
158 $serviceStyle::addStyle( "#ssbService-$cId:hover .ssbService .link a", array( 'background-color' => $linkBGHovColor ) );
159 $serviceStyle::addStyle( "#ssbService-$cId .ssbService .link a svg", array( 'fill' => $linkIconColor ) );
160
161 ob_start(); ?>
162 <div class='wp-block-services-section-service' id='ssbService-<?php echo esc_attr( $cId ); ?>'>
163 <style><?php echo wp_kses( $serviceStyle::renderStyle(), [] ); ?></style>
164 <div class='ssbService'>
165 <?php echo 'service' === $linkIn ? "<a class='serviceLink' href='". esc_url( $link ) ."'></a>" : ''; ?>
166 <div class='bgLayer'></div>
167 <div class='icon'><?php echo $isUpIcon ? ( isset($upIcon['url'] ) ? "<img src='". esc_url( $upIcon['url'] ) ."' alt='". esc_attr( $upIcon['alt'] ) ."' />" : '' ) : ( isset($icon['class'] ) ? "<i class='". esc_attr( $icon['class'] ) ."'></i>" : '' ); ?></div>
168
169 <?php echo $isTitle ? ( 'title' === $linkIn ? "<a href='". esc_url( $link ) ."'><h3 class='title'>". wp_kses_post( $title ) ."</h3></a>" : "<h3 class='title'>". wp_kses_post( $title ) ."</h3>") : ''; ?>
170
171 <?php echo $isDesc ? "<p class='description'>". wp_kses_post( $desc ) ."</p>" : ''; ?>
172
173 <?php echo $isLink && 'button' === $linkIn ? "<div class='link'><a href='". esc_url( $link ) ."'>
174 <svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 493.356 493.356'><path d='M490.498,239.278l-109.632-99.929c-3.046-2.474-6.376-2.95-9.993-1.427c-3.613,1.525-5.427,4.283-5.427,8.282v63.954H9.136 c-2.666,0-4.856,0.855-6.567,2.568C0.859,214.438,0,216.628,0,219.292v54.816c0,2.663,0.855,4.853,2.568,6.563 c1.715,1.712,3.905,2.567,6.567,2.567h356.313v63.953c0,3.812,1.817,6.57,5.428,8.278c3.62,1.529,6.95,0.951,9.996-1.708 l109.632-101.077c1.903-1.902,2.852-4.182,2.852-6.849C493.356,243.367,492.401,241.181,490.498,239.278z' /></svg>
175 </a></div>" : ''; ?>
176 </div>
177 </div>
178 <?php $serviceStyle::$styles = array(); // Empty styles
179 return ob_get_clean();
180 } // Render Service
181 }
182 ServicesSectionBlock::instance();