ap_remove_all_filters( string $tag, int $priority = false )

Description #

Removes all filters from a WordPress filter, and stashes them in the anspress() global in the event they need to be restored later.

Copied directly from bbPress plugin.

Parameters #

  • $tag
    string (Required)
  • $priority
    int (Optional) Default value: false

Changelog #

VersionDescription
4.2.0Introduced.

Source #

File: includes/functions.php

function ap_remove_all_filters( $tag, $priority = false ) {
	global $wp_filter, $merged_filters;

	$ap = anspress();

	// Filters exist
	if ( isset( $wp_filter[ $tag ] ) ) {

		// Filters exist in this priority
		if ( ! empty( $priority ) && isset( $wp_filter[ $tag ][ $priority ] ) ) {

			// Store filters in a backup
			$ap->new_filters->wp_filter[ $tag ][ $priority ] = $wp_filter[ $tag ][ $priority ];

			// Unset the filters
			unset( $wp_filter[ $tag ][ $priority ] );

		// Priority is empty.
		} else {

			// Store filters in a backup
			$ap->new_filters->wp_filter[ $tag ] = $wp_filter[ $tag ];

			// Unset the filters
			unset( $wp_filter[ $tag ] );
		}
	}

	// Check merged filters
	if ( isset( $merged_filters[ $tag ] ) ) {

		// Store filters in a backup
		$ap->new_filters->merged_filters[ $tag ] = $merged_filters[ $tag ];

		// Unset the filters
		unset( $merged_filters[ $tag ] );
	}

	return true;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment