Merge pull request #23203 from woocommerce/update/23199

[3.6] Prevent removal of the wc- prefix from non core order statuses
This commit is contained in:
Timmy Crawford 2019-04-08 12:13:11 -07:00 committed by GitHub
commit b4352c8b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 7 deletions

View File

@ -58,9 +58,6 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
$order->set_date_created( current_time( 'timestamp', true ) ); $order->set_date_created( current_time( 'timestamp', true ) );
$order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() ); $order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() );
$raw_status = $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' );
$status = wc_is_order_status( 'wc-' . $raw_status ) ? 'wc-' . $raw_status : $raw_status;
$id = wp_insert_post( $id = wp_insert_post(
apply_filters( apply_filters(
'woocommerce_new_order_data', 'woocommerce_new_order_data',
@ -68,7 +65,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ), 'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ), 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
'post_type' => $order->get_type( 'edit' ), 'post_type' => $order->get_type( 'edit' ),
'post_status' => $status, 'post_status' => $this->get_post_status( $order ),
'ping_status' => 'closed', 'ping_status' => 'closed',
'post_author' => 1, 'post_author' => 1,
'post_title' => $this->get_post_title(), 'post_title' => $this->get_post_title(),
@ -144,12 +141,10 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
// Only update the post when the post data changes. // Only update the post when the post data changes.
if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) { if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) {
$raw_status = $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' );
$status = wc_is_order_status( 'wc-' . $raw_status ) ? 'wc-' . $raw_status : $raw_status;
$post_data = array( $post_data = array(
'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ), 'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ), 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
'post_status' => $status, 'post_status' => $this->get_post_status( $order ),
'post_parent' => $order->get_parent_id(), 'post_parent' => $order->get_parent_id(),
'post_excerpt' => $this->get_post_excerpt( $order ), 'post_excerpt' => $this->get_post_excerpt( $order ),
'post_modified' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ), 'post_modified' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
@ -215,6 +210,36 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
/**
* Get the status to save to the post object.
*
* Plugins extending the order classes can override this to change the stored status/add prefixes etc.
*
* @since 3.6.0
* @param WC_order $order Order object.
* @return string
*/
protected function get_post_status( $order ) {
$order_status = $order->get_status( 'edit' );
if ( ! $order_status ) {
$order_status = apply_filters( 'woocommerce_default_order_status', 'pending' );
}
$post_status = $order_status;
$valid_statuses = get_post_stati();
// Add a wc- prefix to the status, but exclude some core statuses which should not be prefixed.
// @todo In the future this should only happen based on `wc_is_order_status`, but in order to
// preserve back-compatibility this happens to all statuses except a select few. A doing_it_wrong
// Notice will be needed here, followed by future removal.
if ( ! in_array( $post_status, array( 'auto-draft', 'draft', 'trash' ), true ) && in_array( 'wc-' . $post_status, $valid_statuses, true ) ) {
$post_status = 'wc-' . $post_status;
}
return $post_status;
}
/** /**
* Excerpt for post. * Excerpt for post.
* *