简体   繁体   English

有什么办法可以在核心php代码中访问WordPress数据库

[英]Is there any way to access WordPress database in core php code

What I am trying to achieve: Store data into PHP database and WordPress database我想要实现的目标:将数据存储到 PHP 数据库和 WordPress 数据库中

for example, there are two databases, A is for corephp site and B is for wp site.比如有两个数据库,A是corephp站点,B是wp站点。 Now when a user registers through corephp site, the entry is made in database A fine, along with that how should I make the same user entry into database B as well which is for WP, and not connected to corephp site anyhow right now.现在,当用户通过 corephp 站点注册时,该条目在数据库 A 中很好,以及我应该如何将相同的用户条目也输入到数据库 B 中,这是用于 WP 的,并且现在无论如何都没有连接到 corephp 站点。

Reason to connect both sites is, my WP site shows the woocommerce subscription purchases and I need to have that user data in WP database to see which user is registered with which membership subscription.连接这两个站点的原因是,我的 WP 站点显示 woocommerce 订阅购买,我需要在 WP 数据库中有该用户数据才能查看哪个用户注册了哪个会员订阅。

updated code:更新代码:

$dir = getcwd().'/explore';
include $dir.'/wp-config.php';
include $dir.'/wp-load.php';
if ($f == 'register') {
    $register = Wo_RegisterUser($re_data, $in_code);
    if ($register === true) {
        wp_create_user($_POST['username'], $_POST['password'], $_POST['email']);
    }
}

Yes, you can achieve.是的,你可以实现。 you have need to include 'wp-config.php' and 'wp-load.php' in your core php project.您需要在核心 php 项目中包含“wp-config.php”和“wp-load.php”。 After that you have a need to call WordPress function 'wp_create_user' to insert new user data in the WordPress database.之后,您需要调用 WordPress 函数 'wp_create_user' 在 WordPress 数据库中插入新的用户数据。

for More details.更多细节。 https://developer.wordpress.org/reference/functions/wp_create_user/ https://developer.wordpress.org/reference/functions/wp_create_user/

//include 'wp-config.php' and 'wp-load.php' in your core php project. Make sure you are passing the correct url of these two files.
include '/wp-config.php';
include '/wp-load.php';

$user_id = username_exists( $user_name );

if ( ! $user_id && false == email_exists( $user_email ) ) {
    $random_password = wp_generate_password( $length = 12, $include_standard_special_chars = false );
    $user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
    $random_password = __( 'User already exists.  Password inherited.', 'textdomain' );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM