WP User Object not Working in Multi-Site
-
We are running WP Multi-Site and when I tried to create a user object fieldmap, none of the user fields were showing up to be able to map them. I checked /classes/class-object-sync-sf-wordpress.php and it was using the wpdb->prefix incorrectly. Multi-site uses the same user table across sites so it doesn’t have a site prefix like on the other tables. It needs to use the base prefix. I added an additional check for Multi-Site to the code and use the proper prefix in a Multi-Site environment. The plugin works correctly now and shows all the user fields on any subsite.
Here is what I modified on line 208 of /classes/class-object-sync-sf-wordpress.php:
// Check for Multisite installation. Sitewide User table uses base site prefix across all sites.
if ( is_multisite() ) {
$object_table_structure = array(
‘object_name’ => ‘user’,
‘content_methods’ => array(
‘create’ => ‘wp_insert_user’,
‘read’ => ‘get_user_by’,
‘update’ => ‘wp_update_user’,
‘delete’ => ‘wp_delete_user’,
‘match’ => ‘get_user_by’,
),
‘meta_methods’ => $user_meta_methods,
‘content_table’ => $this->wpdb->base_prefix . ‘users’,
‘id_field’ => ‘ID’,
‘meta_table’ => $this->wpdb->base_prefix . ‘usermeta’,
‘meta_join_field’ => ‘user_id’,
‘where’ => ”,
‘ignore_keys’ => array( // Keep it simple and avoid security risks.
‘user_pass’,
‘user_activation_key’,
‘session_tokens’,
),
);
} else {
$object_table_structure = array(
‘object_name’ => ‘user’,
‘content_methods’ => array(
‘create’ => ‘wp_insert_user’,
‘read’ => ‘get_user_by’,
‘update’ => ‘wp_update_user’,
‘delete’ => ‘wp_delete_user’,
‘match’ => ‘get_user_by’,
),
‘meta_methods’ => $user_meta_methods,
‘content_table’ => $this->wpdb->prefix . ‘users’,
‘id_field’ => ‘ID’,
‘meta_table’ => $this->wpdb->prefix . ‘usermeta’,
‘meta_join_field’ => ‘user_id’,
‘where’ => ”,
‘ignore_keys’ => array( // Keep it simple and avoid security risks.
‘user_pass’,
‘user_activation_key’,
‘session_tokens’,
),
);
}`
- The topic ‘WP User Object not Working in Multi-Site’ is closed to new replies.