为什么 SimplyBook API addClient 功能不起作用?错误日志显示“客户端名称值错误”

问题描述 投票:0回答:1

我正在尝试使用 JSONRCP 将客户端添加到 SimplyBook 系统。当使用 UserRegistration 插件构建的注册表单将新用户作为订阅者添加到 Wordpress 时,会调用此函数。

当用户尝试注册时,它会挂起,然后抛出错误“客户端名称错误”。我尝试过对一些虚拟数据进行硬编码,这确实有效。所以看来使用函数从数据库获取数据有问题

"$first_name = get_user_meta($user_id, 'first_name', true);"

任何关于我可能做错的事情的建议将非常感激!

/* Function to run when a new user is created */
function sync_user_created($user_id) {

    $user_id = reset($user)->ID;

    // Get user data
    $user_info = get_userdata($user_id);

    // Check if the user has the role of 'subscriber'
    if (in_array('subscriber', $user_info->roles)) {

        $first_name = get_user_meta($user_id, 'first_name', true);
        $user_email = get_userdata($user_id, 'user_email');
        $user_phone = get_user_meta($user_id, 'phone', true);

        // authenticate connection - this function works
        $JsonRcpClient = SimplyBookAdminAuth();
    
        $clientData = array(
            'name' => $first_name,
            'email' => $user_email,
            'phone' => $user_p  hone
        );

        // add the new client to SimplyBook database - don't send an email
        $JsonRcpClient->addClient($clientData, false);
    
    }

}
// hook into new user registration
add_action('user_register', 'sync_user_created');

我从用户注册日志中收到的错误是:

2024-10-18T13:05:18+01:00 CRITICAL Uncaught Exception: Request error: Client name value is wrong in C:\wamp64\www\Gruffs\wp-content\themes\understrap-child\includes\JsonRpcClient.php:57Stack trace:#0 C:\wamp64\www\Gruffs\wp-content\themes\understrap-child\includes\sb_client_sync.php(35): JsonRpcClient->_call('addClient', Array)#1 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(326): sync_user_created('861')#2 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)#3 C:\wamp64\www\Gruffs\wp-includes\plugin.php(517): WP_Hook->do_action(Array)#4 C:\wamp64\www\Gruffs\wp-includes\meta.php(336): do_action('updated_user_me...', '861', 50, 'first_name', 'Adam')#5 C:\wamp64\www\Gruffs\wp-includes\user.php(1217): update_metadata('user', 50, 'first_name', 'Adam', '')#6 C:\wamp64\www\Gruffs\wp-content\plugins\user-registration\includes\frontend\class-ur-frontend-form-handler.php(253): update_user_meta(50, 'first_name', 'Adam')#7 C:\wamp64\www\Gruffs\wp-content\plugins\user-registration\includes\frontend\class-ur-frontend-form-handler.php(123): UR_Frontend_Form_Handler::ur_update_user_meta(50, Array, 167)#8 C:\wamp64\www\Gruffs\wp-content\plugins\user-registration\includes\class-ur-ajax.php(296): UR_Frontend_Form_Handler::handle_form(Array, 167)#9 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(324): UR_AJAX::user_form_submit('')#10 C:\wamp64\www\Gruffs\wp-includes\class-wp-hook.php(348): WP_Hook->apply_filters('', Array)#11 C:\wamp64\www\Gruffs\wp-includes\plugin.php(517): WP_Hook->do_action(Array)#12 C:\wamp64\www\Gruffs\wp-admin\admin-ajax.php(207): do_action('wp_ajax_nopriv...')#13 {main}thrown in C:\wamp64\www\Gruffs\wp-content\themes\understrap-child\includes\JsonRpcClient.php on line 57
php ajax wordpress user-registration
1个回答
0
投票

感谢您的帮助。我最终确实弄清楚了这一点。这是工作功能的代码。我使用了错误的钩子,代码中的一些错误也需要修复。使用 UserRegistration 插件时使用的钩子是下面的钩子,而不是“user_register”。

/* Function to run when a new user is created */
function sync_user_created( $valid_form_data, $form_id, $user_id ) {

    // Get user data
    $user_info = get_userdata($user_id);

    // Check if the user has the role of 'subscriber'
    if (in_array('subscriber', $user_info->roles)) {

        $first_name = get_user_meta($user_id, 'first_name', true);
        $last_name = get_user_meta($user_id, 'last_name', true);
        $user_email = get_userdata($user_id)->user_email;
        $user_phone = get_user_meta($user_id, 'user_registration_phone_number', true);

        // authenticate connection - this function works
        $JsonRcpClient = SimplyBookAdminAuth();
        
        $clientData = array(
            'name' => $first_name . ' ' . $last_name,
            'email' => $user_email,
            'phone' => $user_phone
        );

        // add the new client to SimplyBook database - don't send an email
        $JsonRcpClient->addClient($clientData, false);
        
    }
    
}
// hook into new user registration when UserRegistration form is used
add_action('user_registration_after_register_user_action', 'sync_user_created', 10, 3);

希望能帮助其他遇到此问题的人。

© www.soinside.com 2019 - 2024. All rights reserved.