Using WordPress ‘get_block_editor_server_block_settings()’ PHP function

The get_block_editor_server_block_settings WordPress PHP function prepares server-registered blocks for the block editor.

Usage

$block_settings = get_block_editor_server_block_settings();

Parameters

  • None

More information

See WordPress Developer Resources: get_block_editor_server_block_settings

Examples

Display registered block settings

This code will display an array of registered block settings for the block editor.

$block_settings = get_block_editor_server_block_settings();
print_r($block_settings);

Check if a specific block is registered

This code checks if a specific block (e.g., ‘core/paragraph’) is registered.

$block_settings = get_block_editor_server_block_settings();

if (isset($block_settings['core/paragraph'])) {
    echo 'The core/paragraph block is registered!';
} else {
    echo 'The core/paragraph block is not registered!';
}

Modify a block setting

This code will modify the ‘supports’ setting of the ‘core/paragraph’ block.

$block_settings = get_block_editor_server_block_settings();

if (isset($block_settings['core/paragraph'])) {
    $block_settings['core/paragraph']['supports']['customClassName'] = false;
}

Add a custom block setting

This code will add a custom setting to the ‘core/paragraph’ block.

$block_settings = get_block_editor_server_block_settings();

if (isset($block_settings['core/paragraph'])) {
    $block_settings['core/paragraph']['customSetting'] = 'My custom setting';
}

Count the number of registered blocks

This code will count and display the total number of registered blocks.

$block_settings = get_block_editor_server_block_settings();
$total_blocks = count($block_settings);
echo "There are {$total_blocks} registered blocks.";