Update Public.php - Performance tweak

Only do the class check once, not every time the hook is invoked.