0

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."

1 Answer 1

0

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);
    }
}
2
  • Hi Arshid, thanks for your reply. I found out that adding wp_redirect( admin_url() ); after ` updateTheme('Creative_Grid');` was enough to make the redirection. It should be enough no?
    – Dedalos01
    Commented Jan 20, 2015 at 12:27
  • Most of the time it is enough but sometimes it creates errors due to not loading all thing. So creating an option is the best solution and avoiding errors. Hope this helps.
    – Sabbir H
    Commented Sep 12, 2022 at 10:47

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.