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

API for registering custom icons for the editor #51563

Open
getdave opened this issue Jun 16, 2023 · 7 comments
Open

API for registering custom icons for the editor #51563

getdave opened this issue Jun 16, 2023 · 7 comments
Labels
[Package] Icons /packages/icons [Type] New API New API to be used by plugin developers or package users.

Comments

@getdave
Copy link
Contributor

getdave commented Jun 16, 2023

There have been quite a few requests to allow us to customise the icons used in blocks in the editor

Currently this is not possible.

Whilst exploring this in #51527 I suggested exploring a new API to allow developers to register their own custom icons with the editor.

register_editor_icon(
    name: 'myicon',
    label: 'My Icon',
    svg: // SVG markup here
);

As I suggested we would need to register this PHP side and sanitize the SVG there.

Then on output we would:

  • PHP: use esc_ functions.
  • JS: use dangerouslySetInnerHTML with equivalent escape functions.
@MaggieCabrera
Copy link
Contributor

Related #16513

@getdave
Copy link
Contributor Author

getdave commented Jun 19, 2023

@scruffian Is there any scope here to absorb icons as part of global styles as some kind of element? Is that even possible?

@MaggieCabrera
Copy link
Contributor

I think it makes more sense for it to be a block?

@getdave
Copy link
Contributor Author

getdave commented Jun 19, 2023

I think it makes more sense for it to be a block?

I agree that having a block for "icon" might be useful. However, this issue is specifically about providing a means for developers to use custom icons within the editor.

What we need is a means to register those icons (note: that doesn't mean we need to be able to upload them).

One use case for such an API can be found here.

@getdave
Copy link
Contributor Author

getdave commented Jun 21, 2023

@scruffian
Copy link
Contributor

Is there any scope here to absorb icons as part of global styles as some kind of element? Is that even possible?

It's possible to create an icon element, but I don't think it would help much with what you're seeking to achieve here. It could be a good followup though.

@getdave
Copy link
Contributor Author

getdave commented Jul 3, 2023

I think we should consider doing this via Theme JSON instead. I'm going to think about this some more and come up with a counter proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Icons /packages/icons [Type] New API New API to be used by plugin developers or package users.
Projects
None yet
Development

No branches or pull requests

3 participants