WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/02/2016 12:30:29 AM (4 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/src/wp-includes/ms-blogs.php

    r38943 r39082  
    767767 */
    768768function switch_to_blog( $new_blog, $deprecated = null ) {
    769     global $wpdb;
     769    global $wpdb, $wp_roles;
    770770
    771771    $blog_id = get_current_blog_id();
     
    823823
    824824    if ( did_action( 'init' ) ) {
    825         wp_roles()->reinit();
     825        $wp_roles = new WP_Roles();
    826826        $current_user = wp_get_current_user();
    827827        $current_user->for_blog( $new_blog );
     
    851851 */
    852852function restore_current_blog() {
    853     global $wpdb;
     853    global $wpdb, $wp_roles;
    854854
    855855    if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
     
    897897
    898898    if ( did_action( 'init' ) ) {
    899         wp_roles()->reinit();
     899        $wp_roles = new WP_Roles();
    900900        $current_user = wp_get_current_user();
    901901        $current_user->for_blog( $blog );
Note: See TracChangeset for help on using the changeset viewer.