Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do plugins change the block editor icon? #38555

Closed
carlomanf opened this issue Feb 7, 2022 · 7 comments
Closed

How do plugins change the block editor icon? #38555

carlomanf opened this issue Feb 7, 2022 · 7 comments
Labels
[Type] Question Questions about the design or development of the editor.

Comments

@carlomanf
Copy link

Description

I want to bundle an image in my (private) plugin, and use it as the icon that shows in the top-left corner of the block editor screen.

There is an official filter for changing the site icon, but it is not used when resolving the block editor icon. Apparently, the only way to change the default icon is through an attachment post ID, which seems unnecessarily stringent.

Either the existing filter should be used here, or there should be a second filter specifically for the block editor icon.

I would appreciate this to be considered a high priority and considered a bug, not an enhancement. It should always be easy for plugins to disable the default branding.

Step-by-step reproduction instructions

  1. Install a hypothetical plugin that re-brands the admin without inserting new attachment posts
  2. Continue to see the default icon in the block editor

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

No

@carlomanf
Copy link
Author

Although I didn't want to do this by setting a site icon through the customiser, I tried it anyway for the time being, and I am finding that I can't even change the block editor icon this way. Nothing I try will change the default icon.

Using core version 5.9 with all plugins deactivated.

@t-hamano
Copy link
Contributor

t-hamano commented Feb 7, 2022

How about using the rest_index hook?

Like this:

function register_site_icon_url( $response ) {
	$data                  = $response->data;
	$data['site_icon_url'] = get_theme_file_uri( 'icon.png' );
	$response->set_data( $data );
	return $response;
}
add_filter( 'rest_index', 'register_site_icon_url' );

@carlomanf
Copy link
Author

Thanks for the code, it solves what I want to do. I did come across that hook in my research but couldn't spot how to use it. Still not sure why the customiser didn't work?

@t-hamano
Copy link
Contributor

t-hamano commented Feb 7, 2022

I haven't analyzed it in depth, so I don't know if the lack of functioning of the customizer is a specification or a bug.

I will look into it again if I have time.

@carlomanf
Copy link
Author

Although I didn't want to do this by setting a site icon through the customiser, I tried it anyway for the time being, and I am finding that I can't even change the block editor icon this way. Nothing I try will change the default icon.

Using core version 5.9 with all plugins deactivated.

Confirmed to work with the gutenberg plugin active, but not when inactive.

@carlomanf
Copy link
Author

How about using the rest_index hook?

Like this:

function register_site_icon_url( $response ) {
	$data                  = $response->data;
	$data['site_icon_url'] = get_theme_file_uri( 'icon.png' );
	$response->set_data( $data );
	return $response;
}
add_filter( 'rest_index', 'register_site_icon_url' );

I notice that some code handling the site icon that passes through this filter was only added in core version 5.9, which suggests that the regression might have happened in that version. On the other hand, I can't find anything in version 5.8.3 to handle the site icon.

Does anyone know whether the icon replacement was ever possible in core, or only with the plugin active?

@carlomanf
Copy link
Author

It looks like this was fixed by WordPress/wordpress-develop#3157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

3 participants