PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / trunk
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz vtrunk
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 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / modules / gutenberg / classes / class-spec-init-blocks.php
sureforms / modules / gutenberg / classes Last commit date
class-spec-block-config.php 2 years ago class-spec-block-helper.php 1 year ago class-spec-block-js.php 2 years ago class-spec-block-loader.php 2 years ago class-spec-filesystem.php 2 months ago class-spec-gb-helper.php 11 months ago class-spec-init-blocks.php 5 months ago class-spec-spectra-compatibility.php 5 months ago
class-spec-init-blocks.php
181 lines
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 add_action( 'enqueue_block_assets', [ $this, 'editor_assets' ] );
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 if ( empty( $post->post_content ) ) {
78 return;
79 }
80
81 // find blocks in post content.
82 $blocks = parse_blocks( $post->post_content );
83
84 if ( empty( $blocks ) && ! is_array( $blocks ) ) {
85 return;
86 }
87
88 $allowed_blocks = [
89 'srfm/form',
90 'srfm/advanced-heading',
91 'srfm/separator',
92 'srfm/image',
93 'srfm/icon',
94 ];
95
96 $has_required_block = false;
97
98 foreach ( $blocks as $block ) {
99
100 if ( $has_required_block ) {
101 break;
102 }
103
104 if ( in_array( $block['blockName'], $allowed_blocks, true ) ) {
105 $has_required_block = true;
106 }
107 }
108
109 if ( ! $has_required_block ) {
110 return;
111 }
112
113 // Register block styles for both frontend + backend.
114 wp_enqueue_style(
115 'srfm-block-style-css', // Handle.
116 SRFM_URL . 'modules/gutenberg/build/style-blocks.css',
117 is_admin() ? [ 'wp-editor' ] : null, // Dependency to include the CSS after it.
118 SRFM_VER // filemtime( plugin_dir_path( __DIR__ ) . 'build/style-blocks.css' ) // Version: File modification time.
119 );
120
121 }
122
123 /**
124 * Enqueue assets for both backend.
125 *
126 * @since 0.0.1
127 */
128 public function editor_assets() {
129
130 $post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
131 $post_type = get_post_type( $post_id );
132
133 if ( SRFM_FORMS_POST_TYPE === $post_type ) {
134
135 $script_dep_path = SRFM_DIR . 'modules/gutenberg/build/blocks.asset.php';
136 $script_info = file_exists( $script_dep_path )
137 ? include $script_dep_path
138 : [
139 'dependencies' => [],
140 'version' => SRFM_VER,
141 ];
142 $script_dep = array_merge( $script_info['dependencies'], [ 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ] );
143 $script_ver = $script_info['version'];
144
145 // Register block editor script for backend.
146 wp_enqueue_script(
147 'srfm-spec-block-js', // Handle.
148 SRFM_URL . 'modules/gutenberg/build/blocks.js',
149 $script_dep, // Dependencies, defined above.
150 $script_ver, // Version: filemtime — Gets file modification time.
151 true // Enqueue the script in the footer.
152 );
153
154 wp_set_script_translations( 'srfm-spec-block-js', 'sureforms' );
155
156 // Register block editor styles for backend.
157 wp_enqueue_style(
158 'srfm-block-block-editor-css', // Handle.
159 SRFM_URL . 'modules/gutenberg/build/blocks.style.css',
160 [ 'wp-edit-blocks' ], // Dependency to include the CSS after it.
161 SRFM_VER // Version: File modification time.
162 );
163
164 // Common Editor style.
165 wp_enqueue_style(
166 'srfm-block-common-editor-css', // Handle.
167 SRFM_URL . 'modules/gutenberg/dist/editor.css',
168 [ 'wp-edit-blocks' ], // Dependency to include the CSS after it.
169 SRFM_VER // Version: File modification time.
170 );
171
172 }
173 }
174 }
175
176 /**
177 * Prepare if class 'Spec_Init_Blocks' exist.
178 * Kicking this off by calling 'get_instance()' method
179 */
180 Spec_Init_Blocks::get_instance();
181