pronamic / wp-orbis-subscriptions

The Orbis Subscriptions plugin extends your Orbis environment with the option to add subscription products and subscriptions.
http://www.pronamic.eu/plugins/orbis-subscriptions/
2 stars 2 forks source link

Fatal error on subscription save #30

Closed rvdsteege closed 8 months ago

rvdsteege commented 8 months ago

I'm getting an error when trying to publish a new subscription:

Publiceren mislukt. De reactie is geen geldige JSON-reactie.

The underlying error message is:

Fatal error: Uncaught Error: Call to a member function setTime() on bool in /wp-content/plugins/orbis-subscriptions/includes/post.php on line 283

This seems to be caused by changes in /includes/post.php last week:

$activation_date_string = get_post_meta( $post_id, '_orbis_subscription_activation_date', true );

- $activation_date = new \DateTime( $activation_date_string, \wp_timezone() );
+ $activation_date = DateTimeImmutable::createFromFormat( 'Y-m-d', $activation_date_string )->setTime( 0, 0 );

https://github.com/pronamic/wp-orbis-subscriptions/commit/ba5420c760fcdb4198061c92982b539370190c41#diff-c598a688002b8ecbcb8e530b9dda652939e6382f0fa507627b838b24784c611d

Before, when $activation_date_string was false, the $activation_date would be set to todays' date through new DateTime( false ). But now, setTime() is called on the result of DateTimeImmutable::createFromFormat( 'Y-m-d', false ) which is false and results in a fatal error.

PHP debug ```php var_dump( new DateTime( false ) ); var_dump( DateTimeImmutable::createFromFormat( 'Y-m-d', false )->setTime( 0, 0 ) ); ```
remcotolsma commented 8 months ago

Problem only occurred in the block editor, fixed in https://github.com/pronamic/wp-orbis-subscriptions/commit/b6c21f964f53def1c0da9bd9336e476c3ac42ec5.