From fdf8fa62de27243ffa3179cd37ed6b39bdf141dc Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Tue, 12 Mar 2024 12:35:02 +0000 Subject: [PATCH] Fix Code Standards for RC 2 release (#59774) Co-authored-by: getdave Co-authored-by: swissspidy Co-authored-by: youknowriad Co-authored-by: ockham --- .../block-library/src/navigation/index.php | 65 ++++++++++++------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index e3e53ed3bfdb0..f28f017f0238c 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -543,7 +543,7 @@ private static function get_nav_wrapper_attributes( $attributes, $inner_blocks ) /** * Gets the nav element directives. * - * @param bool $is_interactive Whether the block is interactive. + * @param bool $is_interactive Whether the block is interactive. * @return string the directives for the navigation element. */ private static function get_nav_element_directives( $is_interactive ) { @@ -1457,17 +1457,25 @@ function block_core_navigation_set_ignored_hooked_blocks_metadata( $inner_blocks /** * Updates the post meta with the list of ignored hooked blocks when the navigation is created or updated via the REST API. * + * @access private + * @since 6.5.0 + * * @param stdClass $post Post object. + * @return stdClass The updated post object. */ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) { - // We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into - // all anchor blocks. For the root level, we create a mock Navigation and extract them from there. + /* + * We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into + * all anchor blocks. For the root level, we create a mock Navigation and extract them from there. + */ $blocks = parse_blocks( $post->post_content ); - // Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that - // we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be - // used as context for hooked blocks insertion). - // We thus have to look it up from the DB,based on `$post->ID`. + /* + * Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that + * we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be + * used as context for hooked blocks insertion). + * We thus have to look it up from the DB,based on `$post->ID`. + */ $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, get_post( $post->ID ) ); $root_nav_block = parse_blocks( $markup )[0]; @@ -1488,22 +1496,28 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) { return $post; } -// Before adding our filter, we verify if it's already added in Core. -// However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". -// Therefore, we concatenate the Core's function name to circumvent this prefix for our check. -$rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; +/* + * Before adding our filter, we verify if it's already added in Core. + * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". + * Therefore, we concatenate the Core's function name to circumvent this prefix for our check. + */ +$rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found -// Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 -// that are not present in Gutenberg's WP 6.5 compatibility layer. +/* + * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 + * that are not present in Gutenberg's WP 6.5 compatibility layer. + */ if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) { - add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10 ); + add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta' ); } -// Previous versions of Gutenberg and WordPress 6.5 Betas were attaching the block_core_navigation_update_ignore_hooked_blocks_meta -// function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_). -// To avoid collisions, we need to remove the filter from that action if it's present. +/* + * Previous versions of Gutenberg were attaching the block_core_navigation_update_ignore_hooked_blocks_meta + * function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_). + * To avoid collisions, we need to remove the filter from that action if it's present. + */ if ( has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) { - remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback, 10 ); + remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ); } /** @@ -1511,7 +1525,6 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) { * * @param WP_REST_Response $response The response object. * @param WP_Post $post Post object. - * @param WP_REST_Request $request Request object. * @return WP_REST_Response The response object. */ function block_core_navigation_insert_hooked_blocks_into_rest_response( $response, $post ) { @@ -1530,13 +1543,17 @@ function block_core_navigation_insert_hooked_blocks_into_rest_response( $respons return $response; } -// Before adding our filter, we verify if it's already added in Core. -// However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". -// Therefore, we concatenate the Core's function name to circumvent this prefix for our check. +/* + * Before adding our filter, we verify if it's already added in Core. + * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_". + * Therefore, we concatenate the Core's function name to circumvent this prefix for our check. + */ $rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_hooked_blocks_into_rest_response'; -// Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 -// that are not present in Gutenberg's WP 6.5 compatibility layer. +/* + * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5 + * that are not present in Gutenberg's WP 6.5 compatibility layer. + */ if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) { add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 ); }