Closed peter-tmann closed 1 year ago
@peter-tmann Can you speak to whether this kind of code is necessary on other WordPress objects, or if it's only needed on the user object?
(Related to issue #179, although I'm not sure how big the scope of that issue is vs how limited this fix is.)
This is only needed on the user object because the user table is the same across all sites in a Multisite installation and therefore needs to be accessed using the base prefix. For all other objects, wpdb->prefix will retrieve the correct table for the site in a Multisite installation.
The plugin is running with this modification on our Multisite installation and that was the only issue I came across so far.
@peter-tmann thank you. In that case, I suggest overwriting the array values that are different, rather than duplicating so much code. Like this:
$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',
),
);
// Check for Multisite installation. Sitewide User table uses base site prefix across all sites.
if ( is_multisite() ) {
$object_table_structure['content_table'] = $this->wpdb->base_prefix . 'users';
$object_table_structure['meta_table'] = $this->wpdb->base_prefix . 'usermeta';
}
Can you see if this works in your testing, and if it does, edit your pull request to that effect?
@jonathanstegall, Good point. I'll make the change on our site today and update the pull request if it tests OK.
@jonathanstegall, I updated and tested the code on our site and everything is working. I updated the file in my fork, so it's up to date for the pull request.
Added lines 209-230 to check for WP Multisite installation.
If it's a Multisite, then the 'user' object will be accessed using the 'wpdb->base_prefix' because the 'user' table is the same across all sites and just 'wpdb->prefix' does not work.
If it's not a Multisite, then the previous code executes.
What does this Pull Request do?
Adds WP Multisite compatibility for the 'user' object
How do I test this Pull Request?
Install the plugin on WP Multisite installation. Create a Fieldmap with the 'user' WordPress object (current version of plugin doesn't work at this point)