Avoid a PHP notice by checking $post before using it

`expand_content()` and `autop_for_non_funcref()` are both hooked to
`’the_content’`. Some plugins apparently run that hook on things that
aren’t a post. So I’ve added a sanity check to see that $post is set
before checking the post type.