add hook restricted only to either plugins or themes?

Errm, you can’t. And more importantly, why would you want to? The whole point of hooks is to open up an API to other developers! You can use a singleton/static flags and/or private methods (called from a hooked public method) if you want to lock down how your plugin can be manipulated. static function myfunction_for_themes() … Read more

Adding add_action function

The first thing to do is ensure that your template’s header.php and footer.php files contain, respectively, calls to wp_head() and wp_footer(). Without those functions, no actions hooked to wp_head / wp_footer will work.

plugins_loaded action is not working properly

plugins_loaded is going to load this form much too early, even if you weren’t getting errors. The form is loading before the opening <html tags. You need to select better hooks for this– admin_notices maybe, but it is hard to tell exactly what you want. Second, you need to separate your handler: function process_wpse_194468() { … Read more