Skip to content

How do plugins change the block editor icon? #38555

Closed

Description

@carlomanf

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

Activity

  1. carlomanf commented on Feb 7, 2022

    @carlomanf
    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.

  2. t-hamano commented on Feb 7, 2022

    @t-hamano
    Contributor

    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' );
  3. carlomanf commented on Feb 7, 2022

    @carlomanf
    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?

  4. t-hamano commented on Feb 7, 2022

    @t-hamano
    Contributor

    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.

  5. carlomanf commented on Feb 8, 2022

    @carlomanf
    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.

  6. carlomanf commented on Feb 21, 2022

    @carlomanf
    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?

  7. added
    [Type] Question
    on Feb 22, 2022
  8. carlomanf commented on Sep 6, 2022

    @carlomanf
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] Question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions