Make WordPress Core

Ticket #45098: 45098.7.diff

File 45098.7.diff, 5.2 KB (added by peterwilsoncc, 7 years ago)
  • src/wp-admin/includes/schema.php

    diff --git src/wp-admin/includes/schema.php src/wp-admin/includes/schema.php
    index b93fad35b4..ef4158c4dc 100644
    function populate_roles() { 
    608608        populate_roles_270();
    609609        populate_roles_280();
    610610        populate_roles_300();
     611        populate_roles_500();
    611612}
    612613
    613614/**
    function populate_roles_300() { 
    848849        }
    849850}
    850851
     852/**
     853 * Create and modify WordPress roles for WordPress 5.0.
     854 *
     855 * Assigns capabilities for reading and editing reusable blocks. Runs
     856 * directly on the option to avoid updating the roles option 30+ times.
     857 *
     858 * @since 5.0.0
     859 */
     860function populate_roles_500() {
     861        global $wp_user_roles, $wpdb;
     862
     863        if ( ! empty( $wp_user_roles ) ) {
     864                // Roles and caps are not stored in the database.
     865                return;
     866        }
     867
     868        $site_id = get_current_blog_id();
     869        $role_key = $wpdb->get_blog_prefix( $site_id ) . 'user_roles';
     870        $roles_and_caps = get_option( $role_key, array() );
     871
     872        $editor_caps = array(
     873                'edit_blocks',
     874                'edit_others_blocks',
     875                'publish_blocks',
     876                'read_private_blocks',
     877                'read_blocks',
     878                'delete_blocks',
     879                'delete_private_blocks',
     880                'delete_published_blocks',
     881                'delete_others_blocks',
     882                'edit_private_blocks',
     883                'edit_published_blocks',
     884                'create_blocks',
     885        );
     886
     887        $caps_map = array(
     888                'administrator' => $editor_caps,
     889                'editor'        => $editor_caps,
     890                'author'        => array(
     891                        'edit_blocks',
     892                        'publish_blocks',
     893                        'read_blocks',
     894                        'delete_blocks',
     895                        'delete_published_blocks',
     896                        'edit_published_blocks',
     897                        'create_blocks',
     898                ),
     899                'contributor'   => array(
     900                        'read_blocks',
     901                ),
     902        );
     903
     904        foreach ( $caps_map as $role_name => $caps ) {
     905                if ( ! isset( $roles_and_caps[ $role_name ] ) ) {
     906                        continue;
     907                }
     908                $role = $roles_and_caps[ $role_name ];
     909
     910                if ( empty( $role ) ) {
     911                        continue;
     912                }
     913
     914                /*
     915                 * Due to roles being created in the block editor feature plugin,
     916                 * the presence needs to be checked before adding the role.
     917                 */
     918                foreach ( $caps as $cap ) {
     919                        if ( isset( $role['capabilities'][ $cap ] ) ) {
     920                                continue;
     921                        }
     922                        $roles_and_caps[ $role_name ]['capabilities'][ $cap ] = true;
     923                }
     924        }
     925
     926        update_option( $role_key, $roles_and_caps );
     927}
     928
    851929if ( !function_exists( 'install_network' ) ) :
    852930/**
    853931 * Install Network.
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index f36d2d0c02..13c075b4c6 100644
    function upgrade_all() { 
    628628        if ( $wp_current_db_version < 37965 )
    629629                upgrade_460();
    630630
    631         if ( $wp_current_db_version < 43764 )
     631        if ( $wp_current_db_version < 43824 )
    632632                upgrade_500();
    633633
    634634        maybe_disable_link_manager();
    function upgrade_500() { 
    18151815                }
    18161816                deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
    18171817        }
     1818
     1819        if ( $wp_current_db_version < 43824 ) {
     1820                populate_roles_500();
     1821        }
    18181822}
    18191823
    18201824/**
  • src/wp-includes/capabilities.php

    diff --git src/wp-includes/capabilities.php src/wp-includes/capabilities.php
    index 38bb4c6c6d..748d02907c 100644
    function map_meta_cap( $cap, $user_id ) { 
    555555                        return call_user_func_array( 'map_meta_cap', $args );
    556556                }
    557557
    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 
    575558                // If no meta caps match, return the original cap.
    576559                $caps[] = $cap;
    577560        }
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index c9d1edbe67..03189b89e1 100644
    function create_initial_post_types() { 
    261261                        'rest_controller_class' => 'WP_REST_Blocks_Controller',
    262262                        'capability_type'       => 'block',
    263263                        'capabilities'          => array(
    264                                 // You need to be able to edit posts, in order to read blocks in their raw form.
    265                                 'read'                   => 'edit_posts',
    266                                 // You need to be able to publish posts, in order to create blocks.
    267                                 'create_posts'           => 'publish_posts',
    268                                 'edit_published_posts'   => 'edit_published_posts',
    269                                 'delete_published_posts' => 'delete_published_posts',
    270                                 'edit_others_posts'      => 'edit_others_posts',
    271                                 'delete_others_posts'    => 'delete_others_posts',
     264                                'read'         => 'read_blocks',
     265                                'create_posts' => 'create_blocks',
    272266                        ),
    273267                        'map_meta_cap'          => true,
    274268                        'supports'              => array(
    function create_initial_post_types() { 
    278272                )
    279273        );
    280274
    281 
    282275        register_post_status( 'publish', array(
    283276                'label'       => _x( 'Published', 'post status' ),
    284277                'public'      => true,
  • src/wp-includes/version.php

    diff --git src/wp-includes/version.php src/wp-includes/version.php
    index ab321dd33a..cee49296ce 100644
    $wp_version = '5.0-beta2-43845-src'; 
    1111 *
    1212 * @global int $wp_db_version
    1313 */
    14 $wp_db_version = 43764;
     14$wp_db_version = 43824;
    1515
    1616/**
    1717 * Holds the TinyMCE version