• Stars
    star
    176
  • Rank 216,987 (Top 5 %)
  • Language
    PHP
  • Created about 12 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 :

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

// Second sample
class MyClassB {
    function __construct() {
        add_action( 'wp_footer', array( $this, 'my_action' ), 10 );
    }
    function my_action() {
        print '<h1>' . __class__ . ' - ' . __function__ . '</h1>';
    }
}
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.

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.

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 !

More Repositories

1

wordpress-cli-tools

Collection of tools for WordPress
PHP
15
star
2

hyperdb

HyperDB is an advanced database class that supports replication, failover, load balancing, and partitioning.
10
star
3

less_theme_generator

Manage Less/CSS of WordPress theme with compilation/cache on fly
PHP
9
star
4

wordpress-media-remove-accents

Remove accents for existing media on WordPress.
PHP
7
star
5

simple-taxonomy

A WordPress plugin for manage custom taxonomies on WordPress
PHP
7
star
6

simple-post-gmaps

A WordPress plugin that allow to geolocalise post with Google Maps (API in v3). No google maps key are required. You can choose with the map the position of the post on admin
PHP
5
star
7

relation-post-types

This WordPress plugin allow to build relation between 2 custom types, very useful for manage related content.
PHP
4
star
8

wpms-remove-prefix-blog

Remove prefix /blog/ for WordPress Multisite Subfolders installation
PHP
3
star
9

bea-post-offline

WordPress plugin for create new post status "offline" and add WP Cron task to change post status when the expiration date has passed
PHP
3
star
10

my-taxonomy-order

A WordPress plugin for order any taxonomies of WP
PHP
2
star
11

ms-generator

Custom website generator for WordPress Multisite, allow to clone a existing website
1
star
12

wp-goodbarber

Fork of GoodBarber WordPress plugin
PHP
1
star
13

simple-sidebars

Manage dynamic sidebar on WordPress
PHP
1
star
14

activecollab-fr

Traduction française du logiciel de gestion de projets activeCollab / French translation of projects software activeCollab
PHP
1
star
15

simple-custom-types

WordPress 3.1 and up allow to manage new custom post type, this plugin makes it even simpler, removing the need for you to write any code.
PHP
1
star
16

simple-taxonomy-image

PHP
1
star
17

fancy-gallery

Fork of Fancy Gallery Plugins with no ads
1
star
18

post-types-taxonomies-intersections

A WordPress plugin that allow to create intersections between a post type and a taxonomy
1
star
19

simple-shortcodes-manager

A WordPress plugin for manage shortcodes on WordPress
PHP
1
star
20

simple-snap

A WordPress plugin for build a glossary
PHP
1
star
21

meta-for-blogs

Meta table for blogs of WordPress Multisite (old WPmu)
PHP
1
star
22

bea-post-views-counter-fullphp-addon

This addon to BEA Post Views Counter add a full PHP implementation for increment counter
PHP
1
star
23

wpms-direct-media-url

Replace virtual link created by old version of WordPress Multisite with a direct URL to media !
PHP
1
star
24

shortcuts

A WordPress plugin for create addresses simple and SEO friendly to make complex query on your contents. A kind of "Views drupal" for WordPress.
PHP
1
star