Properly flush rewrite rules on plugin activation

Simple way: In my plugins, register_activation_hook always have a line like delete_option('rewrite_rules'); when I’m creating custom post types. WordPress will properly rebuild them.

I’ve provided a detailed answer

Also another inspiring answer here