<?php
/**
 * Plugin Name: EDD Staged Rollouts
 * Plugin URI: https://wpadvancedads.com/
 * Description: Staged Rollouts Support for Easy Digital Downloads
 * Author: webgilde
 * Author URI: https://webgilde.com/
 * Version: 1.0.0
 * Text Domain: edd-staged-rollouts
 *
 * @author Advanced Ads GmbH
 * @version 1.0.0
 */

/*******************************************************************************
 * Staged Rollouts: the following code allows us to deliver updates in batches
 * see wp-content/plugins/edd-software-licensing/edd-software-licenses.php :: get_latest_version_remote()
 * and https://github.com/webgilde/wpadvancedads-custom-code/issues/17 for details on the implementation
 *
 * Be aware of the following:
 * - the filter already delivers the new version details including the descriptions
 * - if we just swap the new version number with an older one then users with that old version will not be informed about an update
 * - if we set another (newer) version than the user currently has, but not the most recent one then they will see the update but with the latest changelog
 ******************************************************************************/

 // Exit if accessed directly.
 if ( ! defined( 'ABSPATH' ) ) exit;

function edd_sr_load () {
   // Exit if EDD Software Licensing doesn't exist
   if ( class_exists( 'EDD_Software_Licensing' ) ) {
  	 if ( ! defined( 'EDD_SR_PLUGIN_DIR' ) ) {
  	 		define( 'EDD_SR_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
  	 	}

  	 	if ( ! defined( 'EDD_SR_PLUGIN_URL' ) ) {
  	 		define( 'EDD_SR_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  	 	}

  	 	if ( ! defined( 'EDD_SR_PLUGIN_FILE' ) ) {
  	 		define( 'EDD_SR_PLUGIN_FILE', __FILE__ );
  	 	}

  	 	if ( ! defined( 'EDD_SR_VERSION' ) ) {
  	 		define( 'EDD_SR_VERSION', '1.0.0' );
  	 	}

  		if( is_admin() ) {
  			include_once( EDD_SR_PLUGIN_DIR . 'includes/admin/metabox.php' );
  		}

      include_once( EDD_SR_PLUGIN_DIR . 'includes/scripts.php' );
      include_once( EDD_SR_PLUGIN_DIR . 'includes/actions.php' );

  } else {
    /**
     * EDD Software Licensing doesn't exist or is not activated
     * deactivate EDD Staged Rollouts
    */
    function staged_rollouts_deactivate() {
        deactivate_plugins( plugin_basename( __FILE__ ) );
    }
    add_action( 'admin_init', 'staged_rollouts_deactivate' );

    function staged_rollouts_admin_notice() {
         echo '<div class="updated"><p><strong>Easy Digital Downloads - Software Licensing</strong> is not active/installed; Easy Digital Downloads - Staged Rollouts has been <strong>deactivated</strong>.</p></div>';
         if ( isset( $_GET['activate'] ) )
              unset( $_GET['activate'] );
    }
    add_action( 'admin_notices', 'staged_rollouts_admin_notice' );
  }
}
/**
 * Load EDD Staged Rollouts after all other plugins are loaded
*/
add_action( 'plugins_loaded', 'edd_sr_load' );
