Make WordPress Core


Ignore:
Timestamp:
11/02/2016 12:30:29 AM (8 years ago)
Author:
pento
Message:

Roles/Capabilities: Add a new wp_roles_init filter.

Historically, it's been difficult to extend user roles, but reasonable to work around by waiting until after init has fired, to add custom roles and capabilities. With the addition of Locale Switching, Core now potentially loads roles before init has fired, leaving a window where custom roles and capabilities are not handled.

The new filter allows plugins to add their own custom roles whenever they're initialised (on page load, or when switching sites, for example), so that they can always be obeyed.

WP_Roles has also been tidied up a little bit, to remove duplicate code.

Props johnjamesjacoby, pento.
Fixes #23016.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/multisite.php

    r38903 r39082  
    397397        $this->assertWPError( $result );
    398398    }
     399
     400    /**
     401     * @ticket 23016
     402     */
     403    public function test_wp_roles_global_is_reset() {
     404        global $wp_roles;
     405        $role = 'test_global_is_reset';
     406        $role_name = 'Test Global Is Reset';
     407        $blog_id = self::factory()->blog->create();
     408
     409        $wp_roles->add_role( $role, $role_name, array() );
     410
     411        $this->assertNotEmpty( $wp_roles->get_role( $role ) );
     412
     413        switch_to_blog( $blog_id );
     414
     415        $this->assertEmpty( $wp_roles->get_role( $role ) );
     416
     417        $wp_roles->add_role( $role, $role_name, array() );
     418
     419        $this->assertNotEmpty( $wp_roles->get_role( $role ) );
     420
     421        restore_current_blog();
     422
     423        $this->assertNotEmpty( $wp_roles->get_role( $role ) );
     424
     425        $wp_roles->remove_role( $role );
     426    }
    399427}
    400428
Note: See TracChangeset for help on using the changeset viewer.