суботу, 27 квітня 2013 р.

Несколько WordPress сайтов с единой базой пользователей

Необходимо в файл wp-config добавить в конец (перед /* Это всё, дальше не редактируем. Успехов! */):

define('CUSTOM_CAPABILITIES_PREFIX', 'wp_');
define('CUSTOM_USER_TABLE', 'wp_users');
define('CUSTOM_USER_META_TABLE', 'wp_usermeta');

в wp-includes/capabilities.php обновить функцию _init_caps(...):

    /**
     * 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();
    }

В файл 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');

Немає коментарів:

Дописати коментар

HyperComments for Blogger

comments powered by HyperComments