最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

hooks - Problem in plugin debuging in wordpress

matteradmin6PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far