Download the PHP package inpsyde/object-hooks-remover without Composer

On this page you can find all versions of the php package inpsyde/object-hooks-remover. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package object-hooks-remover

Object Hooks Remover

Package to remove WordPress hook callbacks that use object methods or closures.

Static Analysis Unit Tests


What is this?

WordPress plugin API has a partly incomplete implementation.

add_action and add_filter accepts as "callback" any kind PHP callable:

The functions to remove hooks, remove_action and remove_filter, works without issues only with named functions and static object methods (2 of the 5 types of callbacks).

The remaining cases involving object instances remove_action and remove_filter can only be used when having access to the object instance that was used to add hooks, but many times that's not available.

This package provides six functions that can be used to remove hooks that use object methods or closures even without having access to the original object instance.

The package functions are:

You might notice there is no difference between action and filters because, especially in removing, there's absolutely no difference between the two.

The return value of all the functions is the number of callbacks removed.


Inpsyde\remove_object_hook()

This function is used to remove hook callbacks that use object methods. By default, it only targets dynamic methods, but it can be used for static methods passing true to the last parameter.

Usage Example

Inpsyde\remove_closure_hook()

This function targets hook callbacks added using anonymous functions (aka closures).

Closures are the most tricky callbacks to remove because it is hard to distinguish them.

In fact, in PHP, all closures are instances of the same class, Closure, and not having a method name there's very little left to distinguish one closure from another.

This function uses two ways to distinguish closures:

Inpsyde\remove_closure_hook signature is:

The second optional param, $targetThis, can be used to identify the $this of the closure to remove.

It can be:

The third optional param, $targetArgs is an array that can be used to distinguish closures by their parameters.

For example, a closure like this:

can be targeted just by parameter names, passing an array like:

or by parameter names and types, passing an array like:

The two styles can't be mixed, if the type declaration is used for one param it must be used for all of them. In case any of the parameters have no type declaration, null or "mixed" must be used.

It is also possible to pass null as the third argument (or don't pass anything, which is the same because the param defaults to null), and in that case, closures to be removed will be only distinguished by the bound $this.

When both the second and the third arguments are null, which is the default, all closures added to the given hook are removed (only optionally filtered by priority).

Usage Example

Inpsyde\remove_static_method_hook()

Similarly to remove_object_hook() this function targets only static methods.

The signature is:

Usage Example

Even if static class methods could be removed via remove_action / remove_filter, this function can be still useful because can remove callbacks from any priority and even without specifying a method name.

For example, we can use the following to remove all the static methods of the Foo::class attached to the init hook:

Inpsyde\remove_instance_hook()

This function can be used to remove hook callbacks added with a specific object instance.

When having access to the exact instance used to add some hooks, it would be possible to remove those hooks via core functions remove_action / remove_filter, but this function can still be useful because in a single call can remove all the hooks that use the instance, no matter the method or the priority used.

The remove_instance_hook signature is:

Usage Example

Inpsyde\remove_invokable_hook()

This function targets hooks added with invokable objects.

The signature:

Usage Example

Inpsyde\remove_all_object_hooks()

This function is used to remove all hook callbacks that use the given object or class name.

When passing an object instance, it removes all the hook callbacks using that exact instance.

When passing a class name, it removes all the hook callbacks using that class (regardless of the instance).

Static methods are removed when:

Usage Example


Minimum Requirements

Object Hooks Remover is a Composer package, installable via the package name inpsyde/object-hooks-remover.

It has no dependencies and requires PHP 7.4+.

It is tested and guaranteed to work with WP 5.9+, but should work, at least, with WP 5.3+ (which is the first version officially supporting PHP 7.4).


Copyright and License

This package is free software distributed under the terms of the GNU General Public License version 2 or (at your option) any later version. For the full license, see LICENSE.


All versions of object-hooks-remover with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4 < 8.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package inpsyde/object-hooks-remover contains the following files

Loading the files please wait ....