0

I'm using Gravity Forms User Registration add-on and need to remove the action that include the activate page.

In the add-on, the hook is called like this:

add_action( 'wp',        array( $this, 'maybe_activate_user' ) );

This is added inside a public function called init(), a method from GF_User_Registration class.

What I tried:

add_action('init', function () {
    remove_action('wp', ['GF_User_Registration', 'maybe_activate_user']);
});
4
  • 1
    The add-on uses $this, so you need to know and be able to access the object (i.e. class instance) in order to unhook the maybe_activate_user function. E.g. If they did $object = new GF_User_Registration;, then you would use remove_action( 'wp', [ $object, 'maybe_activate_user' ] ). But regarding how to find that class instance, you need to check the plugin forums/docs/codebase.
    – Sally CJ
    Sep 17, 2021 at 15:06
  • @SallyCJ the add-on use a static method called get_instance(). I tried run $object = \GF_User_Registration::get_instance(); and then remove_action('wp', [$object, 'maybe_activate_user']); but didn't have success. Sep 17, 2021 at 15:43
  • Try hooking on init with a greater number as the 3rd parameter, e.g. add_action( 'init', <your function>, 20 ). Or just hook your function on wp with a 1 priority - add_action( 'wp', <your function>, 1 ). That should work, if you're using the correct class instance.
    – Sally CJ
    Sep 17, 2021 at 16:45
  • 1
    Thanks @SallyCJ, add a greater number fix the problem. Sep 17, 2021 at 18:54

1 Answer 1

0

Problem solved!

add_action('init', function () {
    $object = \GF_User_Registration::get_instance();
    remove_action('wp', [$object, 'maybe_activate_user']);
}, 20);

Thanks SallyCJ for the tips!

Your Answer

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

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