From fec43e7aa1a21b71c0c9521b99f0e976414d04be Mon Sep 17 00:00:00 2001 From: mreishus Date: Wed, 4 Dec 2024 20:45:04 +0000 Subject: [PATCH] register_block_metadata_collection: Silence path validation notices (#40450) Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12167771840 Upstream-Ref: Automattic/jetpack@849ac7b9d42813a57d41a5c52299f5b27dfbe25d --- CHANGELOG.md | 1 + class.jetpack-gutenberg.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0646d7c5b1..dc1e689862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This is an alpha version! The changes listed here are not final. - AI Assistant: Add feature flag for AI feedback feature - External media: Add logic to persist session in cookie - Jetpack AI: remove dead and deprecated code +- register_block_metadata_collection: Silence path validation notices - Testing: Remove old instructions. - Updated package dependencies. diff --git a/class.jetpack-gutenberg.php b/class.jetpack-gutenberg.php index e591673fc0..abc5cdf211 100644 --- a/class.jetpack-gutenberg.php +++ b/class.jetpack-gutenberg.php @@ -1332,6 +1332,32 @@ public static function site_supports_next_default_size() { return false; } + /** + * Temporarily bypasses _doing_it_wrong() notices for block metadata collection registration. + * + * WordPress 6.7 introduced block metadata collections (with strict path validation). + * Any sites using symlinks for plugins will fail the validation which causes the metadata + * collection to not be registered. However, the blocks will still fall back to the regular + * registration and no functionality is affected. + * While this validation is being discussed in WordPress Core (#62140), + * this method allows registration to proceed by temporarily disabling + * the relevant notice. + * + * @since 14.2-a.0 + * + * @param bool $trigger Whether to trigger the error. + * @param string $function The function that was called. + * @param string $message A message explaining what was done incorrectly. + * @param string $version The version of WordPress where the message was added. + * @return bool Whether to trigger the error. + */ + public static function bypass_block_metadata_doing_it_wrong( $trigger, $function, $message, $version ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + if ( $function === 'WP_Block_Metadata_Registry::register_collection' ) { + return false; + } + return $trigger; + } + /** * Register block metadata collection for Jetpack blocks. * This allows for more efficient block metadata loading by avoiding @@ -1351,11 +1377,15 @@ public static function site_supports_next_default_size() { public static function register_block_metadata_collection() { $meta_file_path = JETPACK__PLUGIN_DIR . '_inc/blocks/blocks-manifest.php'; if ( function_exists( 'wp_register_block_metadata_collection' ) && file_exists( $meta_file_path ) ) { + add_filter( 'doing_it_wrong_trigger_error', array( __CLASS__, 'bypass_block_metadata_doing_it_wrong' ), 10, 4 ); + // @phan-suppress-next-line PhanUndeclaredFunction -- New in WP 6.7. We're checking if it exists first. wp_register_block_metadata_collection( JETPACK__PLUGIN_DIR . '_inc/blocks/', $meta_file_path ); + + remove_filter( 'doing_it_wrong_trigger_error', array( __CLASS__, 'bypass_block_metadata_doing_it_wrong' ), 10 ); } } }