Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

wp-filters-extras

> 编程语言
Open source

Add 2 methods for WP Filter API

182 stars0 likes2 views
WebsiteGitHub

About

Add 2 methods for WP Filter API

WP Filters Extras

Add 2 PHP functions for WP Filter API, it's allow to remove filter/action on hooks for specific cases with CLASS PHP.

These functions are very useful for removing filters and actions from plugin not very well developed!

Remove filters with method name only

remove_filters_with_method_name( $hook_name = '', $method_name = '', $priority = 0 );

Allow to remove method for an hook when, it's a class method used and class don't have global for instanciation !

Remove filters with class and method name

remove_filters_for_anonymous_class( $hook_name = '', $class_name ='', $method_name = '', $priority = 0 );

Allow to remove method for an hook when, it's a class method used and class don't have global for instanciation, but you know the class name :)

Usage

Example :

php
// First sample
class MyClassA {
    function __construct() {
        add_action( 'wp_footer', array( $this, 'my_action' ), 10 );
    }
    function my_action() {
        print '
' . __class__ . ' - ' . __function__ . '
';
    }
}
new MyClassA();

// Second sample
class MyClassB {
    function __construct() {
        add_action( 'wp_footer', array( $this, 'my_action' ), 10 );
    }
    function my_action() {
        print '
' . __class__ . ' - ' . __function__ . '
';
    }
}
new MyClassB();

The problem

With WordPress API, you can't remove the filter my_action because MyClassA and MyClassB don't have a variable ! The right way to load class is : $my_class_b = new MyClassB();

Way 1

This first method, remove_filters_with_method_name();, is fairly aggressive because it removes all filters that have the name "my_action", whatever the class.

php
remove_filters_with_method_name( 'wp_footer', 'my_action', 10 );

This call will remove the 2 filters for classes MyClassA and MyClassB.

Way 2

The second method, remove_filters_for_anonymous_class();, is more accurate because it is necessary to specify both the name of the method but also the name of the PHP class.

php
remove_filters_for_anonymous_class( 'wp_footer', 'MyClassB', 'my_action', 10 );

This call will only remove the filter for the class MyClassB.

Tips

The priority argument of the two functions is important, you must use the same priority as the hook you want to remove !

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言