# sureforms/0.0.10/modules/gutenberg/classes/class-spec-init-blocks.php

SureForms – Contact Form Builder, AI Forms, Payment Form, Survey &amp; Quiz, version 0.0.10. 145 lines.

- Page: https://pluginprobe.com/plugins/sureforms/0.0.10/code/modules/gutenberg/classes/class-spec-init-blocks.php
- Raw: https://pluginprobe.com/plugins/sureforms/0.0.10/raw/modules/gutenberg/classes/class-spec-init-blocks.php
- Modified: 2024-05-03T15:04:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/sureforms/0.0.10/code/modules/gutenberg/classes/class-spec-init-blocks.php#L10-L20`.

```php
<?php
/**
 * Sureforms Blocks Initializer
 *
 * Enqueue CSS/JS of all the blocks.
 *
 * @since 0.0.1
 * @package Sureforms
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Spec_Init_Blocks.
 *
 * @package Sureforms
 */
class Spec_Init_Blocks {

	/**
	 * Member Variable
	 *
	 * @var instance
	 */
	private static $instance;

	/**
	 * Store Json variable
	 *
	 * @since 0.0.1
	 * @var instance
	 */
	public static $icon_json;

	/**
	 * As our svg icon is too long array so we will divide that into number of icon chunks.
	 *
	 * @var int
	 * @since 0.0.1
	 */
	public static $number_of_icon_chunks = 4;

	/**
	 *  Initiator
	 */
	public static function get_instance() {
		if ( ! isset( self::$instance ) ) {
			self::$instance = new self();
		}
		return self::$instance;
	}

	/**
	 * Constructor
	 */
	public function __construct() {

		// Hook: Frontend assets.
		add_action( 'enqueue_block_assets', [ $this, 'block_assets' ] );

		// Hook: Editor assets.
		add_action( 'enqueue_block_editor_assets', [ $this, 'editor_assets' ] );

	}

	/**
	 * Enqueue Gutenberg block assets for both frontend + backend.
	 *
	 * @since 0.0.1
	 */
	public function block_assets() {

		global $post;

			// Register block styles for both frontend + backend.
			wp_enqueue_style(
				'srfm-block-style-css', // Handle.
				SRFM_URL . 'modules/gutenberg/build/style-blocks.css',
				is_admin() ? [ 'wp-editor' ] : null, // Dependency to include the CSS after it.
				SRFM_VER // filemtime( plugin_dir_path( __DIR__ ) . 'build/style-blocks.css' ) // Version: File modification time.
			);

	}

	/**
	 * Enqueue assets for both backend.
	 *
	 * @since 0.0.1
	 */
	public function editor_assets() {

		$post_id   = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$post_type = get_post_type( $post_id );

		if ( SRFM_FORMS_POST_TYPE === $post_type ) {

			$script_dep_path = SRFM_DIR . 'modules/gutenberg/build/blocks.asset.php';
			$script_info     = file_exists( $script_dep_path )
				? include $script_dep_path
				: [
					'dependencies' => [],
					'version'      => SRFM_VER,
				];
			$script_dep      = array_merge( $script_info['dependencies'], [ 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ] );
			$script_ver      = $script_info['version'];

			// Register block editor script for backend.
			wp_enqueue_script(
				'srfm-spec-block-js', // Handle.
				SRFM_URL . 'modules/gutenberg/build/blocks.js',
				$script_dep, // Dependencies, defined above.
				$script_ver, // Version: filemtime — Gets file modification time.
				true // Enqueue the script in the footer.
			);

			wp_set_script_translations( 'srfm-spec-block-js', 'sureforms' );

			// Register block editor styles for backend.
			wp_enqueue_style(
				'srfm-block-block-editor-css', // Handle.
				SRFM_URL . 'modules/gutenberg/build/blocks.style.css',
				[ 'wp-edit-blocks' ], // Dependency to include the CSS after it.
				SRFM_VER // Version: File modification time.
			);

			// Common Editor style.
			wp_enqueue_style(
				'srfm-block-common-editor-css', // Handle.
				SRFM_URL . 'modules/gutenberg/dist/editor.css',
				[ 'wp-edit-blocks' ], // Dependency to include the CSS after it.
				SRFM_VER // Version: File modification time.
			);

		}
	}
}

/**
 *  Prepare if class 'Spec_Init_Blocks' exist.
 *  Kicking this off by calling 'get_instance()' method
 */
Spec_Init_Blocks::get_instance();

```
