Your Ad Here

Posted By

lancemonotone on 08/02/11


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Kurt


Wordpress: Share database between different domains


 / Published in: PHP
 

URL: http://wordpress.org/support/topic/wordpress-25-share-users-table#post-904597

There are a few modifications to make to your WP files to share a single database between multiple installs on separate domains.

  1. 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.
  2.  
  3. Now edit these files...
  4.  
  5. In wp-config:
  6.  
  7. define('CUSTOM_CAPABILITIES_PREFIX', 'wp_');
  8. define('CUSTOM_USER_TABLE', 'wp_users');
  9. define('CUSTOM_USER_META_TABLE', 'wp_usermeta');
  10.  
  11. In wp-includes/capabilities.php:
  12. /**
  13. * Set up capability object properties.
  14. *
  15. * Will set the value for the 'cap_key' property to current database table
  16. * prefix, followed by 'capabilities'. Will then check to see if the
  17. * property matching the 'cap_key' exists and is an array. If so, it will be
  18. * used.
  19. *
  20. * @since 2.1.0
  21. *
  22. * @param string $cap_key Optional capability key
  23. * @access protected
  24. */
  25. function _init_caps( $cap_key = '' ) {
  26. global $wpdb;
  27. if ( empty($cap_key) )
  28. if (defined ('CUSTOM_CAPABILITIES_PREFIX')) {
  29. $this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities';
  30. } else {
  31. $this->cap_key = $wpdb->prefix . 'capabilities';
  32. }
  33. else
  34. $this->cap_key = $cap_key;
  35. $this->caps = &$this->{$this->cap_key};
  36. if ( ! is_array( $this->caps ) )
  37. $this->caps = array();
  38. $this->get_role_caps();
  39. }
  40.  
  41. In the active theme's functions.php:
  42. function table_prefix_switch() {
  43. global $wpdb;
  44. $options = $wpdb->options; //Save the site 2 options table
  45. $wpdb->set_prefix('wp_'); //The prefix to site 1
  46. $wpdb->options = $options; //Put the options table back
  47. }
  48. add_action('init', 'table_prefix_switch');

Report this snippet  

You need to login to post a comment.