helsingborg-stad / content-scheduler

Schedule posts in WordPress (publish/unpublish on date/time)
MIT License
2 stars 3 forks source link

Update Unpublish.php #5

Closed pbrotherton closed 1 year ago

pbrotherton commented 1 year ago

Fixes problem with named arguments in PHP8 installations

sebastianthulin commented 1 year ago

I cannot draw a parallell to named arguments here. This is how WordPress works, and would mean that WordPress is broken in PHP 8. Is the argument definition generating any warnings or notices?

I would revisit the idea of the fault fetch of postID which is fetched from a global post variable, and not scoped to function using the native input parameter $post in save_post hook. This would certainly create bugs described in your original inquiry.

The documentation clearly provides the post_ID parameter as first argument in save_post. Let's just use that.

pbrotherton commented 1 year ago

No, I'm a little unsure of that connection too.

This only solves the problem we had with php8, not the original problem (which you rightly say is probably fixed already in your master branch with the $_POST variable). In php8 sites though, the unpublish post cron crashes with an "Unknown named parameter" error.

This is unique to php8, and the error disappears when the priority and arg count is removed from the action - then the cron runs and the post is unpublished. I know that WP is far from ready for php8 and a lot of these bugs exist in WP core and shouldn't be "fixed" this way.