code to fix shit for WPEC gallery

Unless otherwise specified, all code here is licensed GPLv2