Blocks

Helpers
in package

Global helper functions

Table of Contents

Methods

add_dynamic_context_to_blocks()  : void
Adds dynamic context to blocks.
get_block_by_name()  : Block|null
Gets the single block instance by block name.
render_blocks()  : mixed
Renders and sanitizes a content string of blocks.
render_blocks_in_post_context()  : mixed
Renders a content string (of blocks) in the context of a post.
render_blocks_with_dynamic_context()  : mixed
Renders blocks with dynamic context.
render_inner_blocks_in_post_context()  : mixed
Renders inner blocks within the context of a post.
set_acf_block_mode()  : mixed
Sets the ACF block mode.
set_default_block_category()  : mixed
Sets the default category for new blocks. Must be called before blocks are initialized.

Methods

add_dynamic_context_to_blocks()

Adds dynamic context to blocks.

public static add_dynamic_context_to_blocks(array<string|int, mixed> &$blocks[, array<string|int, mixed> $dynamic_context = array() ]) : void

This will add an attribute called dynamic_context to all nested blocks.

Parameters
$blocks : array<string|int, mixed>

An array of block structures to add dynamic context to.

$dynamic_context : array<string|int, mixed> = array()

The dynamic context to add to the blocks.

get_block_by_name()

Gets the single block instance by block name.

public static get_block_by_name(string $name) : Block|null
Parameters
$name : string

The block name.

Return values
Block|null

Block instance or null if it cannot be found.

render_blocks()

Renders and sanitizes a content string of blocks.

public static render_blocks(string|array<string|int, mixed> $content) : mixed
Parameters
$content : string|array<string|int, mixed>

$content The content string, or array of block structures.

render_blocks_in_post_context()

Renders a content string (of blocks) in the context of a post.

public static render_blocks_in_post_context(string|array<string|int, mixed> $content, int $post_id) : mixed
Parameters
$content : string|array<string|int, mixed>

The content string, or array of block structures.

$post_id : int

The ID of the context post.

render_blocks_with_dynamic_context()

Renders blocks with dynamic context.

public static render_blocks_with_dynamic_context(array<string|int, mixed> $blocks[, array<string|int, mixed> $dynamic_context = array() ]) : mixed

This will add an attribute called dynamic_context to all nested blocks.

Parameters
$blocks : array<string|int, mixed>

An array of block structures to render.

$dynamic_context : array<string|int, mixed> = array()

The dynamic context to add to the blocks.

render_inner_blocks_in_post_context()

Renders inner blocks within the context of a post.

public static render_inner_blocks_in_post_context(WP_Block $wp_block, int $post_id) : mixed
Parameters
$wp_block : WP_Block

The block whose inner blocks should be rendered. Available within render templates.

$post_id : int

The ID of the context post.

set_acf_block_mode()

Sets the ACF block mode.

public static set_acf_block_mode(string $block_name[, string $mode = 'preview' ]) : mixed
Parameters
$block_name : string

The full block name including vendor prefix.

$mode : string = 'preview'

The ACF block mode.

set_default_block_category()

Sets the default category for new blocks. Must be called before blocks are initialized.

public static set_default_block_category(string $category) : mixed
Parameters
$category : string

The default category for new blocks.


        
On this page

Search results