Block
in package
Abstract class to extend for each block.
Table of Contents
Properties
- $icon : string
- The blocks icon from dashicons or an inline SVG.
- $instance : Block|null
- Singleton instance of this class.
- $provides_context : bool
- Determines if this block provides any context to children.
Methods
- get_child_block_names() : array<string|int, mixed>|null
- Function for retrieving an array of child block names for a specified parent block.
- get_field() : mixed
- Get a field value from the current block context.
- init() : void
- Set singleton instance of this class.
- category() : string
- Function for providing the block's category.
- child_blocks() : array<string|int, Child_Block>
- Function for providing the child blocks
- default_style() : array<string|int, mixed>
- Provides the capability of defining a default style object.
- description() : string
- Function for providing the block's description to be used within the WordPress UI.
- fields() : array<string|int, mixed>
- Function for providing fields array.
- label() : string
- Function for providing the block's label to be used within the WordPress UI.
- name() : string
- Function for providing the block's name.
- register_acf_block() : void
- Function to register the block with ACF.
- register_acf_fields() : void
- Function to register the block's fields with ACF.
- register_block_type() : void
- Registers the block type using the provided block data.
- register_child_block() : void
- Function for fully registering child blocks.
- setup() : bool
- Function to be overridden for performing block-specific setup actions.
- supports() : array<string|int, mixed>
- Provide additional support options for the block.
- template() : string
- Function for providing a path to the render template.
- __construct() : mixed
- Function for fully registering the block and all associated functionality.
- get_filesystem() : WP_Filesystem_Base
- Attempts to get the WordPress filesystem.
- initialize_traits() : mixed
- Traits within this namespace and used by extensions of this class can declare initialization functions.
Properties
$icon
The blocks icon from dashicons or an inline SVG.
protected
string
$icon
= 'block-default'
Tags
$instance
Singleton instance of this class.
protected
static Block|null
$instance
= null
$provides_context
Determines if this block provides any context to children.
protected
bool
$provides_context
= false
Methods
get_child_block_names()
Function for retrieving an array of child block names for a specified parent block.
public
static get_child_block_names(string $parent_block_name) : array<string|int, mixed>|null
Useful when a parent block should not allow any nested blocks apart from their own child blocks. If this is the case, JSON encode the output this function and echo the result into the allowedBlocks attribute of the InnerBlocks element.
Parameters
- $parent_block_name : string
-
The parent block name.
Return values
array<string|int, mixed>|null —An array of child block names, null if parent or child blocks cannot be found.
get_field()
Get a field value from the current block context.
public
get_field(string $field_name) : mixed
Parameters
- $field_name : string
-
The field name.
Return values
mixed —The field value.
init()
Set singleton instance of this class.
public
static init() : void
category()
Function for providing the block's category.
protected
category() : string
Return values
string —The block's category.
child_blocks()
Function for providing the child blocks
protected
child_blocks() : array<string|int, Child_Block>
Return values
array<string|int, Child_Block> —Array of child blocks.
default_style()
Provides the capability of defining a default style object.
protected
default_style() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>description()
Function for providing the block's description to be used within the WordPress UI.
protected
description() : string
Return values
string —The block's description.
fields()
Function for providing fields array.
protected
fields() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —An array of field definitions in ACF format.
label()
Function for providing the block's label to be used within the WordPress UI.
protected
abstract label() : string
Return values
string —The block's label.
name()
Function for providing the block's name.
protected
abstract name() : string
Return values
string —The block's name (must be hyphen separated).
register_acf_block()
Function to register the block with ACF.
protected
register_acf_block() : void
register_acf_fields()
Function to register the block's fields with ACF.
protected
register_acf_fields() : void
register_block_type()
Registers the block type using the provided block data.
protected
register_block_type(array<string|int, mixed> $block_data) : void
Parameters
- $block_data : array<string|int, mixed>
-
The block data.
Tags
register_child_block()
Function for fully registering child blocks.
protected
register_child_block(string $parent_block, Child_Block $child_block, array<string|int, mixed> $ancestor_blocks) : void
Parameters
- $parent_block : string
-
The parent block name.
- $child_block : Child_Block
-
The child block to register.
- $ancestor_blocks : array<string|int, mixed>
-
An array of all ancestor block names. Must include parent block name.
setup()
Function to be overridden for performing block-specific setup actions.
protected
setup() : bool
Return values
bool —Whether the setup was successful.
supports()
Provide additional support options for the block.
protected
supports() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>template()
Function for providing a path to the render template.
protected
abstract template() : string
Return values
string —The path to the render template.
__construct()
Function for fully registering the block and all associated functionality.
private
__construct() : mixed
get_filesystem()
Attempts to get the WordPress filesystem.
private
get_filesystem() : WP_Filesystem_Base
Return values
WP_Filesystem_Base —The WordPress filesystem.
initialize_traits()
Traits within this namespace and used by extensions of this class can declare initialization functions.
private
initialize_traits() : mixed
These functions should conform to the following naming convention: init_trait_name. This function is responsible for calling the initialization functions.