PHP Warnings cluttering error log
-
Thank you for this plugin. While it continued working, two conditions triggered warnings.
- When WP’s own twentytwentyone theme’s 404.php was used.
- When updating any post/page, after clearing the check box to unhide its title.
Warning case #1:
Attempt to read property "post_title" on null in .../hide-page-and-post-title.php on line 90
Warning case #2:
Undefined array key "hpt_headertitle" in .../hide-page-and-post-title.php on line 102
Suggested hack case #1. $post == NULL. Replace the line (was 90):
$this->title = $post->post_title;
with this test of the $post var using ‘instanceof’//$this->title = $post->post_title; if ($post instanceof WP_Post) { $this->title = $post->post_title; }
Whenever $post is not a WP_Post object, skip trying to read the title property.
Suggested hack case #2. Replaced the line (was around 102):
$new = $_POST[ $this->hpt_slug ] ;
with this test of the $_POST key//$new = $_POST[ $this->hpt_slug ] ; $new = isset( $_POST[ $this->hpt_slug ] ) ? $_POST[ $this->hpt_slug ] : NULL;
Silence is golden.
- The topic ‘PHP Warnings cluttering error log’ is closed to new replies.