LLMS_Meta_Box_Voucher::save( int $post_id )
Save method
Description Description
Cleans variables and saves using update_post_meta()
.
Parameters Parameters
- $post_id
-
(int) (Required) [id of post object]
Return Return
(boolean|null)
Source Source
File: includes/admin/post-types/meta-boxes/class.llms.meta.box.voucher.php
* @return boolean|null */ public function save( $post_id ) { if ( ! empty( llms_filter_input( INPUT_POST, 'llms_generate_export' ) ) || ! llms_verify_nonce( 'lifterlms_meta_nonce', 'lifterlms_save_data' ) ) { return false; } // Codes save. $codes = array(); $llms_codes = llms_filter_input_sanitize_string( INPUT_POST, 'llms_voucher_code', array( FILTER_REQUIRE_ARRAY ) ); $llms_uses = llms_filter_input( INPUT_POST, 'llms_voucher_uses', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); $llms_voucher_code_id = llms_filter_input( INPUT_POST, 'llms_voucher_code_id', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); $voucher = new LLMS_Voucher( $post_id ); if ( isset( $llms_codes ) && ! empty( $llms_codes ) && isset( $llms_uses ) && ! empty( $llms_uses ) ) { foreach ( $llms_codes as $k => $code ) { if ( isset( $code ) && ! empty( $code ) && isset( $llms_uses[ $k ] ) && ! empty( $llms_uses[ $k ] ) ) { if ( isset( $llms_voucher_code_id[ $k ] ) ) { $data = array( 'code' => $code, 'redemption_count' => intval( $llms_uses[ $k ] ), ); if ( intval( $llms_voucher_code_id[ $k ] ) ) { $data['id'] = intval( $llms_voucher_code_id[ $k ] ); } $codes[] = $data; } } } } if ( ! empty( $codes ) ) { foreach ( $codes as $code ) { if ( isset( $code['id'] ) ) { $voucher->update_voucher_code( $code ); } else { $voucher->save_voucher_code( $code ); } } } // Courses and membership save. $products = array(); foreach ( array( 'courses', 'membership' ) as $type ) { $list = llms_filter_input( INPUT_POST, '_llms_voucher_' . $type, FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); foreach ( (array) $list as $item ) { $products[] = absint( $item ); } } // Remove old products. $voucher->delete_products(); // Save new ones. if ( ! empty( $products ) ) { foreach ( $products as $item ) { $voucher->save_product( $item ); } } // Set old codes as deleted. $ids = llms_filter_input( INPUT_POST, 'delete_ids' ); if ( $ids ) { $delete_ids = array_map( 'absint', explode( ',', $ids ) ); if ( ! empty( $delete_ids ) ) { foreach ( $delete_ids as $id ) { $voucher->delete_voucher_code( $id ); } }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |