Having trouble storing the discord id after a user signs in with discord/wordpress

I can't seem to get the discord id of a user when they sign in. How would I do it?

Best Answer

  • Claude_SchlesserClaude_SchlesserAdministratorOneAll Team
    edited July 2020 Answer ✓

    Here a more complete action to save the Discord username, userid and discriminator:

    //Handle data retrieved from a social network profile
    function oa_social_login_store_extended_data ($user_data, $identity)
    {
        if ($identity->source->key == 'discord')
        {
            $account = array_shift($identity->accounts);
    
            if (isset ($account->username)
            {
                $parts = explode ('#', $account->username);
                if (count ($parts) == 2)
                {
                    update_user_meta ($user_data->ID, 'discord_username', $parts[0]);
                    update_user_meta ($user_data->ID, 'discord_discriminator', $parts[1]);
                }
                else
                {
                    update_user_meta ($user_data->ID, 'discord_username', $parts[0]);   
                }
            }
    
            if (isset ($account->userid)
            {
                update_user_meta ($user_data->ID, 'discord_userid, $account->userid);
            }
        }
    }
    
    //This action is called whenever Social Login adds a new user
    add_action ('oa_social_login_action_after_user_insert', 'oa_social_login_store_extended_data', 10, 2);
    

Answers

  • Claude_SchlesserClaude_SchlesserAdministratorOneAll Team
    edited July 2020

    Hello,

    you can use the following hook:
    http://docs.oneall.com/plugins/guide/social-login-wordpress/#3a

    And then a function like this:

    function oa_social_login_store_extended_data ($user_data, $identity)
    {
        if ($identity->source->key == 'discord')
        {
            if (preg_match ('#/([0-9]+)/#', $identity->id, $matches))
            {
                update_user_meta ($user_data->ID, 'discord_userid', $matches[1]);  
            }
        }
    }
    
    //This action is called whenever Social Login adds a new user
    add_action ('oa_social_login_action_after_user_insert', 'oa_social_login_store_extended_data', 10, 2);
    
  • Put your favorite characters in and get ready for nonstop action with no blocks
    Unblocked Games

  • I’ve recently noticed that my emails are going to spam more often than they should, and it’s starting to affect communication with clients. I know there are many possible reasons for this, like poor list hygiene, weak sender reputation, or even not having the proper authentication records set up (SPF, DKIM, DMARC). I’ve also heard that certain keywords in the subject line or body can trigger spam filters, so I’ve been trying to avoid those.

    While searching for solutions, I came across Mail Monitor, which offers services specifically focused on email deliverability. They seem to help with analyzing what’s causing deliverability problems and how to fix them. Has anyone here used their service or something similar?

  • When storing the Discord ID after WordPress/Discord login, ensure you’re hooking into the authentication callback and saving the ID as user meta with update_user_meta(). Sometimes issues occur if the Discord API response isn’t mapped correctly. Debug the returned data structure carefully. Similar to choosing the best painters in Edmonton, accuracy and reliability in setup matter most.

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.