PHP Warning: Attempt to read property “post_content”
-
This may not be a very practical example, but when previewing a post with no content in the post edit screen, the following error is logged on the server, even if no shortcodes are set:
PHP Warning: Attempt to read property “post_content” on null in /home/production/www/mydomain.com/wp-content/plugins/table-of-contents-plus/includes/class-toc-plus.php on line 1533
The relevant part seems to be the following:
$custom_toc_position = has_shortcode( $post->post_content, 'toc' );
Another cause seems to be that “Attempt to read property ‘—-‘ on null” has become a warning in PHP 8.0.
Personally, I believe the error will not be logged if the following code is added before the above line:
if ( !isset( $post->post_content ) ) {
return false;
}Thank you in advance for your assistance.
- The topic ‘PHP Warning: Attempt to read property “post_content”’ is closed to new replies.