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

LifterLMS LifterLMS

  • Code Reference
  • REST API
  • LLMS-CLI
  • Changelog Subscribe

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
  • 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

	 * @since 5.9.0 Stop using deprecated `FILTER_SANITIZE_STRING`.
	 *
	 * @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.
	 */
	public function redeem_voucher() {

		if ( ! isset( $_REQUEST['lifterlms_voucher_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['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;
		}

Expand full source code Collapse full source code View on GitHub


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 - 2026 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.