LLMS_Meta_Box_Order_Submit::save( int $post_id )
Save action, update order status
Parameters Parameters
- $post_id
-
(int) (Required) WP Post ID of the Order
Return Return
(null)
Source Source
File: includes/admin/post-types/meta-boxes/class.llms.meta.box.order.submit.php
public function save( $post_id ) {
if ( ! isset( $_REQUEST['lifterlms_meta_nonce'] ) ) {
return;
}
if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['lifterlms_meta_nonce'] ) ), 'lifterlms_save_data' ) ) {
return;
}
$order = llms_get_post( $post_id );
if ( isset( $_POST['_llms_order_status'] ) ) {
$new_status = llms_filter_input_sanitize_string( INPUT_POST, '_llms_order_status' );
$old_status = $order->get( 'status' );
if ( $old_status !== $new_status ) {
// Update the status.
$order->set( 'status', $new_status );
}
}
$editable_dates = array(
'_llms_date_access_expires',
);
// Save recurring payments related dates if order's gateway supports recurring payments modification.
if ( $order->supports_modify_recurring_payments() ) {
/**
* Order is important -- if both trial and next payment are updated
* they should be saved in that order since next payment date
* is automatically recalculated by trial end date update.
*/
array_push( $editable_dates, '_llms_date_trial_end', '_llms_date_next_payment' );
}
foreach ( $editable_dates as $id => $key ) {
if ( isset( $_POST[ $key ] ) ) {
// The array of date, hour, minute that was submitted.
$dates = llms_filter_input_sanitize_string( INPUT_POST, $key, array( FILTER_REQUIRE_ARRAY ) );
// Format the array of data as a datetime string.
$new_date = $dates['date'] . ' ' . sprintf( '%02d', $dates['hour'] ) . ':' . sprintf( '%02d', $dates['minute'] );
// Get the existing saved date without seconds (in the same format as $new_date).
$saved_date = date_i18n( 'Y-m-d H:i', strtotime( get_post_meta( $post_id, $key, true ) ) );
// If the dates are not equal, update the date.
if ( $new_date !== $saved_date ) {
$date_key = str_replace( '_llms_date_', '', $key );
$order->set_date( $date_key, $new_date . ':00' );
if ( 'access_expires' === $date_key ) {
$old_date_display = $saved_date
? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $saved_date ) )
: __( 'none', 'lifterlms' );
$new_date_display = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $new_date ) );
// Translators: %1$s = old access expiration date; %2$s = new access expiration date.
$note = sprintf( __( 'Access expiration date changed from %1$s to %2$s', 'lifterlms' ), $old_date_display, $new_date_display );
$order->add_note( $note, true );
}
}
}
}
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 7.0.0 | Do not save recurring payments related dates if order's gateway do not support recurring payments modification. |
| 5.9.0 | Stop using deprecated FILTER_SANITIZE_STRING. |
| 3.36.0 | Date fields require array when sanitized. |
| 3.35.0 | Verify nonces and sanitize $_POST data. |
| 3.19.0 | Unknown. |
| 3.0.0 | |
| 10.0.0 | Introduced. |