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.
<?php
/*
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:
Author Email: [email protected]
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);
error_reporting(E_ALL);
$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(
'%d',
'%s',
'%s',
'%d',
'%s'
));
if ($sql === false) {
return FALSE;
}
else {
return $wpdb->get_results($query);
}
}
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.
<?php
/*
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
Author Email: [email protected]
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);
error_reporting(E_ALL);
$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(
'%d',
'%s',
'%s',
'%d',
'%s'
));
if ($sql === false) {
return FALSE;
}
else {
return $wpdb->get_results($query);
}
}
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
var_dump($my_variable);
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.