From 4a7ff78af658e1adb16a2bc7a4a3cddb08293800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Tue, 5 Apr 2022 10:38:06 +0200 Subject: [PATCH] Site Logo: Fix adding the site icon (#40041) * Site Logo: Fix adding the site icon Regression introduced in the `lib` folder refactoring #39972. * Fix formatting issues --- lib/compat/wordpress-5.9/rest-api.php | 25 ++++++++++++++++--- lib/compat/wordpress-6.0/edit-form-blocks.php | 8 +++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/compat/wordpress-5.9/rest-api.php b/lib/compat/wordpress-5.9/rest-api.php index 0a450f5569cc1..8414f9e514d15 100644 --- a/lib/compat/wordpress-5.9/rest-api.php +++ b/lib/compat/wordpress-5.9/rest-api.php @@ -35,7 +35,7 @@ function gutenberg_register_rest_menu_location() { * * @return array */ -function wp_api_nav_menus_post_type_args( $args, $post_type ) { +function gutenberg_api_nav_menus_post_type_args( $args, $post_type ) { if ( 'nav_menu_item' === $post_type ) { $args['show_in_rest'] = true; $args['rest_base'] = 'menu-items'; @@ -44,7 +44,7 @@ function wp_api_nav_menus_post_type_args( $args, $post_type ) { return $args; } -add_filter( 'register_post_type_args', 'wp_api_nav_menus_post_type_args', 10, 2 ); +add_filter( 'register_post_type_args', 'gutenberg_api_nav_menus_post_type_args', 10, 2 ); /** * Hook in to the nav_menu taxonomy and enable a taxonomy rest endpoint. @@ -54,7 +54,7 @@ function wp_api_nav_menus_post_type_args( $args, $post_type ) { * * @return array */ -function wp_api_nav_menus_taxonomy_args( $args, $taxonomy ) { +function gutenberg_api_nav_menus_taxonomy_args( $args, $taxonomy ) { if ( 'nav_menu' === $taxonomy ) { $args['show_in_rest'] = true; $args['rest_base'] = 'menus'; @@ -63,7 +63,24 @@ function wp_api_nav_menus_taxonomy_args( $args, $taxonomy ) { return $args; } -add_filter( 'register_taxonomy_args', 'wp_api_nav_menus_taxonomy_args', 10, 2 ); +add_filter( 'register_taxonomy_args', 'gutenberg_api_nav_menus_taxonomy_args', 10, 2 ); + +/** + * Exposes the site icon url to the Gutenberg editor through the WordPress REST + * API. The site icon url should instead be fetched from the wp/v2/settings + * endpoint when https://github.com/WordPress/gutenberg/pull/19967 is complete. + * + * @param WP_REST_Response $response Response data served by the WordPress REST index endpoint. + * @return WP_REST_Response + */ +function gutenberg_register_site_icon_url( $response ) { + $data = $response->data; + $data['site_icon_url'] = get_site_icon_url(); + $response->set_data( $data ); + return $response; +} + +add_filter( 'rest_index', 'gutenberg_register_site_icon_url' ); /** * Exposes the site logo to the Gutenberg editor through the WordPress REST diff --git a/lib/compat/wordpress-6.0/edit-form-blocks.php b/lib/compat/wordpress-6.0/edit-form-blocks.php index 68fc938e9e742..490ebd5a38ead 100644 --- a/lib/compat/wordpress-6.0/edit-form-blocks.php +++ b/lib/compat/wordpress-6.0/edit-form-blocks.php @@ -11,7 +11,7 @@ * @param array $preload_paths Preload paths to be filtered. * @return array */ -function optimize_preload_paths( $preload_paths ) { +function gutenberg_optimize_preload_paths( $preload_paths ) { // remove preload of the `/` route. $root_index = array_search( '/', $preload_paths, true ); if ( false !== $root_index ) { @@ -48,7 +48,7 @@ function optimize_preload_paths( $preload_paths ) { return $preload_paths; } -add_filter( 'block_editor_rest_api_preload_paths', 'optimize_preload_paths' ); +add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_optimize_preload_paths' ); /** * Disables loading remote block patterns from REST while initializing the editor. @@ -57,10 +57,10 @@ function optimize_preload_paths( $preload_paths ) { * * @param WP_Screen $current_screen WordPress current screen object. */ -function disable_load_remote_patterns( $current_screen ) { +function gutenberg_disable_load_remote_patterns( $current_screen ) { $is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) ); if ( $is_site_editor || $current_screen->is_block_editor() ) { add_filter( 'should_load_remote_block_patterns', '__return_false' ); } } -add_action( 'current_screen', 'disable_load_remote_patterns' ); +add_action( 'current_screen', 'gutenberg_disable_load_remote_patterns' );