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);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/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; }';
});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/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'];
});library
This filter allows you to enable the block library.
add_filter('blockstudio/settings/library', function() {
return true;
});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;
});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/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);