Improved load order for template settings - avoid calling api_get_user_id() without db connection
Minor: fill REMOTE_ADDR when calling from cli interface