From d9178563781c8ab1eb1319cb38fb33eb8c9c11e9 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 4 Apr 2017 12:39:35 +0100 Subject: [PATCH] Validate status if object_read #13891 --- includes/abstracts/abstract-wc-order.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index 724c791022c..b59fb57f6ce 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -470,18 +470,21 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { $old_status = $this->get_status(); $new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status; - // Only allow valid new status - if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses() ) && 'trash' !== $new_status ) { - $new_status = 'pending'; + // If setting the status, ensure it's set to a valid status. + if ( true === $this->object_read ) { + // Only allow valid new status + if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses() ) && 'trash' !== $new_status ) { + $new_status = 'pending'; + } + + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. + if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses() ) && 'trash' !== $old_status ) { + $old_status = 'pending'; + } } $this->set_prop( 'status', $new_status ); - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. - if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses() ) && 'trash' !== $old_status ) { - $old_status = 'pending'; - } - return array( 'from' => $old_status, 'to' => $new_status,