FortAwesome / wordpress-fontawesome

Font Awesome Official WordPress Plugin
Other
57 stars 19 forks source link

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

Open mlwilkerson opened 2 years ago

mlwilkerson commented 2 years ago

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. https://github.com/FortAwesome/wordpress-fontawesome/blob/7cfd95c2b6bb581acf21f7d322c23f22bc05b3f8/includes/class-fontawesome.php#L280

    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: