@@ -149,19 +149,7 @@ public function add_blocks() {
149149 }
150150
151151 // Determine the block API version to use for registering blocks.
152- // WordPress supports Version 3 from WordPress 6.3:
153- // https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/.
154- $ block_api_version = ( version_compare ( get_bloginfo ( 'version ' ), '6.3 ' , '>= ' ) ? 3 : 2 );
155-
156- /**
157- * Determine the block API version to use for registering blocks.
158- *
159- * @since 3.1.4
160- *
161- * @param int $block_api_version Block API version.
162- * @return int Block API version.
163- */
164- $ block_api_version = apply_filters ( 'convertkit_gutenberg_block_api_version ' , $ block_api_version );
152+ $ block_api_version = $ this ->get_block_api_version ();
165153
166154 // Get registered blocks.
167155 $ registered_blocks = array_keys ( WP_Block_Type_Registry::get_instance ()->get_all_registered () );
@@ -199,6 +187,33 @@ public function add_blocks() {
199187
200188 }
201189
190+ /**
191+ * Determines the block API version to use for registering blocks.
192+ *
193+ * @since 3.2.0
194+ *
195+ * @return int Block API version.
196+ */
197+ public function get_block_api_version () {
198+
199+ // Determine the block API version to use for registering blocks.
200+ // WordPress supports Version 3 from WordPress 6.3:
201+ // https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/.
202+ $ block_api_version = ( version_compare ( get_bloginfo ( 'version ' ), '6.3 ' , '>= ' ) ? 3 : 2 );
203+
204+ /**
205+ * Determine the block API version to use for registering blocks.
206+ *
207+ * @since 3.1.4
208+ *
209+ * @param int $block_api_version Block API version.
210+ * @return int Block API version.
211+ */
212+ $ block_api_version = apply_filters ( 'convertkit_gutenberg_block_api_version ' , $ block_api_version );
213+
214+ return absint ( $ block_api_version );
215+
216+ }
202217 /**
203218 * Enqueues scripts for Gutenberg blocks in the editor view.
204219 *
@@ -229,8 +244,9 @@ public function enqueue_scripts() {
229244 'convertkit-gutenberg ' ,
230245 'convertkit_gutenberg ' ,
231246 array (
232- 'ajaxurl ' => rest_url ( 'kit/v1/blocks ' ),
233- 'get_blocks_nonce ' => wp_create_nonce ( 'wp_rest ' ),
247+ 'ajaxurl ' => rest_url ( 'kit/v1/blocks ' ),
248+ 'block_api_version ' => $ this ->get_block_api_version (),
249+ 'get_blocks_nonce ' => wp_create_nonce ( 'wp_rest ' ),
234250 )
235251 );
236252
0 commit comments