PHP Hooks
Below you'll find a list of all available PHP hooks that can be used to extend or adjust the functionality of the plugin.
Path
This filter allows you to adjust the path of the block folder. By default, this
is blockstudio inside the currently active theme. Alternatively it is possible
to create a new instance for multiple
source directories.
add_filter('blockstudio/path', function() {
$path = get_stylesheet_directory() . '/blocks';
return $path;
});Init
global
This action fires after the plugin has registered all blocks.
add_action('blockstudio/init', function($blocks) {
// All blocks have been registered
});instance
This action fires after the plugin has registered all blocks of a specific
instance.
The $instance segment is the instance path relative to wp-content.
$instance = 'themes/my-theme/client-blocks';
add_action("blockstudio/init/$instance", function() {
// All blocks of this instance have been registered
});global/before
This action fires before the plugin has registered all blocks.
add_action('blockstudio/init/before', function() {
// Before blocks are registered
});global/before/$instance
This action fires before the plugin has registered all blocks of a specific instance.
$instance = 'themes/my-theme/client-blocks';
add_action("blockstudio/init/before/$instance", function() {
// Before blocks of this instance are registered
});Blocks
render
This filter allows you to adjust the output of a block before it is rendered.
add_filter('blockstudio/blocks/render', function($content, $block, $attributes) {
// Modify the block content
return $content;
}, 10, 3);meta
This filter allows you to adjust the data of the block.json file before it is registered.
add_filter('blockstudio/blocks/meta', function($meta, $block) {
if (str_starts_with($block['name'], 'marketing')) {
$meta['icon'] = 'megaphone';
}
return $meta;
}, 10, 2);The above code would change the icon of all blocks starting with marketing.
conditions
This filter allows you to add custom conditions which can be used within blocks.
add_filter('blockstudio/blocks/conditions', function($conditions) {
$conditions['myCustomCondition'] = function($condition) {
return $condition['value'] === 'expected';
};
return $conditions;
});attributes
This filter allows you to adjust the attributes of a block before the block is registered. See Filtering for more information.
add_filter('blockstudio/blocks/attributes', function($attributes, $block) {
// Modify attributes before registration
return $attributes;
}, 10, 2);attributes/render
This filter allows you to adjust the attributes of a block before it is rendered. See Filtering for more information.
add_filter('blockstudio/blocks/attributes/render', function($attributes, $block) {
// Modify attributes before rendering
return $attributes;
}, 10, 2);attributes/populate
This filter allows you to add custom data to the options of a checkbox,
select or radio field. See Populating options for more information.
add_filter('blockstudio/blocks/attributes/populate', function($options, $attribute, $block) {
if ($attribute['populate'] === 'myCustomOptions') {
return [
['value' => '1', 'label' => 'Option 1'],
['value' => '2', 'label' => 'Option 2'],
];
}
return $options;
}, 10, 3);components/use_block_props/render
This filter allows you to adjust the output of the useBlockProps content.
add_filter('blockstudio/blocks/components/use_block_props/render', function($props, $block) {
$props['class'] .= ' my-custom-class';
return $props;
}, 10, 2);components/inner_blocks/render
This filter allows you to adjust the output of the <InnerBlocks /> content.
add_filter('blockstudio/blocks/components/inner_blocks/render', function($content, $block) {
return '<div class="inner-wrapper">' . $content . '</div>';
}, 10, 2);components/inner_blocks/frontend/wrap
This filter allows you to remove the <InnerBlocks /> wrapper from the
frontend.
add_filter('blockstudio/blocks/components/inner_blocks/frontend/wrap', function($wrap, $block) {
return false; // Remove wrapper
}, 10, 2);components/rich_text/render
This filter allows you to adjust the output of the <RichText /> content.
add_filter('blockstudio/blocks/components/rich_text/render', function($content, $attribute, $block) {
return wp_kses_post($content);
}, 10, 3);Block Tags
blockstudio/block_tags/tag_aliases
This filter lets you register custom dashed authoring tags that resolve to real block names before raw HTML fallback. It is useful when a theme wants a concise project-specific tag surface while still rendering standard Blockstudio or core blocks.
add_filter('blockstudio/block_tags/tag_aliases', function($aliases) {
$aliases['theme-button'] = 'bsui/button';
$aliases['theme-card'] = 'theme/card';
return $aliases;
});<theme-button href="/download" label="Download" />
<theme-card title="Fast authoring">
<p>Children are parsed as nested blocks.</p>
</theme-card>Settings
path
This filter allows you to adjust the path of the blockstudio.json file. By
default, this is blockstudio.json inside the currently active theme.
add_filter('blockstudio/settings/path', function() {
return get_stylesheet_directory() . '/config/blockstudio.json';
});users/ids
This filter allows you to enable the editor for specific user IDs.
add_filter('blockstudio/settings/users/ids', function() {
return [1];
});users/roles
This filter allows you to enable the editor for specific user roles.
add_filter('blockstudio/settings/users/roles', function() {
return ['administrator', 'editor'];
});assets/enqueue
This filter allows you to enable/disable the enqueueing of assets in frontend and editor.
add_filter('blockstudio/settings/assets/enqueue', function() {
return false;
});assets/reset/enabled
This filter allows you to enable/disable the removal of WordPress core block styles.
add_filter('blockstudio/settings/assets/reset/enabled', function() {
return true;
});assets/reset/full_width
This filter allows you to control which post types use full-width editing.
add_filter('blockstudio/settings/assets/reset/full_width', function() {
return ['page'];
});assets/minify/css
This filter allows you to enable/disable the minification of CSS.
add_filter('blockstudio/settings/assets/minify/css', function() {
return true;
});assets/minify/js
This filter allows you to enable/disable the minification of JS.
add_filter('blockstudio/settings/assets/minify/js', function() {
return true;
});assets/process/scss
This filter allows you to enable/disable the processing of SCSS in .css files.
add_filter('blockstudio/settings/assets/process/scss', function() {
return true;
});assets/process/scss_files
This filter allows you to enable/disable the processing of .scss files to CSS.
add_filter('blockstudio/settings/assets/process/scss_files', function() {
return true;
});tailwind/enabled
This filter allows you to enable/disable Tailwind.
add_filter('blockstudio/settings/tailwind/enabled', function() {
return true;
});tailwind/config
This filter allows you to add a custom Tailwind CSS configuration.
add_filter('blockstudio/settings/tailwind/config', function() {
return '@theme { --color-primary: pink; }';
});ui/enabled
This filter allows you to enable/disable bundled UI components.
add_filter('blockstudio/settings/ui/enabled', function() {
return true;
});editor/format_on_save
This filter allows you to enable/disable the formatting of code upon saving.
add_filter('blockstudio/settings/editor/format_on_save', function() {
return true;
});editor/assets
This filter allows you to enqueue additional assets in the editor.
add_filter('blockstudio/settings/editor/assets', function() {
return ['my-stylesheet', 'another-stylesheet'];
});editor/markup
This filter allows you to add additional markup to the end of the editor.
add_filter('blockstudio/settings/editor/markup', function() {
return '<style>body { background: black; }</style>';
});block_editor/disable_loading
This filter allows you to disable the loading of blocks inside the Block Editor.
add_filter('blockstudio/settings/block_editor/disable_loading', function() {
return true;
});block_editor/enhance
This filter allows you to enable Blockstudio editor affordances such as cleaner focus styles and hover/selection outlines.
add_filter('blockstudio/settings/block_editor/enhance', function() {
return true;
});block_editor/css_classes
This filter allows you to add stylesheets whose classes should be available for choice in the class field.
add_filter('blockstudio/settings/block_editor/css_classes', function() {
return ['my-stylesheet', 'another-stylesheet'];
});block_editor/css_variables
This filter allows you to add stylesheets whose CSS variables should be available for autocompletion in the code field.
add_filter('blockstudio/settings/block_editor/css_variables', function() {
return ['my-stylesheet', 'another-stylesheet'];
});block_editor/blocks/allow
This filter allows you to control the block names that are allowed in the inserter.
add_filter('blockstudio/settings/block_editor/blocks/allow', function() {
return ['core/*', 'acf/*', 'my-theme/*'];
});block_editor/blocks/deny
This filter allows you to remove block names from the inserter.
add_filter('blockstudio/settings/block_editor/blocks/deny', function() {
return ['core/embed', 'core/freeform'];
});block_editor/blocks/directory
This filter allows you to enable or disable the WordPress block directory assets in the editor.
add_filter('blockstudio/settings/block_editor/blocks/directory', function() {
return false;
});block_editor/blocks/categories/allow
This filter allows you to control which block category slugs remain available.
add_filter('blockstudio/settings/block_editor/blocks/categories/allow', function() {
return ['text', 'media', 'design'];
});block_editor/blocks/categories/deny
This filter allows you to remove block category slugs from the inserter.
add_filter('blockstudio/settings/block_editor/blocks/categories/deny', function() {
return ['embed'];
});block_editor/blocks/categories/rename
This filter allows you to rename block category labels by slug.
add_filter('blockstudio/settings/block_editor/blocks/categories/rename', function() {
return [
'text' => 'Writing',
'design' => 'Layout'
];
});block_editor/blocks/categories/order
This filter allows you to order block category slugs in the inserter.
add_filter('blockstudio/settings/block_editor/blocks/categories/order', function() {
return ['my-theme', 'text', 'media'];
});block_editor/blocks/styles/deny
This filter allows you to unregister PHP-registered block styles by block name.
add_filter('blockstudio/settings/block_editor/blocks/styles/deny', function() {
return [
'my-theme/card' => ['outline'],
'my-theme/media' => ['framed']
];
});block_editor/blocks/legacy_widgets/hide
This filter allows you to hide additional legacy widgets from the legacy widget block.
add_filter('blockstudio/settings/block_editor/blocks/legacy_widgets/hide', function() {
return ['archives', 'calendar'];
});block_editor/patterns/core
This filter allows you to enable or disable WordPress core block patterns.
add_filter('blockstudio/settings/block_editor/patterns/core', function() {
return false;
});block_editor/patterns/remote
This filter allows you to enable or disable remote patterns from the WordPress pattern directory.
add_filter('blockstudio/settings/block_editor/patterns/remote', function() {
return false;
});block_editor/patterns/theme
This filter allows you to enable or disable theme-provided block patterns.
add_filter('blockstudio/settings/block_editor/patterns/theme', function() {
return false;
});block_editor/patterns/blockstudio
This filter allows you to enable or disable Blockstudio file-based patterns.
add_filter('blockstudio/settings/block_editor/patterns/blockstudio', function() {
return false;
});block_editor/patterns/categories/allow
This filter allows you to control which pattern category slugs remain available.
add_filter('blockstudio/settings/block_editor/patterns/categories/allow', function() {
return ['featured', 'buttons', 'columns'];
});block_editor/patterns/categories/deny
This filter allows you to remove pattern category slugs from the pattern inserter.
add_filter('blockstudio/settings/block_editor/patterns/categories/deny', function() {
return ['gallery'];
});block_editor/patterns/categories/rename
This filter allows you to rename pattern category labels by slug.
add_filter('blockstudio/settings/block_editor/patterns/categories/rename', function() {
return [
'featured' => 'Featured Layouts'
];
});block_editor/patterns/categories/order
This filter allows you to order pattern category slugs in the inserter.
add_filter('blockstudio/settings/block_editor/patterns/categories/order', function() {
return ['featured', 'buttons'];
});block_editor/media/openverse
This filter allows you to enable or disable the Openverse media category in the block editor media inserter.
add_filter('blockstudio/settings/block_editor/media/openverse', function() {
return false;
});block_editor/media/image_sizes/allow
This filter allows you to control which image size names remain available in editor media controls.
add_filter('blockstudio/settings/block_editor/media/image_sizes/allow', function() {
return ['thumbnail', 'large'];
});block_editor/media/image_sizes/deny
This filter allows you to remove image size names from editor media controls.
add_filter('blockstudio/settings/block_editor/media/image_sizes/deny', function() {
return ['medium_large'];
});ai/enable_context_generation
This filter allows you to enable or disable context file generation for LLM tool integration. When enabled, the context file assembles up-to-date block data, Blockstudio settings of the current install, all relevant schemas, and Blockstudio documentation into a single source for use with AI development tools.
add_filter('blockstudio/settings/ai/enable_context_generation', function() {
return true;
});block_tags/enabled
This filter allows you to enable/disable page-level block tag rendering.
add_filter('blockstudio/settings/block_tags/enabled', function() {
return true;
});dev/grab/enabled
This filter allows you to enable/disable the element grabber.
add_filter('blockstudio/settings/dev/grab/enabled', function() {
return false;
});dev/perf
This filter allows you to enable/disable the performance profiler.
add_filter('blockstudio/settings/dev/perf', function() {
return false;
});dev/canvas/enabled
This filter allows you to enable/disable the canvas.
add_filter('blockstudio/settings/dev/canvas/enabled', function() {
return false;
});dev/canvas/admin_bar
This filter allows you to show/hide the WordPress admin bar on the canvas.
add_filter('blockstudio/settings/dev/canvas/admin_bar', function() {
return true;
});Admin
enabled
This filter allows you to enable or disable the Blockstudio admin page under Tools > Blockstudio.
add_filter('blockstudio/admin/enabled', function() {
return false;
});Assets
enable
This filter allows you to disable the asset processing and enqueueing of a specific asset type.
add_filter('blockstudio/assets/enable', function($enable, $type, $block) {
if ($type === 'css' && $block['name'] === 'my/block') {
return false;
}
return $enable;
}, 10, 3);disable
This filter allows you to disable specific assets by their ID. Assets matching an ID in the returned array will not be rendered on the frontend.
add_filter('blockstudio/assets/disable', function($disabled) {
$disabled[] = 'my-block-style';
return $disabled;
});process/scss/import_paths
This filter allows you to add additional paths to the @import statement of the
SCSS compiler.
add_filter('blockstudio/assets/process/scss/import_paths', function($paths) {
$paths[] = get_stylesheet_directory() . '/scss';
return $paths;
});process/scss/prelude
This filter allows you to prepend shared Sass code before each SCSS file is compiled.
add_filter('blockstudio/assets/process/scss/prelude', function($prelude, $path, $scss) {
return '@import "functions";' . "\n"
. '@import "variables";' . "\n"
. '@import "mixins";';
}, 10, 3);process/css/content
This filter allows you to adjust the content of the CSS file before it is being compiled.
add_filter('blockstudio/assets/process/css/content', function($content, $block) {
return str_replace('old-class', 'new-class', $content);
}, 10, 2);process/js/content
This filter allows you to adjust the content of the JS file before it is being compiled.
add_filter('blockstudio/assets/process/js/content', function($content, $block) {
return $content;
}, 10, 2);Render
global
This filter allows you to adjust the output of the page before it is being rendered.
add_filter('blockstudio/render', function($content) {
return $content;
});head
This filter allows you to adjust the output of the <head> tag before it is
being rendered.
add_filter('blockstudio/render/head', function($content) {
return $content . '<meta name="custom" content="value">';
});footer
This filter allows you to adjust the output of the </body> before it is being
rendered.
add_filter('blockstudio/render/footer', function($content) {
return $content . '<script>console.log("loaded")</script>';
});Error Handling
error/logged
Action fired after an error is logged. Use this to send errors to external logging services.
add_action('blockstudio/error/logged', function($message, $level, $context) {
if ($level === 'error') {
my_external_logger($message, $context);
}
}, 10, 3);error/exception
Action fired after an exception is handled.
add_action('blockstudio/error/exception', function($exception, $context) {
my_error_tracker($exception);
}, 10, 2);Database
All database hooks receive a single $params array.
db/before_create
Action fired before a record is created.
add_action('blockstudio/db/before_create', function($params) {
// $params: block, schema, data, storage
});db/after_create
Action fired after a record is created.
add_action('blockstudio/db/after_create', function($params) {
// $params: block, schema, record, storage
wp_mail($params['record']['email'], 'Welcome!', 'Thanks for subscribing.');
});db/before_update
Action fired before a record is updated.
add_action('blockstudio/db/before_update', function($params) {
// $params: block, schema, id, data, storage
});db/after_update
Action fired after a record is updated.
add_action('blockstudio/db/after_update', function($params) {
// $params: block, schema, id, record, storage
});db/before_delete
Action fired before a record is deleted.
add_action('blockstudio/db/before_delete', function($params) {
// $params: block, schema, id, storage
});db/after_delete
Action fired after a record is deleted.
add_action('blockstudio/db/after_delete', function($params) {
// $params: block, schema, id, storage
});RPC
All RPC hooks receive a single $params array.
rpc/before_call
Action fired before an RPC function is called.
add_action('blockstudio/rpc/before_call', function($params) {
// $params: block, function, params
});rpc/after_call
Action fired after an RPC function is called.
add_action('blockstudio/rpc/after_call', function($params) {
// $params: block, function, params, result
});