How to include add_filter() in a condition based on $post data

When using anonymous functions in filters you will be unable to remove them later:

Important: To remove a hook, the $function_to_remove and $priority
arguments must match when the hook was added. This goes for both
filters and actions. No warning will be given on removal failure.

Source.