PHP code example of inpsyde / object-hooks-remover
1. Go to this page and download the library: Download inpsyde/object-hooks-remover library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
inpsyde / object-hooks-remover example snippets
function remove_object_hook(
string $hook,
class-string $targetClassName,
?string $methodName = null,
?int $targetPriority = null,
bool $removeStaticCallbacks = false
): int
// Somewhere...
class Foo
{
public function __construct()
{
add_action('init', [$this, 'init'], 99);
add_action('template_redirect', [__CLASS__, 'templateRedirect']);
}
public function init(): void
{
}
public static function templateRedirect(): void
{
}
}
new Foo();
// Somewhere else...
Inpsyde\remove_object_hook('init', Foo::class, 'init');
Inpsyde\remove_object_hook('template_redirect', Foo::class, 'templateRedirect', removeStaticCallbacks: true);
function remove_closure_hook(
string $hook,
?object $targetThis = null,
?array $targetArgs = null,
?int $targetPriority = null
): int
$closure = function (string $foo, int $bar, $baz) { /*... */ };
// Somewhere...
class Foo
{
public function __construct()
{
add_filter('template_redirect', $this);
}
public function __invoke()
{
}
}
new Foo();
// Somewhere else...
Inpsyde\remove_invokable_hook('template_redirect', Foo::class);
function remove_all_object_hooks(
class-string|object $targetObject,
?bool $removeStaticCallbacks = null
): int
// Somewhere...
class Foo
{
public function __construct()
{
add_action('init', [$this, 'init'], 99);
add_action('template_redirect', [__CLASS__, 'templateRedirect']);
}
public function init(): void
{
}
public static function templateRedirect(): void
{
}
}
global $foo;
$foo = new Foo();
// Somewhere else...
global $foo;
Inpsyde\remove_all_object_hooks($foo); // remove "init" hook
Inpsyde\remove_all_object_hooks(Foo::class); // would remove both hooks, but only one left
Inpsyde\remove_all_object_hooks($foo, true); // would remove both hooks, but none left
Inpsyde\remove_all_object_hooks(Foo::class, false); // would remove the "init" hook, but none left
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.