Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created December 12, 2014 17:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zanematthew/1fecf2ff89740becce4b to your computer and use it in GitHub Desktop.
Save zanematthew/1fecf2ff89740becce4b to your computer and use it in GitHub Desktop.
Note this is a snippet from a class, you can replace the $this-> with your params or hardcode them. Its all ran during admin_init.
<?php
/**
* Sends user to the start page on first activation, as well as each time the
* plugin is upgraded to a new version
*
* @access public
* @since 1.1
* @return void
*/
public function welcome_init(){
// Bail if no activation redirect
if ( ! get_transient( '_' . $this->plugin_slug . '_activation_redirect' ) )
return;
// Delete the redirect transient
delete_transient( '_' . $this->plugin_slug . '_activation_redirect' );
// Bail if activating from network, or bulk
if ( is_network_admin() || isset( $_GET['activate-multi'] ) )
return;
if( ! $this->upgraded_from ){ // First time install
wp_safe_redirect( admin_url( 'index.php?page=' . $this->start_slug ) ); exit;
} else { // Update
wp_safe_redirect( admin_url( 'index.php?page=' . $this->update_slug ) ); exit;
}
}
@zanematthew
Copy link
Author

Note version numbers can be handled to your liking, this is how I do it: https://gist.github.com/zanematthew/f8440442df8524a9dff0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment