Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A plugin to share users and usermeta tables between independent WordPress installations. This plugin requires CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE defined into wp-config file
* @package Kinsta_Share_Users
* @version 1.0
Plugin Name: Kinsta Share Users
Plugin URI:
Description: This is an example plugin for Kinsta blog readers
Author: Carlo Daniele
Version: 1.0
Author URI:
* Duplicate {$pref}_capabilities and {$pref}_user_level rows in {$pref}_usermeta table
* @param int $user_id The user ID.
* @param string $role The new role.
* @param array $old_roles An array of the user's previous roles.
* @link
* @link
function ksu_save_role( $user_id, $role ) {
// Site 1
// Change value if needed
$prefix_1 = 'first_';
// Site 2 prefix
// Change value if needed
$prefix_2 = 'second_';
$caps = get_user_meta( $user_id, $prefix_1 . 'capabilities', true );
$level = get_user_meta( $user_id, $prefix_1 . 'user_level', true );
if ( $caps ){
update_user_meta( $user_id, $prefix_2 . 'capabilities', $caps );
if ( $level ){
update_user_meta( $user_id, $prefix_2 . 'user_level', $level );
add_action( 'set_user_role', 'ksu_save_role', 10, 2 );
Copy link

rosshaydock commented Apr 29, 2019


I have implemented this on my wordpress sites and would like to know if there is any way that i can now setup a single sign on between two wordpress sites on the same domain which are not multisite. Do you know if this is possible and if so how.


Copy link

tosinamuda commented Aug 21, 2020

Copy link

eorama commented Sep 18, 2020

When there are more than two sites to connect, an "or" is performed within the "If"
if ( $caps ){ update_user_meta( $user_id, $prefix_2 . 'capabilities', $caps ); "or" update_user_meta( $user_id, $prefix_3 . 'capabilities', $caps ); "or" update_user_meta( $user_id, $prefix_4 . 'capabilities', $caps ); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment