Skip to content

Commit

Permalink
Site Logo: Fix adding the site icon (#40041)
Browse files Browse the repository at this point in the history
* Site Logo: Fix adding the site icon
Regression introduced in the `lib` folder refactoring #39972.

* Fix formatting issues
  • Loading branch information
gziolo authored Apr 5, 2022
1 parent f1cfc3b commit 4a7ff78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 21 additions & 4 deletions lib/compat/wordpress-5.9/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand All @@ -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';
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/compat/wordpress-6.0/edit-form-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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.
Expand All @@ -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' );

0 comments on commit 4a7ff78

Please sign in to comment.