Completely rewritten for WP 3.6 & TBS 3.0+