Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

[Unreleased]

### Added
- Support for registering example data for ACF Blocks.

## [1.41.6]

### Added
Expand Down
33 changes: 33 additions & 0 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ class Block implements GroupableInterface {
*/
protected $parent = null;

/**
* An array of example data for the block.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/#example-optional
* @see https://www.advancedcustomfields.com/resources/acf_register_block_type/
*
* @var array
*/
protected $example = [];

/**
* The renderer for this block.
*
Expand Down Expand Up @@ -466,6 +476,16 @@ public function get_styles() : array {
*/
public function set_parent( ?array $parent ) : self {
$this->parent = $parent;
}

/**
* Setter for the block example data.
*
* @param array $example Array of example data.
* @return self
*/
public function set_example( array $example ) : self {
$this->example = $example;

return $this;
}
Expand All @@ -479,6 +499,15 @@ public function get_parent() : ?array {
return $this->parent;
}

/*
* Getter for the example data of the block.
*
* @return array
*/
public function get_example() : array {
return $this->example;
}

/**
* Add a data filtering function for the block
*
Expand Down Expand Up @@ -588,6 +617,10 @@ protected function register_block() {
$args['post_types'] = $post_types;
}

if ( ! empty( $this->get_example() ) ) {
$args['example'] = $this->get_example();
}

// Register the ACF Block.
return \acf_register_block( $args );
}
Expand Down
Loading