admin管理员组文章数量:1026156
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);
}
}
Share
Improve this question
edited Apr 3, 2019 at 18:01
Wordpress Learner
asked Apr 3, 2019 at 17:23
Wordpress LearnerWordpress Learner
1092 bronze badges
7
- 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 Commented Apr 3, 2019 at 17:37
- Where you have define('user_register ... Do you mean to have, add_action( ... ? – tmdesigned Commented Apr 3, 2019 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 Commented Apr 3, 2019 at 18:02
- Also, what is $query on your last line? – tmdesigned Commented Apr 3, 2019 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 Commented Apr 3, 2019 at 18:04
1 Answer
Reset to default 0What 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.
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);
}
}
Share
Improve this question
edited Apr 3, 2019 at 18:01
Wordpress Learner
asked Apr 3, 2019 at 17:23
Wordpress LearnerWordpress Learner
1092 bronze badges
7
- 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 Commented Apr 3, 2019 at 17:37
- Where you have define('user_register ... Do you mean to have, add_action( ... ? – tmdesigned Commented Apr 3, 2019 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 Commented Apr 3, 2019 at 18:02
- Also, what is $query on your last line? – tmdesigned Commented Apr 3, 2019 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 Commented Apr 3, 2019 at 18:04
1 Answer
Reset to default 0What 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.
本文标签: hooksProblem in plugin debuging in wordpress
版权声明:本文标题:hooks - Problem in plugin debuging in wordpress 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745630912a2160158.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论