百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
W

wp-filters-extras

> 编程语言
开源

为 WP Filter API 添加 2 个方法

182 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

为 WP Filter API 添加 2 个方法

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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