Source of small annoyance with errors in debug log
-
Hi codeWrangler, Inc. As of this writing I’m on staffer 2.1, which has worked well enough (thank you). FYI, I did notice it generates warnings in my debug log such as, ‘Trying to get property of non-object’. I tracked it down to the staffer_body_class function at the bottom of this file:
public_html/wp-content/plugins/staffer/public/class-staffer-public.php
What’s happening is the staffer_body_class function appears to be called more than once when the page is called, and at least one of those times $post is considered a non-object, causing the error. To make a long story short, basically I wrapped this check…
if( !is_object($post) ) {}
… around the function’s original if loop. Below is the end result after I modified the code to eliminate the error.
`public function staffer_body_class( $classes ) {
global $post;
$staffer = new Staffer();
$options = $staffer->get_options();
// I added the outside ‘if’ to
//avoid ‘Trying to get property of non-object’ for $post->ID
if( !is_object($post) ) {
return $classes;
}
if( $post->ID == $options[‘main_page_id’] ) {
$classes[] = ‘staffer-main-page’;
}
return $classes;
}
}`
- The topic ‘Source of small annoyance with errors in debug log’ is closed to new replies.