我在Yext.com上配置了web-hook。并且在创建/修改位置时触发。我将这些数据发布到我的WordPress插件文件http://example.com/wp-content/plugins/plugin-name/plugin-file.php
。我以这种方式存储请求数据:
$webhook_posted_json = file_get_contents('php://input');
$location_info = json_decode($webhook_posted_json, true);
我在yext.com上以json格式更新/创建位置信息时获取数据,然后我对其进行解码。
现在我将数据存储在变量中,如下所示:
$location_name = $location_info[location][locationName]; // Get Location Name
$location_email = $location_info[location][emails][0]; // Get primary contact email
以下是创建新用户的主要部分:我的问题是用户未注册以下代码。你知道它为什么不触发吗?
$the_user_id = 0;
// Check if user exist or not!
if ( !function_exists( 'get_user_by' ) ) {
require_once ABSPATH . WPINC . '/pluggable.php';
}
if ( username_exists( $location_name ) ){
$the_user = get_user_by('login', $location_name);
$the_user_id = $the_user->ID;
}
else{
$the_user_id = 0;
}
if ( !function_exists( 'wp_insert_user' ) ) {
require_once ABSPATH . WPINC . '/user.php';
}
$password = wp_generate_password();
// An array, object, or WP_User object of user data arguments.
$userdata = array(
'ID' => $the_user_id,
'user_pass' => $password,
'user_login' => $location_name,
'user_email' => $location_email,
'role' => 'editor'
);
// NOTICE! Understand what this does before running.
$result = wp_insert_user($userdata);
当我访问http://example.com/wp-content/plugins/plugin-name/plugin-file.php
时,我发现致命错误:Fatal error: require_once(): Failed opening required 'ABSPATHWPINC/pluggable.php'
。
有人可以帮我解决如何处理webhook并根据数据创建新用户的问题吗?