WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 21 months ago

#13635 closed defect (bug) (invalid)

Bug in capabilities and custom user and usermeta tables

Reported by: czepol Owned by: ryan
Milestone: Priority: high
Severity: normal Version:
Component: Role/Capability Keywords:
Focuses: Cc:

Description

I own 2 blogs based on WordPress with one instance for each of them. I use "wp_" table prefix for the first, "wp_blog_" for the other one. In a wp-config.php file used by the second blog (that one with "wp_blog_" prefix), I set two constans:

define( 'CUSTOM_USER_TABLE', 'wp_users' );
define( 'CUSTOM_USER_META_TABLE', 'wp_usermeta' );

Someone forgot about 'wp_capabilities'. If I didn't change capabilities's table to "wp_capabilities" for blog which has table prefix "wp_blog_" I can't login on the blog (Error: "You do not have sufficient permissions to access this page."). It's needed to add some code to wp-includes/capabilites.php in function "_init_caps( $cap_key = "" )". Now the _init_caps looks like this:

    function _init_caps( $cap_key = '' ) {
        global $wpdb;
        if ( empty($cap_key) )
            $this->cap_key = $wpdb->prefix . 'capabilities';
        else
            $this->cap_key = $cap_key;
        $this->caps = &$this->{$this->cap_key};
        if ( ! is_array( $this->caps ) )
            $this->caps = array();
        $this->get_role_caps();
    }

I propose to change this function to:

    function _init_caps( $cap_key = '' ) {
        global $wpdb;
        if ( empty($cap_key) )
            $this->cap_key = $wpdb->prefix . 'capabilities';
        else
            $this->cap_key = $cap_key;
        $this->caps = &$this->{$this->cap_key};
        if ( defined('CUSTOM_CAPABILITIES_TABLE') )
            $this->cap_key = CUSTOM_CAPABILITIES_TABLE;
        if ( ! is_array( $this->caps ) )
            $this->caps = array();
        $this->get_role_caps();
    }

Finally, I must set a constant 'CUSTOM_CAPABILITIES_TABLE' in wp-config.php.

http://codex.wordpress.org/Editing_wp-config.php#Custom_User_and_Usermeta_Tables

Change History (2)

comment:1 westi4 years ago

Capabilities are designed to work on a per blog implementation not a shared table.

The idea is that when using these defines the users are shared but the users have to be given the caps on a per-install basis so that you don't have to have the same capabilities across the sharing installs for all users.

comment:2 nacin21 months ago

  • Component changed from Database to Role/Capability
  • Milestone Future Release deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.