Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Hooks API: Refactor Navigation to account for get_hooked_blocks_by_anchor_block #62658

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

tjcafferkey
Copy link
Contributor

@tjcafferkey tjcafferkey commented Jun 18, 2024

Related WordPress/wordpress-develop#6584

What?

Consolidated our approach to getting hooked blocks which means function signatures have changed for the visitor functions. So checking for the existence of get_hooked_blocks_by_anchor_block before using it.

Why?

Because the function signatures of the visitor functions have now changed.

How?

Use function_exists before executing code that depends on it.

Testing Instructions

Follow the below stops for WordPress 6.5/6.6 to ensure no regressions have been introduced, and then again using latest trunk of wordpress-develop once WordPress/wordpress-develop#6584 has been merged.

  1. Add the below code to your themes functions.php
  2. Load frontend and check the Login/Logout block is an inner block of the core Navigation block and hasn't been added twice.
  3. Load the Header template part in the Site Editor and check that the Login/Logout block is present as an inner block of the core Navigation and hasn't been added twice.
  4. Make customisations to move the block and check it persists between reloads.
  5. Make customisations to remove the block completely and check it persists between reloads.
  6. Remove the PHP code added in step 1, and now add the below JSON to the same blocks block.json file and retest starting from step 2.
function register_logout_block_as_navigation_last_child( $hooked_blocks, $position, $anchor_block, $context ) {
	if ( $anchor_block === 'core/navigation' && $position === 'last_child' ) {
		$hooked_blocks[] = 'core/loginout';
	}

	return $hooked_blocks;
}

add_filter( 'hooked_block_types', 'register_logout_block_as_navigation_last_child', 10, 4 );
"blockHooks": {
	"core/navigation": "lastChild"
}

Copy link

Flaky tests detected in 385d07b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9566832934
📝 Reported issues:

@tjcafferkey tjcafferkey added the [Type] Iteration Scoped iteration of an effort from a tracking issue or overview issue ideally for a major release. label Jun 19, 2024
@tjcafferkey tjcafferkey marked this pull request as ready for review June 19, 2024 07:32
@tjcafferkey tjcafferkey requested a review from ajitbohra as a code owner June 19, 2024 07:32
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: tjcafferkey <tomjcafferkey@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@tjcafferkey tjcafferkey added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Jun 19, 2024
@tjcafferkey tjcafferkey changed the title Block Hooks API: Refactor to account for get_hooked_blocks_by_anchor_block Block Hooks API: Refactor Navigation to account for get_hooked_blocks_by_anchor_block Jun 25, 2024
@gziolo gziolo removed the [Type] Iteration Scoped iteration of an effort from a tracking issue or overview issue ideally for a major release. label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Feature] Block hooks [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants