Hooks - PHP

Last modified:

Below you'll find a list of all available PHP hooks which can be used to extend or adjust the functionality of the plugin.

Assets

assets

This filter disables automatic asset enqueuing.

functions.php

                add_filter('blockstudio/assets', '__return_false');

        
Copy

Blocks

blocks/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 ($block) {
      if (strpos($block->name, 'marketing') === 0) {
        $block->blockstudio['icon'] = '<svg></svg>';
      }

      return $block;
    });

        
Copy

The above code would change the icon of all blocks starting with marketing.

blocks/conditions

This filter allows you to add custom conditions which can be used within blocks.

functions.php

                add_filter('blockstudio/blocks/conditions', function () {
      return ['purchasedProduct' => userHasPurchasedProduct()];
    });

        
Copy

blocks/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 ($attribute, $block) {
        if (isset($attribute["id"]) && $attribute["id"] === "lineNumbers") {
          $attribute["default"] = true;
          $attribute["conditions"] = [
            [
              [
                "id" => "language",
                "operator" => "==",
                "value" => "css",
              ],
            ],
          ];
        }

        return $attribute;
      },
      10,
      2
    );

        
Copy

blocks/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 ($value, $key, $block) {
        if (
          $key === "copyButton" &&
          $block["name"] === "blockstudio-element/code"
        ) {
          $value = true;
        }

        return $value;
      },
      10,
      3
    );

        
Copy

blocks/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 () {
      return [
        "customData" => [
          [
            "value" => "custom-1",
            "label" => "Custom 1",
          ],
          [
            "value" => "custom-2",
            "label" => "Custom 2",
          ],
          [
            "value" => "custom-3",
            "label" => "Custom 3",
            ],
          ],
        ];
      ]);
    });

        
Copy

blocks/components/innerblocks/frontend/wrap

This filter allows you to remove the InnerBlocks wrapper from the frontend.

functions.php

                add_filter(
      "blockstudio/blocks/components/innerblocks/frontend/wrap",
      function ($render, $block) {
        if ($block->name === "blockstudio/my-block") {
          $render = false;
        }

        return $render;
        },
      10,
      2
    );

        
Copy

Editor

editor/users

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

functions.php

                add_filter('blockstudio/editor/users', function () {
      return [1, 19];
    });

        
Copy

editor/users/roles

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

functions.php

                add_filter('blockstudio/editor/users/roles', function () {
      return ['administrator', 'editor'];
    });

        
Copy

editor/assets

This filter allows you to add custom assets to the editor. Please note that this only works for assets that have been registered using admin_enqueue_scripts.

functions.php

                add_filter('blockstudio/editor/assets', function () {
      return ['stylesheet-handle'];
    });

        
Copy

editor/markup

This filter allows you to add custom markup to the editor document. It will be added to the end before the closing of the body tag.

functions.php

                add_filter('blockstudio/editor/markup', function () use ($style) {
      echo '<style>body { background: black; }</style>';
    });

        
Copy

editor/options

This filter allows you to activate editor related options.

functions.php

                add_filter('blockstudio/editor/options', function () {
      return [
        "formatOnSave"     => true,
        "processorScss"    => true,
        "processorEsbuild" => true,
      ];
    });

        
Copy

Library

library

This filter allows you to activate the element library.

functions.php

                add_filter('blockstudio/library', '__return_true');

        
Copy
Search