$style ){ $new = ''; foreach( $style as $property => $value ){ if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; } } $output .= "$selector { $new }"; } return $output; } } // Services Section Block class ServicesSectionBlock{ function __construct(){ add_action( 'enqueue_block_assets', [$this, 'enqueueBlockAssets'] ); add_action( 'init', [$this, 'onInit'] ); } function enqueueBlockAssets(){ wp_enqueue_style( 'fontAwesome', SSB_ASSETS_DIR . 'css/fontAwesome.min.css', [], '5.15.4' ); } function onInit(){ wp_register_style( 'services-section-services-editor-style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], SSB_PLUGIN_VERSION ); // Backend Style wp_register_style( 'services-section-services-style', plugins_url( 'dist/style.css', __FILE__ ), [ 'wp-editor' ], SSB_PLUGIN_VERSION ); // Frontend Style register_block_type( __DIR__, [ 'editor_style' => 'services-section-services-editor-style', 'style' => 'services-section-services-style', 'render_callback' => [$this, 'render_services'] ] ); // Register Block wp_set_script_translations( 'services-section-services-editor-script', 'services-section', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate } // Register function render_services( $attributes, $content ){ extract( $attributes ); $servicesStyle = new SSBStyleGenerator(); // Generate Styles $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices", [ 'grid-gap' => "$rowGap $columnGap", $background['styles'] ?? 'background-color: #0000;' => '' ] ); $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService", [ 'text-align' => $textAlign, 'min-height' => $itemHeight, 'padding' => $itemPadding['styles'] ?? '50px 30px 50px 50px', 'box-shadow' => $itemShadow['styles'] ?? '0 0 20px 0 #0000001a', $itemBorder['styles'] ?? 'border-radius: 15px;' => '' ] ); $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .bgLayer", [ 'border-radius' => $itemBorder['radius'] ?? '15px' ] ); $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .icon", [ 'padding' => $iconPadding['styles'] ?? '0 0 10px 0', 'margin' => $iconMargin['styles'] ?? '0 0 20px 0' ] ); $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .title", [ $titleTypo['styles'] ?? 'font-size: 23px' => '', 'margin' => $titleMargin['styles'] ?? '0 0 30px 0' ] ); $servicesStyle::addStyle( "#ssbServices-$cId .ssbServices .ssbService .description", [ $descTypo['styles'] ?? 'font-size: 16px' => '' ] ); $titleFontLink = $titleTypo['googleFontLink'] ?? ''; $descFontLink = $descTypo['googleFontLink'] ?? ''; return "
$content
"; $servicesStyle::$styles = []; // Empty styles } // Render Services } new ServicesSectionBlock; // Require files require_once plugin_dir_path( __FILE__ ) . 'child/child.php';