Skip to content

Commit

Permalink
conditional block registration based on ACF activation
Browse files Browse the repository at this point in the history
  • Loading branch information
guzmandrade-wds committed Sep 3, 2023
1 parent 3886135 commit 992f091
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions inc/wpcli/block-starter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ import './style.scss';
import Edit from './edit';
import metadata from './block.json';

/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType( metadata.name, {
...metadata,
import apiFetch from '@wordpress/api-fetch';
const plugins = await apiFetch( { path: '/wp/v2/plugins' } );

const isACFProEnabled = plugins.find(
( plugin ) =>
plugin.plugin === 'advanced-custom-fields-pro/acf' &&
plugin.status === 'active'
);

if ( ! isACFProEnabled ) {
/**
* @see ./edit.js
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
edit: Edit,
} );
registerBlockType( metadata.name, {
...metadata,
/**
* @see ./edit.js
*/
edit: Edit,
} );
}

0 comments on commit 992f091

Please sign in to comment.