Is this function not a better mechanism than the *plugin-dir* global var (after the fixes you mentioned above)?