Validate status if object_read

#13891
This commit is contained in:
Mike Jolley 2017-04-04 12:39:35 +01:00
parent 505813403e
commit d917856378
1 changed files with 11 additions and 8 deletions

View File

@ -470,17 +470,20 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$old_status = $this->get_status(); $old_status = $this->get_status();
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status; $new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
// If setting the status, ensure it's set to a valid status.
if ( true === $this->object_read ) {
// Only allow valid new status // Only allow valid new status
if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses() ) && 'trash' !== $new_status ) { if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses() ) && 'trash' !== $new_status ) {
$new_status = 'pending'; $new_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 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 ) { if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses() ) && 'trash' !== $old_status ) {
$old_status = 'pending'; $old_status = 'pending';
} }
}
$this->set_prop( 'status', $new_status );
return array( return array(
'from' => $old_status, 'from' => $old_status,