0

I modified the default Wordpress registration page to include a role and also payment fields. I am adding a Gold Member feature the my website, which requires payment.

I'd like it that after this user makes a payment and it is approved, he gets redirected back to the home page. I'm using the registration_errors filter to achieve this. This is not working, the user is instead redirected back to the wp-login page with a successful message on top.

Additionally, the wp_update_user function is not working either; the user is added to the db with the default role - Subscriber. How do I pass the user_id in here? Or, should I do this in another place.

function process_payment($errors, $sanitized_user_login, $user_email) {

if ( $errors->get_error_code() ) return $errors;

global $tran;

if($tran->Process()) {
    $approved = $tran->authcode;
    add_filter('registration_redirect', 'gold_login_redirect');
            wp_update_user( array ('ID' => $user_id, 'role' => 'gold_member') ) ;

} else {
    $errors->add( 'fidelipay_response', __('<strong>Declined</strong>:'. $tran->result . '<br/>' . $tran->error . '<br/>' . $tran->cvv2_result . '<br/>' ,'mysite.com') );
        if($tran->curlerror) {
            $errors->add( 'fidelipay_response', __('<strong>Reason</strong>:' . $tran->curlerror, 'mysite.com'));   
            return $errors; 
        }
        return $errors;                                                         
}
  return $errors;
}

add_filter('registration_errors', 'process_payment', 10, 3);

function gold_login_redirect() {
     return home_url('?role=gold_member');
}       

1 Answer 1

1

You can use wp_redirect function (Codex) at any point where you want to redirect the user:

wp_redirect( home_url() ); exit;
2
  • Thanks, the redirection worked, but the user didn't get entered into the db.
    – MF1
    Commented Apr 17, 2013 at 0:50
  • @MF1 here's what the doc says: To create a new user, use wp_insert_user() instead. Commented Apr 17, 2013 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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