I want to save extra user fields in custom table after user register.

In my plugin I added user_register hook and I am checking this code while user register but I cannot find any errors and cannot print the data.

How can I test this code and what if I want to print something here that will reflect on webpage?

I am new to plugin creation please help you good people.

Plugin Name: Bonus Point Calculator Plugin
Plugin URI: 
Description: This plugin adds reward points of user.
Version: 1.0
Author: Test (Dev Team)
Author URI: http://www.test.com
Author Email: support@test.com

  Copyright 2019 Test

define('THEMENAME', 'listingpro');
define('BONUSPOINTS_PLUGIN_PATH', plugin_dir_path(__FILE__));

add_action('user_register', 'rwdpoint_registration_save', 10, 1);

function rwdpoint_registration_save($user_id) {
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    $user_info = get_userdata($user_id);
    $username = $user_info->user_login;
    $useremail = $user_info->user_email;
    global $wpdb;
    $sql = $wpdb->insert('wp_userrewardpoints', array(
        'rwuserid ' => $user_id,
        'rwusername' => $username,
        'rwemail' => $useremail,
        'rwrewardpoint' => 10,
        'rwcreateddate' => date("Y-m-d H:i:s")
    ) , array(
    if ($sql === false) {
        return FALSE;
    else {
        return $wpdb->get_results($query);
  • I don't think I fully understand your question. Have you read up on how you can test plugins in general? What specific problem is it you're having with your current code? – kero Apr 3 at 17:37
  • Where you have define('user_register ... Do you mean to have, add_action( ... ? – tmdesigned Apr 3 at 18:01
  • I want to call rwdpoint_registration_save function after User register, but can't get in to the function with this hook 'user_register' – Wordpress Learner Apr 3 at 18:02
  • Also, what is $query on your last line? – tmdesigned Apr 3 at 18:03
  • yes please check i edited the line from define('user_register') to add_action('user_register').... it was my mistake – Wordpress Learner Apr 3 at 18:04

What I do, when I'm developing a plugin (or theme) on a local WordPress install and I'm feeling lazy, I just use a combination of

die; // exit; works too

This way I get an idea whats going on and I see when the variable stops being what I expect it to be.

Another thing I sometimes do is I use error_log( print_r( $my_variable, true ) ); inside functions to push stuff into the error log so that I can review it later.

Unfortunately I haven't worked that much with custom tables so I can't comment on those matters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.