autoship_version_trigger (function)

(src/upgrade.php) Used to check for upgrades, new installs, and changes of Autoship Cloud versions. It is hooked into the admin_init (Wordpress) action for all types of updates.

Function

**
 * The version checks for upgrades, installs and changes.
 * Hooked into admin_init for all types of updates.
 */
function autoship_version_trigger(){

  // Check for custom transition version key
	$versions = get_option( '_autoship_transition_version' );
	$existing = get_option( 'autoship_site_id' );

  // If empty check for existing post meta to see if this is a new
  // or existing setup.
  if ( false === $versions || empty( $versions ) ){
    // We're a < 1.2.32 version change
    if ( false === $existing ){
      //We're a new install
      do_action( 'autoship_new_install_completed', Autoship_Version );
    } else {
      //We're an existing upgrade from pre
      do_action( 'autoship_upgrade_from_null_to_', Autoship_Version );
    }
    // Set transition version.
    update_option( '_autoship_transition_version', Autoship_Version . '_' . Autoship_Version );

  } else {
    // Existing user
    $current_version = explode( '_', $versions);
    if ( version_compare( $current_version[1], Autoship_Version, '<' ) ) {
      //We're an upgrade
      update_option( '_autoship_transition_version', $current_version[1] . '_' . Autoship_Version );
      do_action( "autoship_upgrade_from_{$current_version[1]}_to_", Autoship_Version );
      do_action( 'autoship_upgrade_completed', $current_version[1], Autoship_Version );
    }

  }

}