Notifications
Clear all

PATCH REQUEST: PHP Warning: Attempt to read property "ID" on null

1 Posts
1 Users
0 Reactions
4 Views
Posts: 1
Topic starter
(@dsfgij346ij45y)
New Member
Joined: 17 hours ago
[#14648]

Environment:

  • WordPress 7.0.4
  • PHP 8.4
  • WPForo 3.1.4
  • wpForo - Blog Cross Posting - 3.1.6

Error/Warning:

PHP Warning: Attempt to read property "ID" on null in /nas/content/live/oursite/wp-content/plugins/wpforo-cross-posting/wpForoCrossPosting.php on line 893

----

I don't want to create a patch to handle the warning, but it is filling up the logs, and I'd like to get it cleared up.

----

Root cause: wpForoCrossPosting::postContent() is hooked to the_content at priority 9999 and does global $post; $postID = $post->ID; with no null check. the_content fires in some contexts without a populated $post global (REST rendering, admin-ajax, certain widget/feed paths), so it throws.

---- theoretical patch I could drop into mu-plugins----

if (!defined('ABSPATH')) {

exit;

}

 

add_action('wp', function () {

if (empty($GLOBALS['wpForoCrossPosting']) || !is_object($GLOBALS['wpForoCrossPosting'])) {

return;

}

 

$wpfcp = $GLOBALS['wpForoCrossPosting'];

 

remove_filter('the_content', [$wpfcp, 'postContent'], 9999);

 

add_filter('the_content', function ($content) use ($wpfcp) {

global $post;

if (!($post instanceof WP_Post) || empty($post->ID)) {

return $content;

}

return $wpfcp->postContent($content);

}, 9999);

}, 20);

 

Share:
Scroll to top