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.

For some context, we're building an activation system for new users of an app using WordPress as a framework. We've got a plugin driving most of our interactions, where all of this code resides.

When a new user signs up, they are sent an activate link via email, which when clicked, sends them to an activate page. When they save their details, we want to create the user with appropriate meta data, and redirect them to a custom routing template that shoots them off to their personal subsite.

We have the username and password of the newly created user available to us, so we can use wp_signon(). We've got a Registration_Model class that is instantiated somewhere else. Our class method to start the sign in process is where I believe we want to call add_action.

public function sign_user_in() {
    add_action( 'init', array( $this, 'auto_sign_in') );
}

Our method to process the sign-in is below, but be aware, I've tested out the function to see if the action is even being cued by WordPress by echoing a string, which does nothing.

public function auto_sign_in()
{
    // if ( ! is_user_logged_in() ) {

         //determine WordPress user account to impersonate
         $creds = array();
         $creds['user_login'] = $this->user->email;
         $creds['user_password']  = $this->user->password->one;
         $creds['remember'] = true;
         $user = wp_signon( $creds, false );
         if ( is_wp_error( $user ) ) {
             echo $user->get_error_message();
         } else {
             wp_redirect('/_router/'); exit;
         }
     }
}

It really appears that I'm stuck on the action not being run, or something. Can the add_action be run from somewhere other than the class constructor? Any and all advice or help is appreciated.

EDIT

I've adjusted the function to use $this instead of __CLASS__, although we still get nothing when hooking into 'init'. Just as a test, I've used the absolute last hook that fires, 'shutdown', and I can echo a test string to the browser using it. So I know that there's a whole bunch of operations loading, so I probably need to move the add_action somewhere else so it fires earlier.

share|improve this question
    
where/when is sign_user_in called? –  Milo Jan 30 '13 at 18:07
    
sign_user_in is called in a private static function in the controller class. –  ToddSmithSalter Jan 30 '13 at 20:05

2 Answers 2

Have you tried

add_action( 'init', array( $this, 'auto_sign_in') );

__CLASS__ returns the class name, not the class instance, so it only works for static functions.

share|improve this answer
    
Please explain why that could solve the problem. –  toscho Jan 30 '13 at 18:55
    
__CLASS__ returns the class name, not the class instance, so it only works for static functions. –  vancoder Jan 30 '13 at 19:07
    
What I meant was: Explain it in your answer, not in a comment. :) –  toscho Jan 30 '13 at 19:09
    
Sorry, I'm a newbie. –  vancoder Jan 30 '13 at 19:12
    
Welcome to WordPress Stack Exchange! –  toscho Jan 30 '13 at 19:15

__CLASS__ should be $this in your add_action call. I think __CLASS__ is only used if the function is static

share|improve this answer
1  
Please, &$this is PHP 4. It is just $this nowadays. :) –  toscho Jan 30 '13 at 18:57
    
@toscho thanks for the tip! –  Manny Fleurmond Jan 30 '13 at 19:00

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.