src/Modules/Licenser.php
function activate_license() {
		// listen for our activate button to be clicked.
		if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
			return;
		}
		$status = $this->get_license_status();
		// retrieve the license from the database.
		$license    = $_POST[ $this->product->get_key() . '_license' ];
		$api_params = array(
			'license'   => $license,
			'item_name' => rawurlencode( $this->product->get_name() ),
			'url'       => rawurlencode( home_url() ),
		);
		if ( 'valid' != $status ) {
			// data to send in our API request.
			$api_params['edd_action'] = 'activate_license';
		} else {
			$api_params['edd_action'] = 'deactivate_license';
		}
		// Call the custom API.
		$response = wp_remote_get( add_query_arg( $api_params, $this->get_api_url() ) );
		// make sure the response came back okay.
		if ( is_wp_error( $response ) ) {
			$license_data          = new \stdClass();
			$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';

		} else {
			$license_data = json_decode( wp_remote_retrieve_body( $response ) );
			if ( ! is_object( $license_data ) ) {
				$license_data          = new \stdClass();
				$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
			}
			if ( ! isset( $license_data->license ) ) {
				$license_data->license = 'invalid';
			}
		}
		if ( ! isset( $license_data->key ) ) {
			$license_data->key = $license;
		}
		if ( 'valid' == $license_data->license ) {
			$this->reset_failed_checks();
		}

		if ( isset( $license_data->plan ) ) {
			update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
		}

		update_option( $this->product->get_key() . '_license_data', $license_data );
		set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );

	}
function activate_license() {
		// listen for our activate button to be clicked.
		if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
			return;
		}
		$status = $this->get_license_status();
		// retrieve the license from the database.
		$license    = $_POST[ $this->product->get_key() . '_license' ];
		$api_params = array(
			'license'   => $license,
			'item_name' => rawurlencode( $this->product->get_name() ),
			'url'       => rawurlencode( home_url() ),
		);
		if ( 'valid' != $status ) {
			// data to send in our API request.
			$api_params['edd_action'] = 'activate_license';
		} else {
			$api_params['edd_action'] = 'deactivate_license';
		}
		// Call the custom API.
		$response = wp_remote_get( add_query_arg( $api_params, $this->get_api_url() ) );
		// make sure the response came back okay.
		if ( is_wp_error( $response ) ) {
			$license_data          = new \stdClass();
			$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';

		} else {
			$license_data = json_decode( wp_remote_retrieve_body( $response ) );
			if ( ! is_object( $license_data ) ) {
				$license_data          = new \stdClass();
				$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
			}
			if ( ! isset( $license_data->license ) ) {
				$license_data->license = 'invalid';
			}
		}
		if ( ! isset( $license_data->key ) ) {
			$license_data->key = $license;
		}
		if ( 'valid' == $license_data->license ) {
			$this->reset_failed_checks();
		}

		if ( isset( $license_data->plan ) ) {
			update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
		}

		update_option( $this->product->get_key() . '_license_data', $license_data );
		set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );

	}
function activate_license ( ) { // listen for our activate button to be clicked. if ( ! isset ( $ _POST [ $ this -> product -> get_key ( ) . '_btn_trigger' ] ) ) { return ; } $ status = $ this -> get_license_status ( ) ; // retrieve the license from the database. $ license = $ _POST [ $ this -> product -> get_key ( ) . '_license' ] ; $ api_params = array ( 'license' => $ license , 'item_name' => rawurlencode ( $ this -> product -> get_name ( ) ) , 'url' => rawurlencode ( home_url ( ) ) , ) ; if ( 'valid' != $ status ) { // data to send in our API request. $ api_params [ 'edd_action' ] = 'activate_license' ; } else { $ api_params [ 'edd_action' ] = 'deactivate_license' ; } // Call the custom API. $ response = wp_remote_get ( add_query_arg ( $ api_params , $ this -> get_api_url ( ) ) ) ; // make sure the response came back okay. if ( is_wp_error ( $ response ) ) { $ license_data = new \ stdClass ( ) ; $ license_data -> license = ( 'valid' != $ status ) ? 'valid' : 'invalid' ; } else { $ license_data = json_decode ( wp_remote_retrieve_body ( $ response ) ) ; if ( ! is_object ( $ license_data ) ) { $ license_data = new \ stdClass ( ) ; $ license_data -> license = ( 'valid' != $ status ) ? 'valid' : 'invalid' ; } if ( ! isset ( $ license_data -> license ) ) { $ license_data -> license = 'invalid' ; } } if ( ! isset ( $ license_data -> key ) ) { $ license_data -> key = $ license ; } if ( 'valid' == $ license_data -> license ) { $ this -> reset_failed_checks ( ) ; } if ( isset ( $ license_data -> plan ) ) { update_option ( $ this -> product -> get_key ( ) . '_license_plan' , $ license_data -> plan ) ; } update_option ( $ this -> product -> get_key ( ) . '_license_data' , $ license_data ) ; set_transient ( $ this -> product -> get_key ( ) . '_license_data' , $ license_data , 12 * HOUR_IN_SECONDS ) ; }
Activate the license remotely.
Activate the license remotely .