hooks - Problem in plugin debuging in wordpress

I want to save extra user fields in custom table after user register.In my plugin I added user_register hook and I am ch

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
 |  Show 2 more comments

1 Answer 1

Reset to default 0

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745630914a4637103.html

相关推荐

  • hooks - Problem in plugin debuging in wordpress

    I want to save extra user fields in custom table after user register.In my plugin I added user_register hook and I am ch

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信