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.

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

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

From stackoverflow: http://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);
    }
}
share|improve this answer
    
Many thanks Rob –  Danny Feb 19 '12 at 23:34
add comment

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.