
Ms Eleni Singou
Senior Collection Management & Development Librarian
Library
/** * Removes every OTHER the_content callback via the real remove_filter() * API (not by touching $wp_filter directly), so WP_Hook's own * active-iteration bookkeeping stays consistent. Returns what was * removed, in original priority/order, so restore_callbacks() can put * it back the same way. */ private static function strip_other_callbacks() { global $wp_filter; if ( empty( $wp_filter['the_content'] ) ) { return null; } $hook = $wp_filter['the_content']; $removed = array(); // Read-only enumeration of what's currently registered. foreach ( $hook->callbacks as $priority => $callbacks ) { if ( PHP_INT_MIN === $priority || PHP_INT_MAX === $priority ) { continue; // our own bookend callbacks } foreach ( $callbacks as $cb ) { $removed[] = array( 'priority' => $priority, 'function' => $cb['function'], 'accepted_args' => $cb['accepted_args'], ); } } // Mutate only through core's own API. foreach ( $removed as $item ) { remove_filter( 'the_content', $item['function'], $item['priority'] ); } return $removed; } private static function restore_callbacks( $removed ) { if ( empty( $removed ) ) { return; } foreach ( $removed as $item ) { add_filter( 'the_content', $item['function'], $item['priority'], $item['accepted_args'] ); } }