Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to use the plugin Facebook-AWD plugin.

My site would provide two ways of registration (normal and register with Facebook). Users must select their role, ie: buyer and seller.

With normal registration, I can achieve this easily but if my users choose to register with Facebook-AWD they can't select between roles as the plugin is set up to register user with default role:

'role'=>get_option('default_role');

How can achieve this by adding a hook or action or filter to the plugin in order to preserve the plugin core for future update?

public function register_user()
{
    $username = sanitize_user($this->me['first_name'], true);
    $i = '';
    while (username_exists($username . $i)) {
        $i = absint($i);
        $i++;
    }
    $username = $username . $i;
    $userdata = array(
        'user_pass' => wp_generate_password(), 
        'user_login' => $username, 
        'user_nicename' => $username, 
        'user_email' => $this->me['email'], 
        'display_name' => $this->me['name'], 
        'nickname' => $username, 
        'first_name' => $this->me['first_name'], 
        'last_name' => $this->me['last_name'], 
        'role' => get_option('default_role')
    );
    $userdata = apply_filters('AWD_facebook_register_userdata', $userdata);
    $new_user = wp_insert_user($userdata);
    //Test the creation                         
    if (isset($new_user->errors)) {
        wp_die($this->Debug($new_user->errors));
    }
    if (is_int($new_user)) {
        //send email new registration
        wp_new_user_notification($new_user, $userdata['user_pass']);
        return $new_user;
    }

    return false;
}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

The plugin offers an entry point for this manipulation:

$userdata = apply_filters('AWD_facebook_register_userdata', $userdata);

So, now it's a matter of you filling up the fictional function in this example:

add_filter( 'AWD_facebook_register_userdata', 'user_role_wpse_87863', 10, 1 );

function user_role_wpse_87863 ( $userdata )
{
    $userdata['role'] = your_way_of_getting_the_role();

    return $userdata;
}

Related:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.