BlockGlow — Per-block Custom CSS
BlockGlow adds a ”BlockGlow — Custom CSS” panel to the inspector of every block. Use it to scope custom CSS to a single block instance. The plugin stores CSS in the uploads folder (under uploads/blockglow/) and enqueues the generated CSS file when rendering on the front end. If the uploads directory isn’t writable or file write fails, BlockGlow will fall back to outputting inline styles.
Key features:
- Adds two block attributes to every block:
blockglowCustomCSSandblockglowId. - Inspector panel with a CodeMirror-backed code editor (if WordPress provides it) or a fallback textarea supporting Tab and Shift+Tab outdent.
- Live preview inside the block editor: custom CSS is scoped to the block in the editor so you can see the effect while editing.
- CSS files are saved to
wp-content/uploads/blockglow/blockglow-<id>.cssand enqueued on the front end as a linked stylesheet; files are removed automatically when you clear the Custom CSS field. - Graceful fallback to inline styles when file writing isn’t possible.
How scoping works:
BlockGlow creates a unique blockglowId for each block instance and scopes your CSS with a wrapper selector like:
[data-blockglow-id="bg-xxxxxxx"] { /* your declarations */ }
For convenience you can use & as the wrapper shorthand in the editor. Example:
& .my-class { color: red; }
The plugin will replace & with the wrapper selector for both editor preview and front-end output.
Arbitrary section
Development notes:
- Editor script:
assets/js/blockglow-editor.js— registers attributes, provides the inspector panel and injects editor-scoped styles. - Main plugin file:
blockglow.php— enqueues editor assets and filtersrender_blockto attach per-block CSS files or inline styles. - Upload path:
wp_upload_dir()+/blockglow/. - File writes/deletes: BlockGlow uses the WordPress Filesystem API (WP_Filesystem) when available for compatibility with hosts using FTP/SFTP; when unavailable it will attempt direct writes. Editing capability is required (edit_posts) or operations performed via REST save.
- Per-post bundling: BlockGlow now generates a single stylesheet per post (
blockglow-post-<ID>.css) on post save which contains the combined CSS from all blocks in that post. This reduces HTTP requests and improves performance. - Admin UI: A new submenu under Tools → ”BlockGlow CSS” lists generated files and allows administrators (capability is filterable) to delete them.
- Capability: File generation/deletion is restricted by a filterable capability
blockglow_manage_files_cap(defaultmanage_options). You can change this capability via the filter if you want other roles to manage files. - If you’d like help preparing the plugin for WordPress.org (example
readme.txtadjustments, SVN packaging, or adding screenshots), ping me and I can prepare the required assets and instructions.
Source Code
The plugin includes built/minified assets under assets/dist/ for distribution. The human-readable source for JavaScript is included in the plugin under assets/js/ (e.g. assets/js/blockglow-editor.js and assets/js/blockglow-admin.js). The plugin also contains a package.json and vite.config.js in the plugin root describing how to rebuild these assets locally using npm install and npm run build or npm run watch.
If you need the sources to be hosted externally, provide a URL and I will add it here (for example an upstream GitHub repository).
Installation Notes for WordPress.org
To publish on WordPress.org you will need:
- A fully-formed
readme.txt(this file) using the plugin directory readme format. - Screenshots (1.png, 2.png, etc.) placed in the assets/ directory when committing to SVN, or uploaded via the plugin admin UI after publishing.
- A stable tag or commit to
trunk/in SVN. Typical workflow:- Create a new plugin slug on https://wordpress.org/plugins/ and follow the email to get SVN access.
- Check out the plugin SVN repository, add your plugin files into
trunk/, put screenshots intoassets/, and tag a version. - Commit and wait for the plugin page to become live.
Support
If you find issues or want improvements (for example: limiting who can edit per-block CSS, collecting styles into a single head include, or adding an admin UI to manage generated CSS files), open an issue in the repository or reply here and I will assist.
