The following snippet will let you share databases between two domains in WordPress.
Install the second WP as normal into the same database as the original with a DIFFERENT table prefix. Activate the theme you want to use.
In wp-config:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | define('CUSTOM_CAPABILITIES_PREFIX', 'wp_'); define('CUSTOM_USER_TABLE', 'wp_users'); define('CUSTOM_USER_META_TABLE', 'wp_usermeta'); In wp-includes/capabilities.php: /** * Set up capability object properties. * * Will set the value for the 'cap_key' property to current database table * prefix, followed by 'capabilities'. Will then check to see if the * property matching the 'cap_key' exists and is an array. If so, it will be * used. * * @since 2.1.0 * * @param string $cap_key Optional capability key * @access protected */ function _init_caps( $cap_key = '' ) { global $wpdb; if ( empty($cap_key) ) if (defined ('CUSTOM_CAPABILITIES_PREFIX')) { $this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities'; } else { $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(); } In the active theme's functions.php: function table_prefix_switch() { global $wpdb; $options = $wpdb->options; //Save the site 2 options table $wpdb->set_prefix('wp_'); //The prefix to site 1 $wpdb->options = $options; //Put the options table back } add_action('init', 'table_prefix_switch'); |
Snippet Source/Credit: WordPress.org