bobbingwide / oik-types

oik custom content type manager
http://www.oik-plugins.com/oik-plugins/oik-types/
GNU General Public License v2.0
1 stars 0 forks source link

Enable Reusable Blocks in the admin menu #19

Closed bobbingwide closed 4 years ago

bobbingwide commented 4 years ago

Requirement

To be able to Create and Edit Reusable blocks ( post_type=wp_block ) directly from the WordPress Dashboard.

Proposed solution

Extend oik-types to override _builtin = true and/or adjust the capabilities of a post type.

Alternative solution

Just use Bill Erickson's plugin. https://github.com/billerickson/Reusable-Blocks-UI

Background

Some time ago, when looking at Reusable blocks for the first time, I tried to use oik-types to enable "Blocks" to appear in the admin menu.

I finally achieved it ( in s.b/wordpress ) by updating the administrator role's capabilities.

But I can't remember exactly how I did it.

It could have been a simple edit of the serialised data to add the missing capabilities to wp_user_roles in wp_options.

In unhacked environments I have these 5 capabilities for blocks:

In s.b/wordpress I have 6 more

or I could have done it programmatically, or with a plugin. I may even have hacked 'core', which caused it to update the options table for me.

Anyway, in order to be able to clone the content in Reusabe blocks I believe I have this need to reproduce what I did on s.b/wordpress on other sites.

Notes

Using oik-types does enable the New > Block link in the top admin menu https://s.b/wordpress/wp-admin/post-new.php?post_type=wp_block

You have to select "Show in admin bar", then refresh the page.

but the Blocks and All Blocks link in the side menu is not present https://s.b/wordpress/wp-admin/edit.php?post_type=wp_block

I've searched code changes for _builtin , traced filter results for register_post_type_args and grepped my daily notes files to no avail.

See also https://github.com/bobbingwide/oik-clone/issues/24#issuecomment-474717357

bobbingwide commented 4 years ago

In s.b/wp52 I was able to get the Blocks menu item to appear by hacking core. I changed the registration for wp_block to _builtin = false and show_in_menu = true

I'm not sure why oik-types logic did not take effect.

bobbingwide commented 4 years ago

I've finally tracked it down. oik-types stores its overrides to post types in a serialised array in the wp_options table called bw_types.

By hacking core to set _builtin = false and then using oik-types to update the post type definition it was possible to save the value as _builtin = 0

This then overrode the initially registered value.

It would seem that the simple solution would be to add the _builtin checkbox to the oik-types admin page.

bobbingwide commented 4 years ago

I’ve tested this solution in bobbingwide.com/problem-solving. The Blocks admin menu item does appear. This issue can be closed.

There are some follow on issues associated with editing blocks:

bobbingwide commented 4 years ago

In terms of Problem Solving this was a good example for Step 7: Persist. And also a good response to the question “Did you document the changes?”