Skip to content

General changes to post type registrations and registration of two new invisible patterns #628

@carstingaxion

Description

@carstingaxion

Is your enhancement related to a problem? Please describe.

Gaining for greater flexibility, I'd like us to encourage the Block Hooks API to add all of the GatherPress blocks into templates.
Following on, with what I wrote at #626

Therefore GatherPress registers two invisible block patterns, that are used as template properties of the main post types.

  1. Within my exploration I changed the template property to the following:
'template'     => array(
    // array( 'gatherpress/venue' ),
    array( 'core/pattern', array( 'slug' => 'gatherpress/venue-details' ) ),
),
  1. The called pattern looks like this and will not be visible to the editor at any point:
\register_block_pattern( 'gatherpress/venue-details',
    array(
  	  'title'         => 'Invisible Venue Details Block Pattern', // no i18n needed
  	  'content'       => '', // this will a be hooked ;)
  	  'inserter'      => false,
  	  'source'        => 'plugin',
    )
);
  1. Now any block - inside and outside of the GatherPress plugin - can easily declare:
add_filter( 'hooked_block_types', __NAMESPACE__ . '\\hook_block_into_pattern', 10, 4 );
function hook_block_into_pattern( $hooked_block_types, $relative_position, $anchor_block_type, $context ) {
	if (
		// Conditionally hook the block into the "gatherpress/venue-details" pattern.
		is_array( $context ) &&
		isset( $context[ 'name' ] ) &&
		'gatherpress/venue-details' === $context[ 'name' ]
	) {
		$hooked_block_types[] = 'gatherpress/rsvp';
	}
	return $hooked_block_types;
}
  1. It just gets a little messy when it comes to block variations, that use the Block Bindings API under the hood.

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions