SteamID hook with plugin

edited March 2016 in Questions
Would love some help with this please. I want to obtain the steamID of a user when they log in to my wordpress site. The plugin itself works great btw.

I used this guide in point 3.1 to add a hook in my functions.php file:
(https://docs.oneall.com/plugins/guide/social-login-wordpress/)

Below is my function

function oa_social_login_store_extended_data ($user_data, $identity)
{
update_user_meta ($user_data->id, 'steamid', $identity->steamid);
}

Is the bold code above correct for the steamid contained within $identity? Or does the steam ID not exist in $identity?

Also I have created a column in wp_users for this field 'steamid'

Best Answer

  • Fred_PinelFred_PinelMember
    Answer ✓
    Hi,
    The $identity->steamid won't work. The steamid is located in $identity->accounts, which is an array of account objects.
    Maybe you can try the following code (in your theme's functions.php).

    function oasl_steamid ($user_data, $identity) { $steamid = array_reduce ($identity->accounts, function ($id, $acc) { return (stripos ($acc->domain, 'steam') !== false and !empty ($acc->userid)) ? $acc->userid : NULL; }); if (isset ($steamid)) { update_user_meta ($user_data->ID, 'steamid', $steamid); } } add_action ('oa_social_login_action_after_user_insert', 'oasl_steamid', 10, 2);
    Regards

    Welcome!

    Please sign in to your OneAll account to ask a new question or to contribute to the discussions.

    Please click on the link below to connect to the forum with your OneAll account.