Move endpoint logic into init hook

Loading WP core files by hand is frowned upon