Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect after plugin activation

Tags:

wordpress

How do I redirect users to my plugin settings page after they activate my plugin, I tried

register_activation_hook(__FILE__,'activate_myplugin');
function activate_myplugin()
{
//create and populate DB tables
wp_redirect(plugin_setting_url);
}

but it does not work.

like image 439
Pragati Sureka Avatar asked Mar 15 '10 21:03

Pragati Sureka


People also ask

How do I setup a redirection plugin?

Setting Up Manual RedirectsGo to Tools > Redirection and scroll down to the Add new redirection section. In the Source URL field, type or paste in the URL you want to redirect from. In the Target URL field, type or paste in the URL you want to redirect to.

How do I redirect a WordPress plugin?

Activate the plugin. Go to 'Settings' in the WordPress admin menu and then click on 'Website Redirect'. Enter the URL you want to redirect the site to, set the desired redirection type, set the status to 'Enabled' and save your changes!

What is a redirect plugin?

Redirect plugins will ensure that any broken links point to another relevant page on your WordPress website. That way, if a visitor clicks on a broken link, they'll simply be redirected to a new location where they can continue browsing.

How do I activate a plugin?

On the left-side menu, select Plugins > Installed Plugins. Find the plugin you want to activate and select Activate. Note: If you can't find the plugin in the plugin list, it may be because it's not installed yet. You should install the plugin first to be able to activate it.


1 Answers

You should be able to do something like this:

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);
    }
}
like image 169
Richard M Avatar answered Sep 29 '22 07:09

Richard M