LLMS_Meta_Box_Order_Details::save( int $post_id )

Save method


Parameters Parameters

$post_id

(int) (Required) Post ID of the Order.


Top ↑

Return Return

(int) Returns -1 on invalid or missing nonce, 0 when an order cannot be found, and 1 otherwise.


Top ↑

Source Source

File: includes/admin/post-types/meta-boxes/class.llms.meta.box.order.details.php

	public function save( $post_id ) {

		if ( ! isset( $_REQUEST['lifterlms_meta_nonce'] ) ) {
			return -1;
		}
		if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['lifterlms_meta_nonce'] ) ), 'lifterlms_save_data' ) ) {
			return -1;
		}

		$order = llms_get_post( $post_id );
		if ( ! $order || ! is_a( $order, 'LLMS_Order' ) ) {
			return 0;
		}

		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return -1;
		}

		$fields = array(
			'payment_gateway',
			'gateway_customer_id',
			'gateway_subscription_id',
			'gateway_source_id',
		);

		foreach ( $fields as $key ) {

			if ( isset( $_POST[ $key ] ) ) {
				$order->set( $key, llms_filter_input_sanitize_string( INPUT_POST, $key ) );
			}
		}

		// Only allow editing the total (for the next recurrence) if this is a recurring order.
		if ( $order->is_recurring() && isset( $_POST['total'] ) && is_numeric( $_POST['total'] ) ) {
			$total = floatval( $_POST['total'] );
			$order->set( 'total', $total );
			$order->add_note( sprintf( __( 'Order total for future payments updated to %s.', 'lifterlms' ), $order->get_price( 'total' ) ) );
		}

		$this->save_remaining_payments( $order );

		return 1;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.9.0 Stop using deprecated FILTER_SANITIZE_STRING.
5.3.0 Update return value from void to int (for testing conditions) and include update remaining payment data when necessary.
3.35.0 Verify nonces and sanitize $_POST data.
3.10.0 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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