Presence of 'is_child' causes warnings on non-post pages and new, unsaved posts

Support MB Include Exclude Presence of 'is_child' causes warnings on non-post pages and new, unsaved posts

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3010
    FEDFED
    Participant

    Hello,

    First of all, thank you for the excellent plugin. It's extremely useful.

    While attempting to exclude a MetaBox if a page is the child of another page I encountered the following warning:

    Notice: Trying to get property of non-object in /home/ubuntu/app/wp/wp-content/plugins/meta-box-include-exclude/class-mb-include-exclude.php on line 301

    This seems to be due to the fact that the $post object assumes that there will always be a post_id present. Unfortunately, (as far as I understand) new posts do not have their post_id set until saving and other areas of the Dashboard do not have post_id. This results in the notice being displayed.

    The following is one possible way to get around this issue, though there are likely other ways to approach a solution:

    	public static function check_is_child( $value )
    	{
    		$post     = get_post( self::$post_id );
    		if ( is_object($post) ){
    			$is_child = $post->post_parent ? true : false;
    			return $is_child === $value;
    		} else {
    			return false;
    		}
    	}
    #3025
    Anh TranAnh Tran
    Keymaster

    Thanks a lot, @FED. That's a good fix for the bug. I've just updated the plugin 🙂

    #3033
    FEDFED
    Participant

    Thank you, Anh!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Presence of 'is_child' causes warnings on non-post pages and new, unsaved posts’ is closed to new replies.