Fix bugs, add defensive programming and use WP coding standards

This pull request aims to:
 - Prevent some errors by doing extra checks for existing variables before using them
 - Update the code style to match WP coding standards.
 - Fix an error where if no CPTs were selected in backend the plugin didn't use the default ones.
 - Fix an error where publish to discourse was always happening if post type was enabled and post status was published regardless of the value of 'Publish to discourse' checkbox.
 - Replace comment template only for posts that are published to discourse if 'Use Discourse to comment ...' is checked in admin options.