Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions includes/class-convertkit-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,7 @@ public function add_blocks() {
}

// Determine the block API version to use for registering blocks.
// WordPress supports Version 3 from WordPress 6.3:
// https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/.
$block_api_version = ( version_compare( get_bloginfo( 'version' ), '6.3', '>=' ) ? 3 : 2 );

/**
* Determine the block API version to use for registering blocks.
*
* @since 3.1.4
*
* @param int $block_api_version Block API version.
* @return int Block API version.
*/
$block_api_version = apply_filters( 'convertkit_gutenberg_block_api_version', $block_api_version );
$block_api_version = $this->get_block_api_version();

// Get registered blocks.
$registered_blocks = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() );
Expand Down Expand Up @@ -199,6 +187,33 @@ public function add_blocks() {

}

/**
* Determines the block API version to use for registering blocks.
*
* @since 3.2.0
*
* @return int Block API version.
*/
public function get_block_api_version() {

// Determine the block API version to use for registering blocks.
// WordPress supports Version 3 from WordPress 6.3:
// https://developer.wordpress.org/block-editor/reference-guides/block-api/block-api-versions/.
$block_api_version = ( version_compare( get_bloginfo( 'version' ), '6.3', '>=' ) ? 3 : 2 );

/**
* Determine the block API version to use for registering blocks.
*
* @since 3.1.4
*
* @param int $block_api_version Block API version.
* @return int Block API version.
*/
$block_api_version = apply_filters( 'convertkit_gutenberg_block_api_version', $block_api_version );

return absint( $block_api_version );

}
/**
* Enqueues scripts for Gutenberg blocks in the editor view.
*
Expand Down Expand Up @@ -229,8 +244,9 @@ public function enqueue_scripts() {
'convertkit-gutenberg',
'convertkit_gutenberg',
array(
'ajaxurl' => rest_url( 'kit/v1/blocks' ),
'get_blocks_nonce' => wp_create_nonce( 'wp_rest' ),
'ajaxurl' => rest_url( 'kit/v1/blocks' ),
'block_api_version' => $this->get_block_api_version(),
'get_blocks_nonce' => wp_create_nonce( 'wp_rest' ),
)
);

Expand Down
1 change: 1 addition & 0 deletions resources/backend/js/gutenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ function convertKitGutenbergRegisterBlock(block) {

// Register Block.
registerBlockType('convertkit/' + block.name, {
apiVersion: convertkit_gutenberg.block_api_version,
title: block.title,
description: block.description,
category: block.category,
Expand Down