LLMS_Meta_Box_Coupon::save( int $post_id )
Save all metadata
Parameters Parameters
- $post_id
-
(int) (Required) WP Post ID.
Return Return
(void)
Source Source
File: includes/admin/post-types/meta-boxes/class.llms.meta.box.coupon.php
protected function save( $post_id ) { if ( ! llms_verify_nonce( 'lifterlms_meta_nonce', 'lifterlms_save_data' ) ) { return; } $coupon = new LLMS_Coupon( $post_id ); // Dupcheck the title. $exists = llms_find_coupon( $coupon->get( 'title' ), $post_id ); if ( $exists ) { $this->add_error( __( 'Coupon code already exists. Customers will use the most recently created coupon with this code.', 'lifterlms' ) ); } // Trial validation. $trial_discount = llms_filter_input_sanitize_string( INPUT_POST, $this->prefix . 'enable_trial_discount' ); $trial_amount = llms_filter_input( INPUT_POST, $this->prefix . 'trial_amount', FILTER_SANITIZE_NUMBER_INT ); if ( ! $trial_discount ) { $trial_discount = 'no'; } elseif ( 'yes' === $trial_discount && empty( $trial_amount ) ) { $this->add_error( __( 'A Trial Discount Amount was not supplied. Trial Pricing Discount has automatically been disabled. Please re-enable Trial Pricing Discount and enter a Trial Discount Amount, then save this coupon again.', 'lifterlms' ) ); $trial_discount = 'no'; } $coupon->set( 'enable_trial_discount', $trial_discount ); $coupon->set( 'trial_amount', $trial_amount ); $courses = llms_filter_input( INPUT_POST, $this->prefix . 'coupon_courses', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); if ( empty( $courses ) ) { $courses = array(); } $coupon->set( 'coupon_courses', $courses ); $memberships = llms_filter_input( INPUT_POST, $this->prefix . 'coupon_membership', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); if ( empty( $memberships ) ) { $memberships = array(); } $coupon->set( 'coupon_membership', $memberships ); // Save all the fields. $fields = array( 'coupon_amount', 'usage_limit', 'discount_type', 'description', 'expiration_date', 'plan_type', ); foreach ( $fields as $field ) { if ( isset( $_POST[ $this->prefix . $field ] ) ) { $coupon->set( $field, llms_filter_input_sanitize_string( INPUT_POST, $this->prefix . $field ) ); } } }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.9.0 | Stop using deprecated FILTER_SANITIZE_STRING . |
3.35.0 | Sanitize $_POST data and verify nonce. |
3.0.0 | Introduced. |