Blocks: Add the reusable block post type, wp_block.

See #45098.


Built from https://develop.svn.wordpress.org/branches/5.0@43804


git-svn-id: http://core.svn.wordpress.org/branches/5.0@43633 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2018-10-23 06:53:38 +00:00
parent 8083498426
commit c60c870ab8
4 changed files with 56 additions and 1 deletions

View File

@ -182,6 +182,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 ) {

View File

@ -555,6 +555,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;
}

View File

@ -225,6 +225,39 @@ function create_initial_post_types() {
'supports' => array(),
) );
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(
'label' => _x( 'Published', 'post status' ),
'public' => true,

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-43803';
$wp_version = '5.0-alpha-43804';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.