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

Enable Reusable Blocks in the admin menu #19

Closed
bobbingwide opened this issue Oct 24, 2019 · 4 comments
Closed

Enable Reusable Blocks in the admin menu #19

bobbingwide opened this issue Oct 24, 2019 · 4 comments

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Oct 24, 2019

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:

  • delete_blocks
  • delete_private_blocks
  • edit_private_blocks
  • publish_blocks
  • read_private_blocks

In s.b/wordpress I have 6 more

  • create_blocks
  • delete_others_blocks
  • delete_published_blocks
  • edit_blocks
  • edit_others_blocks
  • edit_published_blocks

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 bobbingwide/oik-clone#24 (comment)

@bobbingwide bobbingwide self-assigned this Oct 24, 2019
@bobbingwide bobbingwide changed the title Enable wp_block in the admin menu Enable Reusable Blocks in the admin menu Oct 24, 2019
@bobbingwide
Copy link
Owner Author

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
Copy link
Owner Author

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
Copy link
Owner Author

bobbingwide commented Nov 1, 2019

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
Copy link
Owner Author

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?”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant