Support

Account

Home Forums General Issues WordPress Advanced Custom Fields not showing for new members in site

Solved

WordPress Advanced Custom Fields not showing for new members in site

  • So, I’m neck deep in a site with a javascript game that I’ve taken over that is surprisingly built on WordPress. I’m using the “Facebook all” plugin to acquire new members to this site, and Advanced Custom Fields to keep track of the custom fields for the subscribers (things like “Rank”, “Score” etc. etc.)

    So, in a perfect world:

    Customer clicks the “Login with Facebook” button
    Customer approves to what Facebook will provide
    Customer is returned to the page (which has a javascript game built on it)
    As customer navigates through the page, the default custom values are updated to reflect their score in the game.
    The only way to get the javascript game to recognize the default custom values on the page would be to manually add a password to the customer, sign in to the back of WP (/wp-admin) and go to their Profile, and then hit UPDATE FIELDS.

    I was hoping that on the page that renders the game, I could put in the following code:

    if (get_field("rank","user_$author_id") == "") {
        update_field("rank","Cadet","user_$author_id"); 
        update_field("score",0,"user_$author_id");  
        update_field("ship",1,"user_$author_id");   
    }  

    However, I’m not so lucky. Any suggestions?

    • Elliot

    • December 13, 2013 at 10:57 am

    Hi @Vinnie Saletto

    For your code to work, a user must exist in the DB with an ID of $user_id. If the facebook plugin is not creating a WP user, I don’t think the code will work.

    It seems that using ACF for this part won’t help much, as you can’t edit the user in the backend anyway. Why not use native WP code like update_option to save . load the data into the wp_options table.

    If you know the facebook user ID, you can use this in the options_name to construct the data name such as:

    
    "{$facebookUserID}_rank"
    

    Hope that helps

    Thanks
    E

  • Hey, Elliot.

    Thanks for the quick response. I should have added some more code to my discussion. The “Facebook All” does create WP users. It really does a great job in filling out user names, websites, bio… all that stuff. What it doesn’t do, however, is attach the custom fields created by ACF that are related to that user.

    So, to get the user ID, I use this code in the header, so that I can acquire the “author ID” (this client is calling the “user” the “author”):

    	global $current_user;get_currentuserinfo();
    	$author_id = $current_user->ID;
    

    It seems simple enough. I’m enclosing a screenshot of the profile page to explain further:

    What the WordPress profile looks like

    Which, if we were using WordPress for anything more than just a back end for the site, would be fine. The user experience, however, is a little bit different:

    The actual user experience.

    So, my conundrum appears to be with step 3 as follows:

    1. Person logs in via Facebook for the first time
    2. A user in WordPress is created
    3. The custom fields need to be updated into the WP User’s profile.
    4. Gameplay ensues

    Any suggestions on how to achieve this, specifically?

    • Elliot

    • December 15, 2013 at 5:53 pm

    Hi @Vinnie Saletto

    If the user exists, then ACF can update the custom field value with the update_field function. Perhaps you just need to do some debugging of your code to make sure it is running and that all the parameters are correct?

    Thanks
    E

  • Thanks, E. I’ve decided to look at it from a different perspective, and found the problem was actually with the “Facebook all” plugin. It appears that they weren’t necessarily creating all meta info when creating the member. So, all it took was a few lines in the plugin to update_field all of those fields with default values. All is good.

    Thank you!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.