This change adds a check to ensure $post is an object before accessing its ID property. If $post is not an object, $post_id will be set to null, avoiding the warning.
Previously $post->ID was being accessed, but it appears that $post might be an integer or something other than an object, leading to the warning.
Here's the updated line:
$post_id = (is_object($post) && isset($post->ID)) ? $post->ID : null;
This change adds a check to ensure
$post
is an object before accessing itsID
property. If$post
is not an object,$post_id
will be set tonull
, avoiding the warning.Previously
$post->ID
was being accessed, but it appears that$post
might be an integer or something other than an object, leading to the warning.$post_id = ! empty( $post ) ? $post->ID : null;