# blockspare/2.6.1/inc/layout/functions.php

BlockSpare – Gutenberg Blocks for News, Magazine, Blog &amp; Business Websites, version 2.6.1. 122 lines.

- Page: https://pluginprobe.com/plugins/blockspare/2.6.1/code/inc/layout/functions.php
- Raw: https://pluginprobe.com/plugins/blockspare/2.6.1/raw/inc/layout/functions.php
- Modified: 2023-05-11T08:51:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/blockspare/2.6.1/code/inc/layout/functions.php#L10-L20`.

```php
<?php
/**
 * Layout block related functions.
 *
 * @package Blockspare
 */

use Blockspare\Layouts\Component_Registry;

/**
 * Registers layout components with the Component Registry
 * for use in the Layouts block.
 *
 * @param array $data The component data.
 *
 * @return bool|WP_Error
 */
function blockspare_register_layout_component( array $data ) {


	$registry = Component_Registry::instance();

	try {
		$registry::add( $data );
		return true;
	} catch ( Exception $exception ) {
		return new WP_Error( esc_html( $exception->getMessage() ) );
	}
}

/**
 * Unregisters the specified layout component from the Component Registry
 * for use in the Layouts block.
 *
 * @return mixed Boolean true if component unregistered. WP_Error object if an error occurs.
 * @param string $type The component type to be unregistered.
 * @param string $key The unique layout key to be unregistered.
 */
function blockspare_unregister_layout_component( $type, $key ) {
	$registry = Component_Registry::instance();
	try {
		$registry::remove( $type, $key );
		return true;
	} catch ( Exception $exception ) {
		return new WP_Error( esc_html( $exception->getMessage() ) );
	}
}

/**
 * Retrieves the specified layout component.
 *
 * @param string $type The layout component type.
 * @param string $key The layout component's unique key.
 *
 * @return mixed|WP_Error
 */
function blockspare_get_layout_component( $type, $key ) {

	if ( empty( $type ) ) {
		return new WP_Error( esc_html__( 'You must supply a type to retrieve a layout component.', 'blockspare' ) );
	}

	if ( empty( $key ) ) {
		return new WP_Error( esc_html__( 'You must supply a key to retrieve a layout component.', 'blockspare' ) );
	}

	$type = sanitize_key( $type );

	$key = sanitize_key( $key );

	$registry = Component_Registry::instance();

	try {
		return $registry::get( $type, $key );
	} catch ( Exception $exception ) {
		return new WP_Error( esc_html( $exception->getMessage() ) );
	}
}

/**
 * Gets the registered layouts.
 *
 * @return array Array of registered layouts.
 */
function blockspare_get_layouts() {
	$registry = Component_Registry::instance();
	return $registry::layouts();
}

/**
 * Gets the registered sections.
 *
 * @return array Array of registered sections.
 */
function blockspare_get_sections() {
	$registry = Component_Registry::instance();
	return $registry::sections();
}


/**
 * Gets the registered blocks.
 *
 * @return array Array of registered blocks.
 */
function blockspare_get_blocks() {
	$registry = Component_Registry::instance();
	return $registry::blocks();
}

/**
 * Gets the registered pages.
 *
 * @return array Array of registered pages.
 */
function blockspare_get_pages() {
	$registry = Component_Registry::instance();
	return $registry::pages();
}



```
