Blockstudio
BlocksHooks

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.

functions.php
add_filter('blockstudio/path', function() {
  $path = get_stylesheet_directory() . '/blocks';
  return $path;
});

Init

global

This action fires after the plugin has registered all blocks.

functions.php
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.

functions.php
$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.

functions.php
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.

functions.php
$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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
add_filter('blockstudio/settings/users/ids', function() {
  return [1];
});

users/roles

This filter allows you to enable the editor for specific user roles.

functions.php
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.

functions.php
add_filter('blockstudio/settings/assets/enqueue', function() {
  return false;
});

assets/minify/css

This filter allows you to enable/disable the minification of CSS.

functions.php
add_filter('blockstudio/settings/assets/minify/css', function() {
  return true;
});

assets/minify/js

This filter allows you to enable/disable the minification of JS.

functions.php
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.

functions.php
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.

functions.php
add_filter('blockstudio/settings/assets/process/scss_files', function() {
  return true;
});

tailwind/enabled

This filter allows you to enable/disable Tailwind.

functions.php
add_filter('blockstudio/settings/tailwind/enabled', function() {
  return true;
});

tailwind/config

This filter allows you to add a custom Tailwind CSS configuration.

functions.php
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.

functions.php
add_filter('blockstudio/settings/editor/format_on_save', function() {
  return true;
});

editor/assets

This filter allows you to enqueue additional assets in the editor.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
add_filter('blockstudio/settings/block_editor/css_variables', function() {
  return ['my-stylesheet', 'another-stylesheet'];
});

library

This filter allows you to enable the block library.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
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.

functions.php
add_filter('blockstudio/render', function($content) {
  return $content;
});

This filter allows you to adjust the output of the <head> tag before it is being rendered.

functions.php
add_filter('blockstudio/render/head', function($content) {
  return $content . '<meta name="custom" content="value">';
});

This filter allows you to adjust the output of the </body> before it is being rendered.

functions.php
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.

functions.php
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.

functions.php
add_action('blockstudio/error/exception', function($exception, $context) {
  my_error_tracker($exception);
}, 10, 2);

On this page