janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

Meta box suddenly hidden in version 0.17.0 #87

Closed janboddez closed 10 months ago

janboddez commented 10 months ago

TL;DR: Enabling the "Use classic meta box" (Settings > Share on Mastodon > "Advanced" tab) option will solve this issue.

As far as I know, this issue affects some but not all "classic editor" users.

I was able to reproduce it as follows:

If the Classic Editor plugin is "configured" to let users choose between the block and classic editors, the use_block_editor_for_post_type(), which I use to determine whether to show the "classic" meta box, can no longer be relied on.

While the Classic Editor plugin filters the outcome of this function before returning it, it does not do so when it is set up to let users choose from either one of the two editors.

"Configuring" the Classic Editor plugin to do so seems to require this bit of code:

add_filter( 'classic_editor_plugin_settings', function() {
    return array(
        'editor'      => 'classic', // `'block'` is another possible value.
        'allow-users' => true,
    );
} );

I've only just found out this is possible at all! I will have to think of another way to detect the editor type, then.

Meanwhile, enabling the "Use classic meta box" (Settings > Share on Mastodon > "Advanced" tab) option will work.

janboddez commented 10 months ago

It’s not a bug in the Classic Editor per se, but rather that WordPress’ use_block_editor_for_post_type() really just checks if a post type could, potentially, support the block editor. In 2023, most post types are registered with block editor support.

We were just "lucky" that the Classic Editor plugin was "nice enough" to filter the outcome of that function.

Except, sometimes it doesn't ...

janboddez commented 10 months ago

Obviously, removing the classic_editor_plugin_settings filter callback will also work, but may not be an option for certain authors.

janboddez commented 10 months ago

OK, I should use '__back_compat_meta_box' => true as per https://developer.wordpress.org/block-editor/how-to-guides/metabox/#testing-converting-and-maintaining-existing-meta-boxes

When the block editor is used, this meta box will no longer be displayed in the meta box area, as it now only exists for backward compatibility purposes. It will display as before in the classic editor.

Rather than try and hide it using my own logic. Just gotta address the fallback for block editor users (i.e., ensure Gutenberg users do see it in case the classic meta box option is ticked).