diff --git a/lib/compat/wordpress-5.8/index.php b/lib/compat/wordpress-5.8/index.php index 9427ce463500af..d1dc42880061f1 100644 --- a/lib/compat/wordpress-5.8/index.php +++ b/lib/compat/wordpress-5.8/index.php @@ -103,3 +103,64 @@ function build_query_vars_from_query_block( $block, $page ) { return $query; } } + +if ( ! function_exists( 'gutenberg_register_legacy_query_loop_block' ) ) { + /** + * Renders the legacy `core/query-loop` block on the server. + * It triggers a developer warning and then calls the renamed + * block's `render_callback` function output. + * + * @param array $attributes Block attributes. + * @param string $content Block default content. + * @param WP_Block $block Block instance. + * + * @return string Returns the output of the query, structured using the layout defined by the block's inner blocks. + */ + function gutenberg_render_legacy_query_loop_block( $attributes, $content, $block ) { + trigger_error( + /* translators: %1$s: Block type */ + sprintf( __( 'Block %1$s has been renamed to Post Template. %1$s will be supported until WordPress version 5.9.', 'gutenberg' ), $block->name ), + headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE + ); + return render_block_core_post_template( $attributes, $content, $block ); + } +} + +if ( ! function_exists( 'gutenberg_register_legacy_query_loop_block' ) ) { + /** + * Complements the renaming of `Query Loop` to `Post Template`. + * This ensures backwards compatibility for any users running the Gutenberg + * plugin who have used Query Loop prior to its renaming. + * + * @see https://github.com/WordPress/gutenberg/pull/32514 + */ + function gutenberg_register_legacy_query_loop_block() { + $registry = WP_Block_Type_Registry::get_instance(); + if ( $registry->is_registered( 'core/query-loop' ) ) { + unregister_block_type( 'core/query-loop' ); + } + register_block_type( + 'core/query-loop', + array( + 'category' => 'design', + 'uses_context' => array( + 'queryId', + 'query', + 'queryContext', + 'displayLayout', + 'templateSlug', + ), + 'supports' => array( + 'reusable' => false, + 'html' => false, + 'align' => true, + ), + 'style' => 'wp-block-post-template', + 'render_callback' => 'gutenberg_render_legacy_query_loop_block', + 'skip_inner_blocks' => true, + ) + ); + } + + add_action( 'init', 'gutenberg_register_legacy_query_loop_block' ); +} diff --git a/packages/block-library/src/post-template/index.php b/packages/block-library/src/post-template/index.php index dd69fda45fe7f3..3daacbad7f6499 100644 --- a/packages/block-library/src/post-template/index.php +++ b/packages/block-library/src/post-template/index.php @@ -86,63 +86,3 @@ function register_block_core_post_template() { ); } add_action( 'init', 'register_block_core_post_template' ); - -/** - * Renders the legacy `core/query-loop` block on the server. - * It triggers a developer warning and then calls the renamed - * block's `render_callback` function output. - * - * This can be removed when WordPress 5.9 is released. - * - * @param array $attributes Block attributes. - * @param string $content Block default content. - * @param WP_Block $block Block instance. - * - * @return string Returns the output of the query, structured using the layout defined by the block's inner blocks. - */ -function render_legacy_query_loop_block( $attributes, $content, $block ) { - trigger_error( - /* translators: %1$s: Block type */ - sprintf( __( 'Block %1$s has been renamed to Post Template. %1$s will be supported until WordPress version 5.9.' ), $block->name ), - headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE - ); - return render_block_core_post_template( $attributes, $content, $block ); -} - -/** - * Complements the renaming of `Query Loop` to `Post Template`. - * This ensures backwards compatibility for any users running the Gutenberg - * plugin who have used Query Loop prior to its renaming. - * - * This can be removed when WordPress 5.9 is released. - * - * @see https://github.com/WordPress/gutenberg/pull/32514 - */ -function gutenberg_register_legacy_query_loop_block() { - $registry = WP_Block_Type_Registry::get_instance(); - if ( $registry->is_registered( 'core/query-loop' ) ) { - unregister_block_type( 'core/query-loop' ); - } - register_block_type( - 'core/query-loop', - array( - 'category' => 'design', - 'uses_context' => array( - 'queryId', - 'query', - 'queryContext', - 'displayLayout', - 'templateSlug', - ), - 'supports' => array( - 'reusable' => false, - 'html' => false, - 'align' => true, - ), - 'style' => 'wp-block-post-template', - 'render_callback' => 'render_legacy_query_loop_block', - 'skip_inner_blocks' => true, - ) - ); -} -add_action( 'init', 'gutenberg_register_legacy_query_loop_block' ); diff --git a/packages/widgets/src/blocks/legacy-widget/index.php b/packages/widgets/src/blocks/legacy-widget/index.php index 8a326056816c9d..e827f8f7c53096 100644 --- a/packages/widgets/src/blocks/legacy-widget/index.php +++ b/packages/widgets/src/blocks/legacy-widget/index.php @@ -29,6 +29,13 @@ function render_block_core_legacy_widget( $attributes ) { $widget_key = $wp_widget_factory->get_widget_key( $id_base ); $widget_object = $wp_widget_factory->get_widget_object( $id_base ); } else { + /* + * This file is copied from the published @wordpress/widgets package when WordPress + * Core is built. Because the package is a dependency of both WordPress Core and the + * Gutenberg plugin where the block editor is developed, this fallback condition is + * required until the minimum required version of WordPress for the plugin is raised + * to 5.8. + */ $widget_key = gutenberg_get_widget_key( $id_base ); $widget_object = gutenberg_get_widget_object( $id_base ); }