PHP Fatal error … Uncaught TypeError … WP_Post …null given [Solved?]
-
Hello
I would like to draw your attention to a PHP issue which you can consider fixing with the next update of your plugin.
We have PHP v8.2.28 running on the web-server.
WordPress v6.8.1 is installed.
The FS Poster plugin is installed as version 7.1.9—
This is the error that occurred:
[01-May-2025 07:14:18 UTC] PHP Fatal error: Uncaught TypeError: FSPoster\App\Providers\WPPost\WPPostService::postMutation(): Argument #1 ($post) must be of type WP_Post, null given, called in /home/customer/www/trike-bike.com.au/public_html/wp-content/plugins/fs-poster/App/Providers/WPPost/WPPostService.php on line 123 and defined in /home/customer/www/trike-bike.com.au/public_html/wp-content/plugins/fs-poster/App/Providers/WPPost/WPPostService.php:126The problem would occur in the file
WPPostService.php, in the following function definition:public static function postMutation ( WP_Post $post, $postStatusChanged, $postDateChanged, $postTermsChanged, ?WP_Post $postBeforeMutation = null )The problem is that at times
nullis given as the variable$post, when the function expects the variable$postto be of the typeWP_Post.As a temporary solution I made the following change to this function definition:
public static function postMutation ($postStatusChanged, $postDateChanged, $postTermsChanged, ?WP_Post $post = null, ?WP_Post $postBeforeMutation = null )Furthermore I added this within the function:
if ($post === null) return;—
I also adjusted the instances where this function is being called, because the order of variables changed…
…this:
self::postMutation( $wpPost, false, false, true );…changed to this:
self::postMutation(false, false, true, $wpPost );…this:
self::postMutation( $wpPost, true, true, false );…changed to this:
self::postMutation(true, true, false, $wpPost );…and this:
self::postMutation( $postAfter, $postStatusChanged, $postDateChanged, false, $postBefore );…changed to this:
self::postMutation($postStatusChanged, $postDateChanged, false, $postAfter, $postBefore );—
You can make your own considerations how to fix this problem. It’s just necessary to take into account that at times
nullis passed as the variable$postto the functionpostMutation, and therefore this circumstance must be caught somehow.Currently, after having made these changes, the PHP fatal error no longer occurs, it seems that this solution is working.
This topic is not a question. If you think this solution works with your plugin you can mark this topic as solved.
Sincerely,
Gevorg
The topic ‘PHP Fatal error … Uncaught TypeError … WP_Post …null given [Solved?]’ is closed to new replies.