A WordPress-centric search engine for devs and theme authors



get_block_editor_server_block_settings ›

Since5.0.0
Deprecatedn/a
get_block_editor_server_block_settings ( No parameters )
Returns:
  • (array) An associative array of registered block data.
Defined at:
Codex:

Prepares server-registered blocks for the block editor.

Returns an associative array of registered block data keyed by block name. Data includes properties of a block relevant for client registration.


Source

function get_block_editor_server_block_settings() {
	$block_registry = WP_Block_Type_Registry::get_instance();
	$blocks         = array();
	$fields_to_pick = array(
		'title'            => 'title',
		'description'      => 'description',
		'icon'             => 'icon',
		'category'         => 'category',
		'keywords'         => 'keywords',
		'parent'           => 'parent',
		'supports'         => 'supports',
		'attributes'       => 'attributes',
		'provides_context' => 'providesContext',
		'uses_context'     => 'usesContext',
		'styles'           => 'styles',
		'textdomain'       => 'textdomain',
		'example'          => 'example',
	);

	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
		foreach ( $fields_to_pick as $field => $key ) {
			if ( ! isset( $block_type->{ $field } ) ) {
				continue;
			}

			if ( ! isset( $blocks[ $block_name ] ) ) {
				$blocks[ $block_name ] = array();
			}

			$blocks[ $block_name ][ $key ] = $block_type->{ $field };
		}
	}

	return $blocks;
}