반응형
코어 php 코드로 워드프레스 데이터베이스에 액세스할 수 있는 방법이 있습니까?
내가 달성하고자 하는 것: PHP 데이터베이스와 WordPress 데이터베이스에 데이터 저장
예를 들어, 두 개의 데이터베이스가 있습니다. A는 corephp 사이트용이고 B는 wp 사이트용입니다.이제 사용자가 corephp 사이트를 통해 등록할 때, A 데이터베이스에 항목이 생성되고, WP용이며, 어떻게 지금 당장 corephp 사이트에 연결되지 않은 동일한 사용자 항목을 B 데이터베이스에 추가해야 하는지도 문제 없습니다.
두 사이트를 모두 연결하는 이유는 제 WP 사이트에 woocommerce 구독 구매가 표시되어 있고 어떤 사용자가 어떤 멤버십 구독에 등록되어 있는지 확인하려면 WP 데이터베이스에 해당 사용자 데이터가 있어야 하기 때문입니다.
업데이트된 코드:
$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']);
}
}
네, 이룰 수 있습니다.'wp-config'를 포함해야 합니다.php' 및 'wp-load'.핵심 php 프로젝트에서 'php'.그런 다음 WordPress 함수 'wp_create_user'를 호출하여 WordPress 데이터베이스에 새 사용자 데이터를 삽입해야 합니다.
자세한 내용은.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' );
}
언급URL : https://stackoverflow.com/questions/56717336/is-there-any-way-to-access-wordpress-database-in-core-php-code
반응형
'source' 카테고리의 다른 글
참조로 새 반환 값을 할당하는 것은 더 이상 권장되지 않습니다. (0) | 2023.07.31 |
---|---|
버튼에서 png 색상 변경 - ios (0) | 2023.07.31 |
네이티브 SQL 준비 문을 사용하여 열 이름을 준비하는 방법 (0) | 2023.07.31 |
C#에서 문자열을 유형으로 변환 (0) | 2023.07.31 |
Oracle SQL Developer와 비교하여 더 나은 툴이 있습니까? (0) | 2023.07.31 |