• Resolved sovrgn

    (@sovrgn)


    Hi There: What I am trying to achieve; update the user virtual wallet with their tokens from the external DB

    I am able to pull across the user data. After looking through other threads on custom additional meta data, I found this code which you suggested for another user which also uses the $exlog_hook_action_authenticated

    function get_player_data($wp_user, $exlog_user_data) {

    $updated = update_user_meta( $wp_user, ‘lws_woovirtualwallet_amount’, $exlog_user_data[‘tokenscore’] );

    // Checking if added ok
    if ($updated) {
    error_log(‘Additional field added’);
    } else {
    error_log(‘Unable to add additional field’);
    }
    }

    add_action(‘exlog_hook_action_authenticated’, ‘get_player_data’, 10, 2);

    I’m not sure if I am doing this correctly, but I can confirm that the meta data entry ‘woovirtualwallet_amount” already exists in the wp_usermeta table, I am not sure if it is recognising the external DB ‘tokenscore’

    Can I do something as method 1 mentioned here: What I am trying to achieve: update the user virtual wallet with their tokens from the external DB

    or am I on the right path with pulling additional user data and assigning it to the meta?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author tbenyon

    (@tbenyon)

    Hey @sovrgn,

    If you’re not sure what data is coming through, my suggestion is that you start by logging the data you are receiving.

    Below I have added three lines of logs, two of which are just to help you find the results more easily in the log file.

    
    function get_player_data($wp_user, $exlog_user_data) {
        error_log(‘-------------EXLOG-START------------------’);
        error_log(var_export($exlog_user_data, true));
        $updated = update_user_meta( $wp_user, ‘lws_woovirtualwallet_amount’, $exlog_user_data[‘tokenscore’] );
    
        // Checking if added ok
        if ($updated) {
            error_log(‘Additional field added’);
        } else {
            error_log(‘Unable to add additional field’);
        }
        error_log(‘-------------EXLOG-END------------------’);
    }
    
    add_action(‘exlog_hook_action_authenticated’, ‘get_player_data’, 10, 2);
    

    It is worth noting that $exlog_user_data will pull all fields that are in the users table you setup in the settings and not additional tables.

    Start by checking the error logs and let me know if you see what you expected.

    Thanks,

    Tom

    Thread Starter sovrgn

    (@sovrgn)

    Hi Tom, thanks for the response. I responded last night, but it seem that the reply wasn’t sent through.

    I’ve used the above suggestion, and the error notice is for a missing Index, namely ‘tokenscore’ – I am not sure if Exlog can’t find the ‘tokenscore’ column.

    I have checked the WP_usermeta to verify that both ‘virtualwallet’ and ‘tokens’ exist for the user. I created this meta using PODS and tested it from the user profile page in the backend. It works, and creates the meta etc.

    Problem seems to be pulling the ‘tokenscore’ index. A bit stuck, so looked around at $WPDB, which may be an option.

    Plugin Author tbenyon

    (@tbenyon)

    Hey @sovrgn,

    I guess the important bit that I’m curious by in your logs is what would come from this:

    
        error_log(‘-------------EXLOG-START------------------’);
        error_log(var_export($exlog_user_data, true));
    

    That second line would output all available data from your users table that it received. Can you make sure that tokenscore is an available property at this point.

    If you can’t see it in there I speculate you’re either:

    • Not writing tokenscore correctly. Maybe it is something like token_score or tokenScore
    • tokenscore field does not exist in your users table in your database. Maybe it is in another table?

    Let me know,

    Thanks,

    Tom ??

    Thread Starter sovrgn

    (@sovrgn)

    Hi Tom,

    I get the ‘Unable to add additional field’ , and I double checked that tokenscore exists in the external DB and that the name corresponds correctly.

    here’s one for a new user:

    [09-Oct-2020 09:25:49 UTC] EXLOG-START
    [09-Oct-2020 09:25:49 UTC] array (
    ‘user_login’ => ‘newuser5’,
    ‘first_name’ => ”,
    ‘last_name’ => ”,
    ‘user_pass’ => ‘password’,
    ‘role’ => ‘subscriber’,
    ‘user_email’ => ‘[email protected]’,
    )
    [09-Oct-2020 09:25:49 UTC] PHP Notice: Undefined index: tokenscore in /home/server/website/wp-content/themes/theme-child/functions.php on line 6
    [09-Oct-2020 09:25:49 UTC] Unable to add additional field
    [09-Oct-2020 09:25:49 UTC] EXLOG-END

    So, i’m assuming it’s pulling the necessary data correctly, like the user name, email etc. but not recognizing the additional index in the external DB? Am I missing something on my end possibly?

    For example, do I need to include something extra for the tokenscore? i.e. table name or prefix something like wp_ ?

    Thread Starter sovrgn

    (@sovrgn)

    Hi Tom

    I was unable to pull the additional data using exlog_user_data(“column name”); but I found a workaround using wpdb to pull the additional meta data from the table.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pulling additional data’ is closed to new replies.