Forked from mrpritchett/wp-gutenberg-reusable-block-interface.php
Last active
November 4, 2024 07:29
-
-
Save apermo/1693f580b9e833bb30fe8ac70020b769 to your computer and use it in GitHub Desktop.
Gutenberg Reusable Block Editor Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_add_interface_to_wp_block( $args, $post_type ) { | |
global $pagenow; | |
if ( 'wp_block' !== $post_type ) { | |
return $args; | |
} | |
$changed_args = array( | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 9, | |
'menu_icon' => 'dashicons-controls-repeat', | |
'show_in_admin_bar' => false, | |
'show_in_nav_menus' => false, | |
'has_archive' => false, | |
'supports' => array( 'title', 'editor' ), | |
'exclude_from_search' => true, | |
); | |
$args = array_merge( $args, $changed_args ); | |
$allowed_pages = [ 'post-new.php', 'post.php' ]; | |
if ( in_array( $pagenow, $allowed_pages, true ) ) { | |
$args['rest_controller_class'] = 'WP_REST_Posts_Controller'; | |
} | |
return $args; | |
} | |
add_filter( 'register_post_type_args', 'custom_add_interface_to_wp_block', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I arrived here from WordPress/gutenberg#13291
I use this code to show the interface for
wp_block
in the menu.The $name variable on line 4 should be changed to $post_type. And like you mentioned in the gutenberg issue: I needed to set
_builtin
to false.