Yes, you can do this like that.
You can call foo_init_setup
on init
or on wp
hook and it will work just fine.
I would call it as late as possible, I guess. This way you won’t affect loading time for requests that don’t end with page rendering (for example when template_redirect
is used for redirecting).
PS. There is much bigger problem with your code, though. You create custom table and store only one row with serialized array containing options for your plugin.
It would be much nicer, if you used Options API.