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

Feature Request: enable Icon Chooser in block-based widget editor #151

Open
mlwilkerson opened this issue Oct 5, 2021 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@mlwilkerson
Copy link
Member

WordPress 5.8 introduced block editing to the widget editing interfaces.

Unfortunately, this plugin currently does not support it because that particular editing interface involves the possibility of legacy widgets that may rely on the ability to instantiate the classic Tiny MCE editor. This is specifically called out in that feature announcement:

Don’t use @wordpress/editor
Many legacy widgets call the wp.editor.initialize() JavaScript function to instantiate a TinyMCE editor. If a plugin or block uses the @wordpress/editor package and enqueues wp-editor as a script dependency, this will re-define the wp.editor global, often resulting in a wp.editor.initialize is undefined error.

But this was the same root cause of a problem we previously had with this plugin, when depending on wp-editor for block editor integration, and being loaded in a context where another plugin relies on the availability of that wp.editor.initialize global for instantiating TinyMCE. The RankMath plugin was the initial reported case in the support forum.

To make this feature work would require some further investigation as to whether it is even possible for us to add the Icon Chooser to that block editor's format bar within the widget editor without depending on @wordpress/editor.

How is anyone else accomplishing this?

Even if we find a solution, it seems likely that some other component will make this mistake. Seems like a foot gun that will be claiming a lot of toes.

Heads Up: Two Paths with Different Properties

As the feature announcement indicates, there are two different ways that this feature is encountered:

  1. Appearance → Widgets
    In initial exploration, this can be enabled by simply adding widgets.php to the list of screens for which the icon chooser should be enabled.

    protected $icon_chooser_screens = array( 'post.php', 'post-new.php' );

    This is because (if I recall, correctly), our is_gutenberg_page() returns true in this scenario. Thus it satisfies the constraint we put in previously: only enable the Icon Chooser with block editor integration when it's clearly a Gutenberg page.

    But this doesn't rule out the possibility of the error condition called about above. It will end up assigning to the wp.editor global, and thus possibly creating a problem for any legacy widgets that try to invoke the global wp.editor.initialize().

  2. Appearance → Customize → Widgets

    In initial exploration, even though the address bar looks like customize.php, there's also an iframe involved. So the current screen that is active when our code runs still ends up being widgets.php. However, is_gutenberg_page() is false in this context.

So making this work will require not just turning it on (because that's not too difficult), but finding a way to turn it on that doesn't break others.

See also:

@mlwilkerson mlwilkerson added the enhancement New feature or request label Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant