WordPress.org

Forums

Simple Facebook Connect
[resolved] Simple Facebook Connect add oAuth Variables - birthday (8 posts)

  1. ixthus27
    Member
    Posted 3 years ago #

    I have the Simple Facebook Connect installed and I'm using nearly all the features. LOVE IT.

    How do I add an other variable for permission? I want to be able to access birthday and that is not standard. How can I add that to the registration permission during authorization?

    http://wordpress.org/extend/plugins/simple-facebook-connect/

  2. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    There was no good way to do this before, but I just added the necessary hook to the trunk code, so here's how you can do it with that code.

    First, you need to add the birthday field to the registration form. You'd do that like so:

    add_filter('sfc_register_fields','add_birthday');
    function add_birthday($fields) {
      $fields[] = array('name'=>'birthday');
      return $fields;
    }

    That adds the birthday field. You can also add 'view'=>'prefilled' to that array to make it only show up for people registering with FB credentials and not to people registering without them.

    Next, you need to get the birthday information and save it somewhere when they submit the form. I added the sfc_register_request action to allow for that.

    add_action('sfc_register_request','get_birthday');
    function get_birthday($info) {
      global $saved_birthday;
      if (!empty($info['birthday'])) $saved_birthday = $info['birthday'];
    }

    Finally, you need to save the birthday with the user's account somehow. SFC's register function doesn't actually create users, it lets WordPress do that normally. So you can hook into the normal WP user_register hook to take the necessary action.

    add_action('user_register','save_birthday');
    function save_birthday($userid) {
      global $saved_birthday;
      if ($userid && !empty($saved_birthday) ) {
        update_usermeta($userid, 'birthday', $saved_birthday);
      }
    }

    Something similar to that will do the job.

  3. ChuckLin1
    Member
    Posted 3 years ago #

    Hey Otto,

    Thanks so much for this excellent plugin. I need to add fields and validation to the registration form to confirm that users are over the age of 13 but have not been able to get this working on WP 3.3, using the latest version of SWC.

    The code above is not working to add the fields. This should be done in sfc-register.php, correct? I added the actions and fields after the functions but still no dice.

  4. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    No, that code should not be in sfc-register.php. It should be in your own plugin or theme's functions.php code.

  5. scottmey
    Member
    Posted 3 years ago #

    Hey Otto ~

    Would it be possible to use the same approach to store the auth token?

    Cheers

  6. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 3 years ago #

    The auth token is already stored as part of the usermeta on login.

  7. scottmey
    Member
    Posted 3 years ago #

    Okay great. Buying you a beer dude!

  8. ndenitto
    Member
    Posted 3 years ago #

    Hi Otto: Thanks for the cool plugin.

    I am calling your code in a script this way:

    $fb_graphdata = sfc_remote($fb_cookie['user_id'], '', $fb_args_array, 'GET');

    Where $fb_args_array is a list (just name and email). Can I add user_birthday to this query somehow? I've been having trouble requesting that data in tandem with your code when used in this way.

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic