| 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.6 |
| 6 |
* Author: bPlugins LLC |
| 7 |
* Author URI: http://bplugins.com |
| 8 |
* License: GPLv3 |
| 9 |
* License URI: https://www.gnu.org/licenses/gpl-3.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.6' ); |
| 18 |
define( 'SSB_ASSETS_DIR', plugin_dir_url( __FILE__ ) . 'assets/' ); |
| 19 |
define( 'SSB_SERVICE_PATTERN', plugins_url( 'dist/src/img/service-pattern.png', __FILE__ ) ); |
| 20 |
|
| 21 |
// Generate Styles |
| 22 |
class SSBStyleGenerator { |
| 23 |
public static $styles = []; |
| 24 |
public static function addStyle( $selector, $styles ){ |
| 25 |
if( array_key_exists( $selector, self::$styles ) ){ |
| 26 |
self::$styles[$selector] = wp_parse_args( self::$styles[$selector], $styles ); |
| 27 |
}else { self::$styles[$selector] = $styles; } |
| 28 |
} |
| 29 |
public static function renderStyle(){ |
| 30 |
$output = ''; |
| 31 |
foreach( self::$styles as $selector => $style ){ |
| 32 |
$new = ''; |
| 33 |
foreach( $style as $property => $value ){ |
| 34 |
if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; } |
| 35 |
} |
| 36 |
$output .= "$selector { $new }"; |
| 37 |
} |
| 38 |
return $output; |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
// Services Section Block |
| 43 |
class ServicesSectionBlock{ |
| 44 |
function __construct(){ |
| 45 |
add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); |
| 46 |
add_action( 'init', [$this, 'onInit'] ); |
| 47 |
} |
| 48 |
|
| 49 |
function enqueueBlockAssets(){ wp_enqueue_style( 'fontAwesome', SSB_ASSETS_DIR . 'css/fontAwesome.min.css', [], '5.15.4' ); } |
| 50 |
|
| 51 |
function onInit(){ |
| 52 |
wp_register_style( 'services-section-services-editor-style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], SSB_PLUGIN_VERSION ); // Backend Style |
| 53 |
wp_register_style( 'services-section-services-style', plugins_url( 'dist/style.css', __FILE__ ), [ 'wp-editor' ], SSB_PLUGIN_VERSION ); // Frontend Style |
| 54 |
|
| 55 |
register_block_type( __DIR__, [ |
| 56 |
'editor_style' => 'services-section-services-editor-style', |
| 57 |
'style' => 'services-section-services-style', |
| 58 |
'render_callback' => [$this, 'render_services'] |
| 59 |
] ); // Register Block |
| 60 |
|
| 61 |
wp_set_script_translations( 'services-section-services-editor-script', 'services-section', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate |
| 62 |
} // Register |
| 63 |
|
| 64 |
function render_services( $attributes, $content ){ |
| 65 |
extract( $attributes ); |
| 66 |
|
| 67 |
$servicesStyle = new SSBStyleGenerator(); // Generate Styles |
| 68 |
$servicesStyle::addStyle( "#ssbServices-$cId .ssbServices", [ 'grid-gap' => "$rowGap $columnGap", $background['styles'] ?? 'background-color: #0000;' => '' ] ); |
| 69 |
$servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService", [ |
| 70 |
'text-align' => $textAlign, |
| 71 |
'min-height' => $itemHeight, |
| 72 |
'padding' => $itemPadding['styles'] ?? '50px 30px 50px 50px', |
| 73 |
'box-shadow' => $itemShadow['styles'] ?? '0 0 20px 0 #0000001a', |
| 74 |
$itemBorder['styles'] ?? 'border-radius: 15px;' => '' |
| 75 |
] ); |
| 76 |
$servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .bgLayer", [ 'border-radius' => $itemBorder['radius'] ?? '15px' ] ); |
| 77 |
$servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .icon", [ 'padding' => $iconPadding['styles'] ?? '0 0 10px 0', 'margin' => $iconMargin['styles'] ?? '0 0 20px 0' ] ); |
| 78 |
$servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .title", [ $titleTypo['styles'] ?? 'font-size: 23px' => '', 'margin' => $titleMargin['styles'] ?? '0 0 30px 0' ] ); |
| 79 |
$servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .description", [ $descTypo['styles'] ?? 'font-size: 16px' => '' ] ); |
| 80 |
|
| 81 |
$titleFontLink = $titleTypo['googleFontLink'] ?? ''; |
| 82 |
$descFontLink = $descTypo['googleFontLink'] ?? ''; |
| 83 |
|
| 84 |
return "<div class='wp-block-services-section-services align" . esc_attr( $align ) ."' id='ssbServices-$cId'> |
| 85 |
<style>@import url( $titleFontLink ); @import url( $descFontLink );". $servicesStyle::renderStyle() ."</style> |
| 86 |
|
| 87 |
<div class='ssbServices $layout columns-". $columns['desktop'] ." columns-tablet-". $columns['tablet'] ." columns-mobile-". $columns['mobile'] ."'> $content </div> |
| 88 |
</div>"; |
| 89 |
$servicesStyle::$styles = []; // Empty styles |
| 90 |
} // Render Services |
| 91 |
} |
| 92 |
new ServicesSectionBlock; |
| 93 |
|
| 94 |
// Require files |
| 95 |
require_once plugin_dir_path( __FILE__ ) . 'child/child.php'; |