Refresh or redirect page after activate my plugin

I'm quite newbie in PHP and plugin development, and I think I'm missing something obvious but I dont know how to do it.

When I activate my plugin (it adds some menu items), everything it's ok except I have to refresh the page to see those items, I that that items appers automatically when the plugin is activated.

I have this to run on activation hook (do I have to add something inside that hook):

Thanks

//////// Run on activation
function to_do_on_activation() {

    cgs_create_page();
    set_static_front_page();
    cptui_register_my_cpt_frontiles();
    cptui_register_my_taxes_tiles_categories();
    insert_term();
    cgs_create_tiles();
    cgs_create_page();
    set_static_front_page();
    updateTheme('Creative_Grid');
}

register_activation_hook( __FILE__, 'to_do_on_activation' );

No I realize that there is an error when activating the plugin with TGM plugin that it's interfering in the normal process of activation (refreshing the page).

The plugin is activated but I have this warning "The plugin generated unexpected output."

Topic activation plugin-development Wordpress

Category Web


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);
    }
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.