Settings

Last modified:

Blockstudio includes a powerful settings API, that allows setting options via a blockstudio.json file inside your theme folder and/or filters. Additionally, allowed users are able to change the settings visually inside the admin area.

Via

JSON

If a blockstudio.json file is present inside your theme folder, it will be used to set the default options for the current site. A JSON schema is available to validate the file and help with autocompletion when used in an IDE.

The following properties are available.

block.json

            {
      "$schema": "https://app.blockstudio.dev/schema/blockstudio",
      "users": {
        "ids": [],
        "roles": []
      },
      "assets": {
        "enqueue": true,
        "minify": {
            "css": false,
            "js": false
        },
        "process": {
            "scss": false
        }
      },
      "editor": {
        "formatOnSave": false,
        "assets": [],
        "markup": false
      },
      "library": false
    }

      
Copy

Filters

Alternatively you can use the blockstudio/settings/${setting} filter to set options via PHP for more flexibility.

functions.php

            add_filter('blockstudio/settings/assets/enqueue', '__return_false');
    add_filter('blockstudio/settings/editor/formatOnSave', '__return_true');
    add_filter('blockstudio/settings/library', '__return_true');

      
Copy

Options set via the blockstudio/settings/${setting} filter will override the ones set via the blockstudio.json file. Both methods can be used together.

Admin

Allowed users from the blockstudio/settings/users/ids and blockstudio/settings/users/roles filters are able to change the settings visually inside the admin area. If the Save as JSON checkbox is checked, the settings will be saved to the JSON file, otherwise they will be saved to the database into the options table.

Settings set via filters will be grayed out and disabled inside the admin area.

Settings

Users

Settings related to allowed users with access to the settings and editor.

users/ids

List of user IDs with access to the settings and editor.

functions.php

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

      
Copy

users/roles

List of user roles with access to the settings and editor.

functions.php

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

      
Copy

Assets

Settings related to asset management.

assets/enqueue

Enqueue assets in frontend and editor.

functions.php

                                            add_filter('blockstudio/settings/assets/enqueue', function() {
                return true;
              });

      
Copy

assets/minify/css

Minify CSS.

functions.php

                                            add_filter('blockstudio/settings/assets/minify/css', function() {
                return false;
              });

      
Copy

assets/minify/js

Minify JS.

functions.php

                                            add_filter('blockstudio/settings/assets/minify/js', function() {
                return false;
              });

      
Copy

assets/process/scss

Process SCSS in .css files.

functions.php

                                            add_filter('blockstudio/settings/assets/process/scss', function() {
                return false;
              });

      
Copy

assets/process/scssFiles

Process .scss files to CSS.

functions.php

                                            add_filter('blockstudio/settings/assets/process/scssFiles', function() {
                return true;
              });

      
Copy

Editor

Settings related to the editor.

editor/formatOnSave

Format code upon saving.

functions.php

                                            add_filter('blockstudio/settings/editor/formatOnSave', function() {
                return false;
              });

      
Copy

editor/assets

Additional asset IDs to be enqueued.

functions.php

                                                      add_filter('blockstudio/settings/editor/assets', function() {
                return ["my-stylesheet","another-stylesheet"];
              });

      
Copy

editor/markup

Additional markup to be added to the end of the editor.

functions.php

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

      
Copy

Library

Add block library.

functions.php

                                            add_filter('blockstudio/settings/library', function() {
                return false;
              });

      
Copy

🍪 This website uses cookies to ensure you get the best experience on our website.

Accept Decline