0

When I try to use profile_update hook inside a class the callback function is not called.

public function __construct() {
  add_action('profile_update', array( $this, 'user_profile_update', 10, 2) );
}
function user_profile_update( $user_id, $old_user_data ) {
  die(var_dump($old_user_data));
}    

Outside the class the callback function works correctly.

1

Careful where you are placing your brackets.

The hook should look like;

add_action('profile_update', array( $this, 'user_profile_update' ), 10, 2 );

Note the close bracket after the method name

0

It's working:

public function __construct() {
    add_action( 'profile_update', array( &$this, 'user_profile_update' ), 10, 2 );
}

public function user_profile_update( $user_id, $old_user_data ) {
    die( var_dump( $old_user_data ) );
}
4
  • Please explain why.
    – Max Yudin
    Oct 9 '17 at 12:41
  • priority and accepted_args fixed. Oct 9 '17 at 13:03
  • Please, edit your answer. Otherwise it does not seems to be useful.
    – Max Yudin
    Oct 9 '17 at 13:08
  • 10, 2 is not valid in question. check exactly. Oct 9 '17 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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