Changeset 43804 for branches/5.0
- Timestamp:
- 10/23/2018 06:52:03 AM (6 years ago)
- Location:
- branches/5.0
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0/src/wp-admin/edit.php
r42811 r43804 182 182 wp_enqueue_script('inline-edit-post'); 183 183 wp_enqueue_script('heartbeat'); 184 185 if ( 'wp_block' === $post_type ) { 186 wp_enqueue_script( 'wp-list-reusable-blocks' ); 187 wp_enqueue_style( 'wp-list-reusable-blocks' ); 188 } 184 189 185 190 $title = $post_type_object->labels->name; -
branches/5.0/src/wp-includes/capabilities.php
r43510 r43804 556 556 } 557 557 558 // Block capabilities map to their post equivalent. 559 $block_caps = array( 560 'edit_blocks', 561 'edit_others_blocks', 562 'publish_blocks', 563 'read_private_blocks', 564 'delete_blocks', 565 'delete_private_blocks', 566 'delete_published_blocks', 567 'delete_others_blocks', 568 'edit_private_blocks', 569 'edit_published_blocks', 570 ); 571 if ( in_array( $cap, $block_caps, true ) ) { 572 $cap = str_replace( '_blocks', '_posts', $cap ); 573 } 574 558 575 // If no meta caps match, return the original cap. 559 576 $caps[] = $cap; -
branches/5.0/src/wp-includes/post.php
r43744 r43804 225 225 'supports' => array(), 226 226 ) ); 227 228 register_post_type( 229 'wp_block', 230 array( 231 'labels' => array( 232 'name' => __( 'Blocks'), 233 'singular_name' => __( 'Block' ), 234 'search_items' => __( 'Search Blocks' ), 235 ), 236 'public' => false, 237 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 238 'show_ui' => true, 239 'show_in_menu' => false, 240 'rewrite' => false, 241 'capability_type' => 'block', 242 'capabilities' => array( 243 // You need to be able to edit posts, in order to read blocks in their raw form. 244 'read' => 'edit_posts', 245 // You need to be able to publish posts, in order to create blocks. 246 'create_posts' => 'publish_posts', 247 'edit_published_posts' => 'edit_published_posts', 248 'delete_published_posts' => 'delete_published_posts', 249 'edit_others_posts' => 'edit_others_posts', 250 'delete_others_posts' => 'delete_others_posts', 251 ), 252 'map_meta_cap' => true, 253 'supports' => array( 254 'title', 255 'editor', 256 ), 257 ) 258 ); 259 227 260 228 261 register_post_status( 'publish', array( -
branches/5.0/tests/phpunit/tests/user/capabilities.php
r43156 r43804 17 17 ); 18 18 protected static $super_admin = null; 19 20 protected static $block_id; 19 21 20 22 public static function wpSetUpBeforeClass( $factory ) { … … 28 30 self::$super_admin = $factory->user->create_and_get( array( 'role' => 'contributor' ) ); 29 31 grant_super_admin( self::$super_admin->ID ); 32 33 self::$block_id = $factory->post->create( 34 array( 35 'post_author' => self::$users['administrator']->ID, 36 'post_type' => 'wp_block', 37 'post_status' => 'publish', 38 'post_title' => 'Test Block', 39 'post_content' => '<!-- wp:core/paragraph --><p>Hello world!</p><!-- /wp:core/paragraph -->', 40 ) 41 ); 30 42 } 31 43 … … 36 48 37 49 } 50 51 public static function wpTearDownAfterClass() { 52 wp_delete_post( self::$block_id, true ); 53 } 54 38 55 39 56 function _flush_roles() { … … 2017 2034 $this->assertSame( 333, $roles->get_site_id() ); 2018 2035 } 2036 2037 /** 2038 * @dataProvider data_block_caps 2039 */ 2040 function test_block_caps( $role, $cap, $use_post, $expected ) { 2041 if ( $use_post ) { 2042 $this->assertEquals( $expected, self::$users[ $role ]->has_cap( $cap, self::$block_id ) ); 2043 } else { 2044 $this->assertEquals( $expected, self::$users[ $role ]->has_cap( $cap ) ); 2045 } 2046 } 2047 2048 function data_block_caps() { 2049 $post_caps = array( 2050 'edit_block', 2051 'read_block', 2052 'delete_block', 2053 ); 2054 2055 $all_caps = array( 2056 'edit_block', 2057 'read_block', 2058 'delete_block', 2059 'edit_blocks', 2060 'edit_others_blocks', 2061 'publish_blocks', 2062 'read_private_blocks', 2063 'delete_blocks', 2064 'delete_private_blocks', 2065 'delete_published_blocks', 2066 'delete_others_blocks', 2067 'edit_private_blocks', 2068 'edit_published_blocks', 2069 ); 2070 2071 $roles = array( 2072 'administrator' => $all_caps, 2073 'editor' => $all_caps, 2074 'author' => array( 2075 'read_block', 2076 'edit_blocks', 2077 'publish_blocks', 2078 'delete_blocks', 2079 'delete_published_blocks', 2080 'edit_published_blocks', 2081 ), 2082 'contributor' => array( 2083 'read_block', 2084 'edit_blocks', 2085 'delete_blocks', 2086 ), 2087 'subscriber' => array(), 2088 ); 2089 2090 $data = array(); 2091 2092 foreach( $roles as $role => $caps ) { 2093 foreach ( $caps as $cap ) { 2094 $use_post = in_array( $cap, $post_caps, true ); 2095 $data[] = array( $role, $cap, $use_post, true ); 2096 } 2097 2098 foreach ( $all_caps as $cap ) { 2099 if ( ! in_array( $cap, $caps, true ) ) { 2100 $use_post = in_array( $cap, $post_caps, true ); 2101 $data[] = array( $role, $cap, $use_post, false ); 2102 } 2103 } 2104 } 2105 2106 return $data; 2107 } 2019 2108 }
Note: See TracChangeset
for help on using the changeset viewer.