Adding a Wizard to My Plugin

That’s WordPress API and the proper tool to use for this is register_activation_hook which fires right after your plugin activation, or after_setup_theme if you were doing this work for a theme.

Here’s an example use, the code should be placed in the main plugin loader file, or if in a sub-directory then provide a path to __FILE__ property from the main file:

add_action( "admin_init", function(){
    if ( get_option( $opt_name = "se_show_my_plugin_wizard_notice" ) ) {
        delete_option( $opt_name );
        add_action( "admin_notices", "se_wizard_notice" );
    } return;
});

/**
  * Check if user has completed wizard already
  * if so then return true (don't show notice)
  *
  */
function se_wizard_completed() {
    return false;
}

function se_wizard_notice() {

    if ( se_wizard_completed() ) return; // completed already
    ?>

    <div class="updated notice is-dismissible">
        <p>Welcome to my plugin! You're almost there, but we think this wizard might help you setup the plugin.</p>
        <p><a href="https://wordpress.stackexchange.com/questions/232305/admin.php?page=my_plugin_wizard" class="button button-primary">Run wizard</a> <a href="javascript:window.location.reload()" class="button">dismiss</a></p>
    </div>

    <?php

}

register_activation_hook( __FILE__, function() {
    update_option( "se_show_my_plugin_wizard_notice", 1 );
});

Hope that helps.

Leave a Comment