From 3af9743b815e83d2c8bb1630367d26b1855bd25a Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Fri, 14 Dec 2018 02:15:37 +0000 Subject: [PATCH] Blocks: Add the reusable block post type, `wp_block`. Merges [43804] from the 5.0 branch to trunk. See #45098. Built from https://develop.svn.wordpress.org/trunk@44146 git-svn-id: http://core.svn.wordpress.org/trunk@43976 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit.php | 5 +++++ wp-includes/capabilities.php | 17 +++++++++++++++++ wp-includes/post.php | 32 ++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/wp-admin/edit.php b/wp-admin/edit.php index 24a02d05b1..3f542be87b 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -200,6 +200,11 @@ $wp_list_table->prepare_items(); wp_enqueue_script( 'inline-edit-post' ); wp_enqueue_script( 'heartbeat' ); +if ( 'wp_block' === $post_type ) { + wp_enqueue_script( 'wp-list-reusable-blocks' ); + wp_enqueue_style( 'wp-list-reusable-blocks' ); +} + $title = $post_type_object->labels->name; if ( 'post' == $post_type ) { diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 375648e768..c192639608 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -574,6 +574,23 @@ function map_meta_cap( $cap, $user_id ) { return call_user_func_array( 'map_meta_cap', $args ); } + // Block capabilities map to their post equivalent. + $block_caps = array( + 'edit_blocks', + 'edit_others_blocks', + 'publish_blocks', + 'read_private_blocks', + 'delete_blocks', + 'delete_private_blocks', + 'delete_published_blocks', + 'delete_others_blocks', + 'edit_private_blocks', + 'edit_published_blocks', + ); + if ( in_array( $cap, $block_caps, true ) ) { + $cap = str_replace( '_blocks', '_posts', $cap ); + } + // If no meta caps match, return the original cap. $caps[] = $cap; } diff --git a/wp-includes/post.php b/wp-includes/post.php index de8b83143e..d8ccf05ffb 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -252,6 +252,38 @@ function create_initial_post_types() { ) ); + register_post_type( + 'wp_block', + array( + 'labels' => array( + 'name' => __( 'Blocks' ), + 'singular_name' => __( 'Block' ), + 'search_items' => __( 'Search Blocks' ), + ), + 'public' => false, + '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ + 'show_ui' => true, + 'show_in_menu' => false, + 'rewrite' => false, + 'capability_type' => 'block', + 'capabilities' => array( + // You need to be able to edit posts, in order to read blocks in their raw form. + 'read' => 'edit_posts', + // You need to be able to publish posts, in order to create blocks. + 'create_posts' => 'publish_posts', + 'edit_published_posts' => 'edit_published_posts', + 'delete_published_posts' => 'delete_published_posts', + 'edit_others_posts' => 'edit_others_posts', + 'delete_others_posts' => 'delete_others_posts', + ), + 'map_meta_cap' => true, + 'supports' => array( + 'title', + 'editor', + ), + ) + ); + register_post_status( 'publish', array( diff --git a/wp-includes/version.php b/wp-includes/version.php index 6a6b2e1b53..01ea95bab4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-44145'; +$wp_version = '5.1-alpha-44146'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.