Home  >  Article  >  CMS Tutorial  >  How to communicate data between two wordpresses

How to communicate data between two wordpresses

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-07-15 14:36:033199browse

How to communicate data between two wordpresses

First of all, find the data table prefix of the main station. It must be that station A is established first, and then the second station B is established. Station B wants to share the users of station A, then Open the wp_config.php file of station B, and then insert the following code:

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

This place must be copied directly to avoid character errors. Copy it to a location with the same format, and then the data users will be common, but use A When logging in to Station B with your website account, you will see this prompt:

How to communicate data between two wordpresses

Related recommendations: "WordPress Tutorial"

This requires two steps , the first step is to execute the following statement in phpmyadmin:

INSERT INTO `dbname`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES 
(NULL, '1', 'wpen_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');

The second step is to make a plug-in, the specific code is as follows:

<?php
/**
* @package user
* @version 1.6
*/
/*
Plugin Name: userdb
Description: 解决多wp网站用户共享,大杭州虹雅居原创插件,by:然子.
Version: 1.6
Author URI: https://www.jinshare.cn/
*/
//设置主站的前缀,其它网站都共享该网站的用户数据表
//添加功能到用户注册的钩子里
$main_prefix = &#39;wp_&#39;;
//设置子站的前缀,例如有两个子站,前缀分别为wpen_和wpcn_
$addi_prefixs = array(&#39;as_&#39;);
//添加功能到用户注册的钩子里
add_action( &#39;user_register&#39;, &#39;dup_capabilities&#39; );
function dup_capabilities( $user_id ) {
global $main_prefix, $addi_prefixs;
//获取该用户权限的值,因为不同角色的值是不同的
if( $cap_val = get_user_meta( $user_id, $main_prefix.&#39;capabilities&#39;, true ) ) {
if( count( $addi_prefixs ) > 0 ) {
foreach( $addi_prefixs as $prefix ) {
add_user_meta( $user_id, $prefix.&#39;capabilities&#39;, $cap_val, true );
}
}
}
}
?>

Completely copy and save as userdb.php and then upload the plug-in directory Just enable it.

The above is the detailed content of How to communicate data between two wordpresses. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn