PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.10
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.10
2.12.8 2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 All 98 releases
sureforms / modules / gutenberg / classes / class-spec-init-blocks.php

class-spec-init-blocks.php in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 0.0.10, at modules/gutenberg/classes/class-spec-init-blocks.php

145 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Sureforms Blocks Initializer
4 *
5 * Enqueue CSS/JS of all the blocks.
6 *
7 * @since 0.0.1
8 * @package Sureforms
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * Spec_Init_Blocks.
17 *
18 * @package Sureforms
19 */
20 class Spec_Init_Blocks {
21
22 /**
23 * Member Variable
24 *
25 * @var instance
26 */
27 private static $instance;
28
29 /**
30 * Store Json variable
31 *
32 * @since 0.0.1
33 * @var instance
34 */
35 public static $icon_json;
36
37 /**
38 * As our svg icon is too long array so we will divide that into number of icon chunks.
39 *
40 * @var int
41 * @since 0.0.1
42 */
43 public static $number_of_icon_chunks = 4;
44
45 /**
46 * Initiator
47 */
48 public static function get_instance() {
49 if ( ! isset( self::$instance ) ) {
50 self::$instance = new self();
51 }
52 return self::$instance;
53 }
54
55 /**
56 * Constructor
57 */
58 public function __construct() {
59
60 // Hook: Frontend assets.
61 add_action( 'enqueue_block_assets', [ $this, 'block_assets' ] );
62
63 // Hook: Editor assets.
64 add_action( 'enqueue_block_editor_assets', [ $this, 'editor_assets' ] );
65
66 }
67
68 /**
69 * Enqueue Gutenberg block assets for both frontend + backend.
70 *
71 * @since 0.0.1
72 */
73 public function block_assets() {
74
75 global $post;
76
77 // Register block styles for both frontend + backend.
78 wp_enqueue_style(
79 'srfm-block-style-css', // Handle.
80 SRFM_URL . 'modules/gutenberg/build/style-blocks.css',
81 is_admin() ? [ 'wp-editor' ] : null, // Dependency to include the CSS after it.
82 SRFM_VER // filemtime( plugin_dir_path( __DIR__ ) . 'build/style-blocks.css' ) // Version: File modification time.
83 );
84
85 }
86
87 /**
88 * Enqueue assets for both backend.
89 *
90 * @since 0.0.1
91 */
92 public function editor_assets() {
93
94 $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
95 $post_type = get_post_type( $post_id );
96
97 if ( SRFM_FORMS_POST_TYPE === $post_type ) {
98
99 $script_dep_path = SRFM_DIR . 'modules/gutenberg/build/blocks.asset.php';
100 $script_info = file_exists( $script_dep_path )
101 ? include $script_dep_path
102 : [
103 'dependencies' => [],
104 'version' => SRFM_VER,
105 ];
106 $script_dep = array_merge( $script_info['dependencies'], [ 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ] );
107 $script_ver = $script_info['version'];
108
109 // Register block editor script for backend.
110 wp_enqueue_script(
111 'srfm-spec-block-js', // Handle.
112 SRFM_URL . 'modules/gutenberg/build/blocks.js',
113 $script_dep, // Dependencies, defined above.
114 $script_ver, // Version: filemtime — Gets file modification time.
115 true // Enqueue the script in the footer.
116 );
117
118 wp_set_script_translations( 'srfm-spec-block-js', 'sureforms' );
119
120 // Register block editor styles for backend.
121 wp_enqueue_style(
122 'srfm-block-block-editor-css', // Handle.
123 SRFM_URL . 'modules/gutenberg/build/blocks.style.css',
124 [ 'wp-edit-blocks' ], // Dependency to include the CSS after it.
125 SRFM_VER // Version: File modification time.
126 );
127
128 // Common Editor style.
129 wp_enqueue_style(
130 'srfm-block-common-editor-css', // Handle.
131 SRFM_URL . 'modules/gutenberg/dist/editor.css',
132 [ 'wp-edit-blocks' ], // Dependency to include the CSS after it.
133 SRFM_VER // Version: File modification time.
134 );
135
136 }
137 }
138 }
139
140 /**
141 * Prepare if class 'Spec_Init_Blocks' exist.
142 * Kicking this off by calling 'get_instance()' method
143 */
144 Spec_Init_Blocks::get_instance();
145