> For the complete documentation index, see [llms.txt](https://whoisandywhite.gitbook.io/porterwp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whoisandywhite.gitbook.io/porterwp/features/blocks.md). Agents can also search and read this documentation through its [MCP server](https://whoisandywhite.gitbook.io/porterwp/~gitbook/mcp).

# ACF custom blocks

PorterWP discovers and registers theme-owned ACF blocks beneath the path configured in [`blocks.json`](https://whoisandywhite.gitbook.io/porterwp/getting-started/configuration-files/blocks-json.md). This integration requires premium code and the ACF PRO APIs checked by PorterWP.

If ACF PRO is missing or incomplete, PorterWP leaves its other features running, skips the custom-block subsystem and displays an administrator notice.

Theme `init.php` files can use Porter's metadata, ACF-key, anchor and template-path helpers. See the [Block helper API](https://whoisandywhite.gitbook.io/porterwp/developer-api/block-helper-api.md).

## Block folder

A block created from the public starter commonly looks like this:

```
porter/blocks/components/testimonial/
├── acf-json/           # ACF local JSON for this block
├── block.json          # WordPress/ACF block metadata
├── init.php            # Optional callbacks and asset registration
├── template.php        # Optional theme render template
├── icon.svg            # Optional editor icon
├── css/style.css       # Optional registered block stylesheet
├── js/block.js         # Optional script registered by the theme
└── scss/style.scss     # Optional build source
```

PorterWP requires only `block.json` for registration. `init.php`, templates, source files and asset conventions belong to the block implementation or starter scaffold.

For new work, prefer WordPress block API version 3 and ACF block version 3:

```json
{
  "name": "acf/testimonial",
  "title": "Testimonial",
  "apiVersion": 3,
  "style": "testimonial-block-css",
  "acf": {
    "blockVersion": 3,
    "mode": "preview",
    "renderCallback": "ThemeTestimonial\\pre_render"
  }
}
```

`block.json` determines the render callback and metadata. PorterWP does not automatically call `template.php`; the public starter's optional `init.php` callback does that for scaffolded blocks.

## Discovery and registration

On `init` priority 4, PorterWP:

1. Gets cached block paths in production or scans the configured directories.
2. Applies `porter_blocks_array`, allowing code such as the premium Filters block to add entries.
3. Resolves each theme block against the active stylesheet directory.
4. Calls `register_block_type()` for directories containing `block.json`.
5. Registers `css/style.css`, when present, as `{block-folder}-block-css` using the active theme version.
6. Includes the block's `init.php`, when present.

If `blocks.settings.folders` is empty, the root block directory is scanned. If it is populated, each listed directory is scanned one level deep instead. See [Directory Structure](https://whoisandywhite.gitbook.io/porterwp/getting-started/directory-structure.md).

## ACF local JSON

PorterWP adds each block's `acf-json/` directory to `acf/settings/load_json`.

When ACF saves a field group whose location tree contains a `block == acf/{block-name}` rule, PorterWP directs that JSON save to the matching block's `acf-json/` directory, creating the directory when needed. Other ACF save paths are left unchanged.

## Icons

When non-core block metadata does not already contain an icon, PorterWP looks for `icon.svg` beside `block.json`, minifies it and supplies it as the metadata icon. A bundled default icon is used when the theme block has no icon file.

## Runtime IDs and repeated ACF blocks

PorterWP wraps ACF metadata render callbacks so every frontend ACF block render receives a unique runtime ID. This includes repeated and nested blocks and prevents field data from bleeding between block instances. Admin block attributes are not rewritten.

## Asset versions

* Theme block `css/style.css` registrations use the active theme version.
* Theme scripts registered by `init.php` control their own version.
* PorterWP-owned premium block assets use `PORTER_VERSION` (`1.4.95`) rather than the theme version.

## Scaffolding with `make.sh`

The `_block-base/` template and `make.sh` helper are part of the public PorterWP starter, not the premium plugin ZIP. From `porter/blocks/`, a typical command is:

```bash
bash make.sh testimonial components
```

The current script uses Bash syntax and macOS/BSD `sed -i` behavior. Run it in that environment, or adapt its in-place `sed` calls before using it on Linux. It copies the base, replaces its placeholders and creates an `icon.svg`. Review the generated namespace, block metadata, ACF fields, render callback and asset handles before use.

## Dynamic block styles

Custom styles for `core/query` are injected with rendered output by default because it is dynamic. Add or remove dynamic block names with the `porter_dynamic_blocks` filter:

```php
add_filter( 'porter_dynamic_blocks', function ( array $blocks ): array {
    $blocks[] = 'my/dynamic-block';
    return array_values( array_unique( $blocks ) );
} );
```

Style definitions and file paths are covered in [`blocks.json`](https://whoisandywhite.gitbook.io/porterwp/getting-started/configuration-files/blocks-json.md).
