• LifterLMS
  • Knowledge Base
  • Academy
  • Blog
  • Podcast
  • Contributors
  • My Account

LifterLMS LifterLMS

  • Code Reference
  • REST API
  • LLMS-CLI

Code Reference

Skip to content
Filter by type:
Search
Browse: Home / Code Reference / Classes / LLMS_Controller_Account / LLMS_Controller_Account::redeem_voucher()

LLMS_Controller_Account::redeem_voucher()

Redeem a voucher from the “Redeem Voucher” endpoint of the student dashboard

Contents

  • Return
  • Source
  • Related
    • Uses
  • Changelog
  • User Contributed Notes

Return #Return

(null|true|WP_Error) Returns null when the form hasn't been submitted, there's a nonce error, or there's no logged in user. Returns true on success and an error object when an error is encountered redeeming the voucher.


Top ↑

Source #Source

File: includes/forms/controllers/class.llms.controller.account.php

	public function redeem_voucher() {

		if ( ! llms_verify_nonce( 'lifterlms_voucher_nonce', 'lifterlms_voucher_check' ) || ! get_current_user_id() ) {
			return null;
		}

		$voucher  = new LLMS_Voucher();
		$redeemed = $voucher->use_voucher( llms_filter_input_sanitize_string( INPUT_POST, 'llms_voucher_code' ), get_current_user_id() );

		if ( is_wp_error( $redeemed ) ) {
			llms_add_notice( $redeemed->get_error_message(), 'error' );
			return $redeemed;
		}

		llms_add_notice( __( 'Voucher redeemed successfully!', 'lifterlms' ), 'success' );
		return true;

	}

Expand full source code Collapse full source code View on GitHub


Top ↑

Related #Related

Uses #Uses

Uses
Uses Description
includes/llms.functions.core.php: llms_filter_input_sanitize_string()

Function used to sanitize user input in a manner similar to the (deprecated) FILTER_SANITIZE_STRING.

includes/llms.functions.core.php: llms_verify_nonce()

Verify nonce with additional checks to confirm request method

includes/functions/llms.functions.notice.php: llms_add_notice()

Stores notice in llms_notices session

includes/class.llms.voucher.php: LLMS_Voucher::__construct()

Constructor


Top ↑

Changelog #Changelog

Changelog
Version Description
5.9.0 Stop using deprecated FILTER_SANITIZE_STRING.
4.12.0 Introduced.

Top ↑

User Contributed Notes #User Contributed Notes

You must log in before being able to contribute a note or feedback.

© 2014 - 2023 LifterLMS · Privacy Policy · Terms and Conditions

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.