Support » Plugin: Instant Articles for WP » error trying to get property of non-object

  • On some pages of my website (generally pages that aren’t strictly posts, such as category pages and the likes) I am getting error notices:

    Notice: Trying to get property of non-object in /wp-content/plugins/fb-instant-articles/class-instant-articles-post.php on line 939

    I think it may be missing a logic check for an empty object before calling the object’s properties.

    I edited from line 931 adding in a few more logic checks, such as is_object and property_exists:

    		$post = $this->_post;
            
            if(!is_object($post)){
                return false;
            }
            
    		// Don't process if this is just a revision or an autosave.
    		if ( wp_is_post_revision( $post ) || wp_is_post_autosave( $post ) ) {
    			return false;
    		}
    
    		// Don't process if this post is not published
    		if (property_exists($post,'post_status') && 'publish' !== $post->post_status ) {
    			return false;
    		}
    
    		// Only process posts
    		$post_types = apply_filters( 'instant_articles_post_types', array( 'post' ) );
    		if (property_exists($post,'post_type') &&  ! in_array( $post->post_type, $post_types ) ) {
    			return false;
    		}

    The page I need help with: [log in to see the link]

  • The topic ‘error trying to get property of non-object’ is closed to new replies.