Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save apermo/1693f580b9e833bb30fe8ac70020b769 to your computer and use it in GitHub Desktop.
Save apermo/1693f580b9e833bb30fe8ac70020b769 to your computer and use it in GitHub Desktop.
Gutenberg Reusable Block Editor Interface
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 );
@apermo
Copy link
Author

apermo commented Nov 4, 2024

Fixed the $name to $post_type

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