doubleedesign / comet-plugin-blocks
WordPress plugin implementing the Comet Components library and associated block editor customisations.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:wordpress-plugin
pkg:composer/doubleedesign/comet-plugin-blocks
Requires
This package is auto-updated.
Last update: 2025-12-23 08:07:24 UTC
README
This plugin is a WordPress implementation of the majority of Double-E Design's Comet Components library and standard customisations of the block editor itself. It includes a selection of the components as blocks, as well as some designed for use directly in templates (such as SiteHeader, SiteFooter, and
Menu). The blocks use a combination of attribute controls that leverage the block editor's native control components and Advanced Custom Fields Pro for their content.
If you're reading this from GitHub, you're seeing the mirror of the Comet Components WordPress Block Editor Plugin package that is here for the purposes of publishing to Packagist and installing via Composer.
Development of this project belongs in the main Comet Components monorepo.
Feature support
This plugin is intended for use as the primary block library in a site. In order to ensure a straightforward editing experience for clients, a number of block editor and adjacent core features are either actively disabled (if necessary) or not supported (if they are opt-in). These include:
- Most core blocks are disabled
- Block patterns are disabled in favour of a "Shared content" custom post type which works similarly but has better UX for clients (given how I usually set everything else up)
- Full-site editing (FSE) is not supported.
The plugin is intended to be used with the Comet Canvas (Block Editor Edition) theme as a parent theme. It would be considered a "hybrid" theme in that it uses traditional PHP templates for rendering, but leverages the block editor for content editing (for the post types it is suitable for).
Extending
This block collection can be extended in client sites using site-specific plugins or themes that define their own blocks. The code that disables core blocks does not prevent registration of new blocks (as long as they aren't namespaced with core/), and the block editor customisations can be extended or overridden by enqueuing additional JavaScript in the block editor context.
Developer notes
Local development
When working on this plugin within the monorepo, use composer.local.json so that symlinked local packages are used:
$env:COMPOSER = "composer.local.json"; composer update --prefer-source
If editing the custom attribute controls (React components), ensure you install the JS dependencies:
npm install
You can compile the CustomControlsWrapper using:
npm run build
Custom controls for the block editor
For UX consistency across blocks, custom controls have been created for use in block inspector panels for things like colour and layout options for the custom blocks that support the corresponding attributes. They are "custom" in that they are React components created specifically for attributes defined by the Comet Components block definitions, but they leverage native block editor components where possible to ensure familiar, consistent, well-supported editor UX.
The custom controls are all rendered in one wrapping component, CustomControlsWrapper, which needs to be compiled (Rollup is configured for this) and enqueued in the block editor for the controls to be available.
When making changes to the components, recompile the CustomControlsWrapper using npm run build or use an automatic watcher in PhpStorm to rebuild when any of the files change.
Why ACF Pro for content + Gutenberg-esque attribute controls?
I have found that this combination provides the best editor experience for clients - ACF fields for almost all content ensures a consistent and easy-to-understand content editing experience, while the customised but native attribute controls provide straightforward access to styling and layout options that specific blocks support.
Component defaults
Comet Components blocks that use the custom attribute controls should have a default set in block.json for the controls to work. However, component defaults can also be set in the Comet global config in PHP, allowing different defaults to be set by client themes and plugins. My intention is that the global config will take precedence over block.json when both are set, because this provides the most flexibility. TODO: At the time of writing, this has not been fully implemented yet.
Creating new blocks
To create a new block that corresponds to a Comet component, you need three files:
- A
block.jsonfile that defines the block's metadata, attributes, CSS files, etc. - A
fields.phpfile that defines the ACF fields for the block's content usingacf_add_local_field_group() - A
render.phpfile that contains the PHP rendering logic for the block editor preview and for the front-end.
Refer to the existing blocks in the plugin for examples.
The editor CSS field should reference the Comet Components Core package CSS files. Note that some blocks will also need the CSS of their inner components to be imported as well. Some very common components' CSS such as Container and PageSection are already loaded into the editor by default.
Ideally, additional CSS should not be necessary in the plugin (client themes and plugins can of course add their own custom CSS in the relevant files) because they should be a basic implementation of the core component and nothing more.
Plugin structure
Due to the way that some things for the block editor can be done in PHP and others must be done in JavaScript, some of the code organisation feels a bit unintuitive because there can be code in either language that deals with the same domain. The following table outlines the purpose these pairs of files in this plugin.
| PHP file | JS or other file | Purpose |
|---|---|---|
JavaScriptImplementation.php |
- | Provides an explicit structure for pairing PHP and JS files that do related things, and handles enqueueing of the JS file in the WordPress admin. |
BlockRegistry.php |
block-registry.js |
Manages availability, supported features, styles, and variations for non-Comet blocks. This includes expressly disabling most Core blocks, while ensuring some supported plugin blocks (such as Ninja Forms' form block) remain available. |
|
| BlockEditorConfig.php | block-editor-config.js | Customisations to the organisation of blocks in the editor such as categorisation, labels and descriptions, and restrictions on parent/child block relationships; customisations to the editor itself such as disabling unwanted/unsupported editor features and customising editor behaviour e.g., sidebar/panel appearance. |