Use strict comparison to compare post dates

With PHP 8.0, non-strict comparisons between integers and strings containing
non-numeric characters are being tightened. This affects comparisons like:

0 < '0000-00-00 00:00:00'

PHP 8.0 that equates to true whereas prior to 8.0 it would be false.

More details of this change can be found at: https://wiki.php.net/rfc/string_to_number_comparison
This commit is contained in:
James Allan 2020-10-22 17:21:15 +10:00
parent 16faf915e0
commit 82b68b4914
5 changed files with 20 additions and 8 deletions

View File

@ -108,8 +108,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
$order->set_props( $order->set_props(
array( array(
'parent_id' => $post_object->post_parent, 'parent_id' => $post_object->post_parent,
'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ),
'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ),
'status' => $post_object->post_status, 'status' => $post_object->post_status,
) )
); );

View File

@ -123,8 +123,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
array( array(
'code' => $post_object->post_title, 'code' => $post_object->post_title,
'description' => $post_object->post_excerpt, 'description' => $post_object->post_excerpt,
'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ),
'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ),
'date_expires' => metadata_exists( 'post', $coupon_id, 'date_expires' ) ? get_post_meta( $coupon_id, 'date_expires', true ) : get_post_meta( $coupon_id, 'expiry_date', true ), // @todo: Migrate expiry_date meta to date_expires in upgrade routine. 'date_expires' => metadata_exists( 'post', $coupon_id, 'date_expires' ) ? get_post_meta( $coupon_id, 'date_expires', true ) : get_post_meta( $coupon_id, 'expiry_date', true ), // @todo: Migrate expiry_date meta to date_expires in upgrade routine.
'discount_type' => get_post_meta( $coupon_id, 'discount_type', true ), 'discount_type' => get_post_meta( $coupon_id, 'discount_type', true ),
'amount' => get_post_meta( $coupon_id, 'coupon_amount', true ), 'amount' => get_post_meta( $coupon_id, 'coupon_amount', true ),

View File

@ -630,4 +630,16 @@ class WC_Data_Store_WP {
); );
wp_cache_delete( 'lookup_table', 'object_' . $id ); wp_cache_delete( 'lookup_table', 'object_' . $id );
} }
/**
* Converts a WP post date string into a timestamp.
*
* @since 4.7.0
*
* @param string $time_string The WP post date string.
* @return int|null The date string converted to a timestamp or null.
*/
protected function string_to_timestamp( $time_string ) {
return '0000-00-00 00:00:00' !== $time_string ? wc_string_to_timestamp( $time_string ) : null;
}
} }

View File

@ -170,8 +170,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
array( array(
'name' => $post_object->post_title, 'name' => $post_object->post_title,
'slug' => $post_object->post_name, 'slug' => $post_object->post_name,
'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ),
'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ),
'status' => $post_object->post_status, 'status' => $post_object->post_status,
'description' => $post_object->post_content, 'description' => $post_object->post_content,
'short_description' => $post_object->post_excerpt, 'short_description' => $post_object->post_excerpt,

View File

@ -62,8 +62,8 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
array( array(
'name' => $post_object->post_title, 'name' => $post_object->post_title,
'slug' => $post_object->post_name, 'slug' => $post_object->post_name,
'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ),
'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ),
'status' => $post_object->post_status, 'status' => $post_object->post_status,
'menu_order' => $post_object->menu_order, 'menu_order' => $post_object->menu_order,
'reviews_allowed' => 'open' === $post_object->comment_status, 'reviews_allowed' => 'open' === $post_object->comment_status,