You may want to consider using the visibility_api module for path/role/css selector visibility. This module is simply an abstracted API to centralize both php and js widget visibility.