Reputation: 73
I have defined a custom user table in my wp-config.
define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');
But, when i try to print out the logged in user info, user_level seems to be missing and the roles is empty. Any idea?
Any help is appreciated!!!!
Upvotes: 1
Views: 4913
Reputation: 43
Had the same issue recently and have a solution that works. We had a multisite but moved to sprat installs using subfolders for caching reasons (W3 Total Cache broke our multisite).
So we defined the user tables in wpconfig
and we user wp_
for our main and wp_2_
for the second and this function in the theme function file worked:
add_action('set_current_user', '_super_set_current_user', 10);
function _super_set_current_user()
{
$user_id = get_current_user_id();
if($user_id==0){ return;}
$metadats = array('wp_capabilities' => 'wp_2_capabilities','wp_user_level' => 'wp_2_user_level');
$x = get_user_meta( $user_id, 'wp_2_capabilities', true );
// Update user meta
if ( !is_array( $x ) )
{
foreach($metadats as $s1 => $s2)
{
$v = get_user_meta( $user_id, $s1, true );
update_user_meta($user_id, $s2, $v);
}
}
return true;
}
So this fetches the wp_
user settings from the old site and then converts them to the new site and just adds the meta data for the user but only if it does not exist.
Upvotes: 0
Reputation: 3637
If you are using only a single users table for multiple WordPress installations, WordPress will only generate the user role for the WordPress installation that you create the user on.
So, if you create john_doe
on site1
, john_doe
will be assigned a user role on site1
(be it administrator, editor, author, etc), but site2
will not assign john_doe
a user role. This is known as an "orphaned role." When john_doe
logs into site2
, he will receive a You do not have sufficient permissions to access this page
error message.
So, you can either manually add the role into the usermeta database, or have an admin update the user's role for that installation, or finally you can use a plugin. I found a plugin that makes managing orphaned user roles much easier. It is called WP-Orphanage Extended.
I also created a video screencast explaining the whole issue, and showing how to use a single users table for multiple WordPress sites. You can find it here: http://mikemclin.net/single-users-table-multiple-wordpress-sites/
Upvotes: 4
Reputation: 6662
user roles are stored in wp_options
with option_name: wp_user_roles
Does that exist, or is it empty?
Are all your tables prefixed with 'wp_
'?
if so.
In wp_usermeta
you have to set meta_key: wp_user_level
Also check meta_key wp_capabilities
Upvotes: 0