0

I am trying to redirect a user once they click "activate" on my plugin, the redirect is working great using the register_activation_hook however the plugin is failing to activate.

Any thoughts on what i need to do to make it run the hook after activation and not before?

function install_redirect() {
wp_redirect('http://www.mydomain.com');exit;
}
register_activation_hook(__FILE__, 'install_redirect');

Thanks

1 Answer 1

1

From stackoverflow: https://stackoverflow.com/questions/2450510/redirect-after-plugin-activation

register_activation_hook(__FILE__, 'my_plugin_activate');
add_action('admin_init', 'my_plugin_redirect');

function my_plugin_activate() {
    add_option('my_plugin_do_activation_redirect', true);
}

function my_plugin_redirect() {
    if (get_option('my_plugin_do_activation_redirect', false)) {
        delete_option('my_plugin_do_activation_redirect');
        wp_redirect(MY_PLUGIN_SETTINGS_URL);
    }
}
0

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.