file      = $_file;
		$this->item_name = $_item_name;
		if ( is_numeric( $_item_id ) ) {
			$this->item_id = absint( $_item_id );
		}
		$this->item_shortname = 'edd_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) );
		$this->version        = $_version;
		$this->edd_license    = new License( $this->item_name, $_optname );
		if ( empty( $this->edd_license->key ) ) {
			$this->edd_license = new License( 'pro' );
			if ( ! empty( $this->edd_license->key ) ) {
				$this->is_pro_license = true;
			}
		}
		$this->license      = $this->edd_license->key;
		$this->author       = $_author;
		$this->api_handler  = new API();
		$this->api_url      = is_null( $_api_url ) ? $this->api_handler->get_url() : $_api_url;
		$this->pass_manager = new \EDD\Admin\Pass_Manager();
		// Setup hooks
		$this->includes();
		$this->hooks();
		/**
		 * Maintain an array of active, licensed plugins that have a license key entered.
		 * This is to help us more easily determine if the site has a license key entered
		 * at all. Initializing it this way helps us limit the data to activated plugins only.
		 * If we relied on the options table (`edd_%_license_active`) then we could accidentally
		 * be picking up plugins that have since been deactivated.
		 *
		 * @see \EDD\Admin\Promos\Notices\License_Upgrade_Notice::__construct()
		 */
		if ( ! empty( $this->license ) ) {
			global $edd_licensed_products;
			if ( ! is_array( $edd_licensed_products ) ) {
				$edd_licensed_products = array();
			}
			$edd_licensed_products[] = $this->item_shortname;
		}
	}
	/**
	 * Include the updater class
	 *
	 * @access  private
	 * @return  void
	 */
	private function includes() {
		if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) )  {
			require_once 'EDD_SL_Plugin_Updater.php';
		}
	}
	/**
	 * Setup hooks
	 *
	 * @access  private
	 * @return  void
	 */
	private function hooks() {
		// Register settings
		add_filter( 'edd_settings_licenses', array( $this, 'settings' ), 1 );
		// Display help text at the top of the Licenses tab
		add_action( 'edd_settings_tab_top', array( $this, 'license_help_text' ) );
		// Check that license is valid once per week
		if ( edd_doing_cron() ) {
			add_action( 'edd_weekly_scheduled_events', array( $this, 'weekly_license_check' ) );
		}
		// For testing license notices, uncomment this line to force checks on every page load
		//add_action( 'admin_init', array( $this, 'weekly_license_check' ) );
		// Updater
		add_action( 'init', array( $this, 'auto_updater' ) );
		// Display notices to admins
		add_action( 'admin_notices', array( $this, 'notices' ) );
		add_action( 'in_plugin_update_message-' . plugin_basename( $this->file ), array( $this, 'plugin_row_license_missing' ), 10, 2 );
		// Register plugins for beta support
		add_filter( 'edd_beta_enabled_extensions', array( $this, 'register_beta_support' ) );
		// Add the EDD version to the API parameters.
		add_filter( 'edd_sl_plugin_updater_api_params', array( $this, 'filter_sl_api_params' ), 10, 3 );
		// Fix missing Stripe keys due to option name change.
		add_action( 'admin_init', array( $this, 'fix_stripe_key' ) );
	}
	/**
	 * Auto updater
	 *
	 * @access  private
	 * @return  void
	 */
	public function auto_updater() {
		$doing_cron = defined( 'DOING_CRON' ) && DOING_CRON;
		if ( ! current_user_can( 'manage_options' ) && ! $doing_cron ) {
			return;
		}
		$license = $this->license;
		// Fall back to the highest license key if one is not saved for this extension or there isn't a pro license.
		if ( empty( $license ) ) {
			if ( $this->pass_manager->highest_license_key ) {
				$license = $this->pass_manager->highest_license_key;
			}
		}
		// Don't check for updates if there isn't a license key.
		if ( empty( $license ) ) {
			return;
		}
		$args = array(
			'version' => $this->version,
			'license' => $license,
			'author'  => $this->author,
			'beta'    => function_exists( 'edd_extension_has_beta_support' ) && edd_extension_has_beta_support( $this->item_shortname ),
		);
		if ( ! empty( $this->item_id ) ) {
			$args['item_id'] = $this->item_id;
		} else {
			$args['item_name'] = $this->item_name;
		}
		// Setup the updater
		new EDD_SL_Plugin_Updater(
			$this->api_url,
			$this->file,
			$args
		);
	}
	/**
	 * Add license field to settings
	 *
	 * @param array   $settings
	 * @return  array
	 */
	public function settings( $settings ) {
		return array_merge( $settings, array(
			array(
				'id'      => $this->item_shortname . '_license_key',
				'name'    => $this->item_name,
				'desc'    => '',
				'type'    => 'license_key',
				'options' => array(
					'is_valid_license_option' => $this->item_shortname . '_license_active',
					'item_id'                 => $this->item_id,
				),
				'size'    => 'regular',
			)
		) );
	}
	/**
	 * Display help text at the top of the Licenses tag
	 *
	 * @since   2.5
	 * @param   string   $active_tab
	 * @return  void
	 */
	public function license_help_text( $active_tab = '' ) {
		static $has_ran = false;
		if ( 'licenses' !== $active_tab ) {
			return;
		}
		if ( ! empty( $has_ran ) ) {
			return;
		}
		?>
		
			
				',
					''
				);
				?>
			
			pass_manager->highest_license_key ) : ?>
				
					 'edd-settings',
							'tab'  => 'general',
						)
					);
					printf(
						__( 'Have a pass? You\'re ready to set up EDD (Pro). %1$sActivate Your Pass%2$s' ),
						'',
						''
					);
					?>
				
			
		 
		is_pro_license ) {
			return;
		}
		// Don't fire when saving settings.
		if ( ! empty( $_POST['edd_settings'] ) ) {
			return;
		}
		if ( empty( $this->license ) ) {
			return;
		}
		// data to send in our API request
		$api_params = array(
			'edd_action' => 'check_license',
			'license'    => $this->license,
			'item_name'  => urlencode( $this->item_name ),
		);
		if ( ! empty( $this->item_id ) ) {
			$api_params['item_id'] = $this->item_id;
		}
		$license_data = $this->api_handler->make_request( $api_params );
		if ( ! $license_data ) {
			return false;
		}
		$this->pass_manager->maybe_set_pass_flag( $this->license, $license_data );
		$this->edd_license->save( $license_data );
	}
	/**
	 * Admin notices for errors
	 *
	 * @return  void
	 */
	public function notices() {
		static $showed_invalid_message = false;
		if ( empty( $this->license ) ) {
			return;
		}
		if ( ! current_user_can( 'manage_shop_settings' ) ) {
			return;
		}
		$messages = array();
		$license = $this->edd_license;
		if ( ( empty( $license->license ) || 'valid' !== $license->license ) && empty( $showed_invalid_message ) ) {
			if ( empty( $_GET['tab'] ) || 'licenses' !== $_GET['tab'] ) {
				$messages[] = sprintf(
					__( 'You have invalid or expired license keys for Easy Digital Downloads. Fix this', 'easy-digital-downloads' ),
					esc_url( edd_get_admin_url( array( 'page' => 'edd-settings', 'tab' => 'licenses' ) ) )
				);
				$showed_invalid_message = true;
			}
		}
		if ( ! empty( $messages ) ) {
			foreach( $messages as $message ) {
				echo '';
					echo '
' . $message . '
';
				echo '