PHPackages                             arraypress/unhooker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. arraypress/unhooker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arraypress/unhooker
===================

Streamlines the bulk removal of WordPress actions and filters, enabling dynamic, conditional unhooking for enhanced plugin and theme development.

17PHP

Since Apr 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/arraypress/unhooker)[ Packagist](https://packagist.org/packages/arraypress/unhooker)[ RSS](/packages/arraypress-unhooker/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Unhooker WordPress Library
==========================

[](#unhooker-wordpress-library)

The Unhooker library offers a powerful solution for dynamically managing and removing WordPress hooks with an emphasis on conditional logic. This library enables developers to effectively control WordPress actions and filters, ensuring precise customization of WordPress behavior, ideal for complex plugin or theme development.

Features
--------

[](#features)

- **Dynamic Hook Management:** Automatically remove or modify actions and filters from WordPress hooks.
- **Conditional Logic:** Leverage callbacks to conditionally remove actions or set filters based on custom logic.
- **Global Conditions:** Apply a global condition that affects all hook modifications.
- **Error Handling:** Includes robust error handling capabilities to gracefully manage and log issues during hook manipulation.
- **Debugging Support:** Keep track of all modifications to actions and filters, aiding in debugging and ensuring transparency.
- **Flexible Usage:** Tailored for WordPress, perfect for developers needing advanced hook control in plugins or themes.

Minimum Requirements
--------------------

[](#minimum-requirements)

- **PHP:** 7.4 or higher
- **WordPress:** 5.0 or higher

Installation
------------

[](#installation)

Unhooker is a developer library, not a WordPress plugin, so it needs to be included in your WordPress project or plugin.

You can install it using Composer:

```
composer require arraypress/unhooker
```

#### Basic File Inclusion

[](#basic-file-inclusion)

```
// Require the Composer autoloader.
require_once __DIR__ . '/vendor/autoload.php';

// Use the functions from the ArrayPress\Utils namespace.
use function ArrayPress\Utils\Unhooker\remove_actions;
use function ArrayPress\Utils\Unhooker\remove_filters;
use function ArrayPress\Utils\Unhooker\set_filters;
use function ArrayPress\Utils\Unhooker\remove_class_hooks;
```

### Removing Actions and Filters

[](#removing-actions-and-filters)

#### Basic Removal

[](#basic-removal)

Remove actions or filters immediately without conditions:

```
remove_actions( [ 'init' => 'wp_cron' ] );
remove_filters( [ 'the_content' => 'wpautop' ] );
```

### Class Method Removal

[](#class-method-removal)

```
// Example class to add and then remove hooks.
class Example_Class {
    public static function init_hooks() {
        add_action( 'wp_footer', [ self::class, 'footer_action' ], 10 );
    }

	public static function footer_action() {
		echo 'This will be removed by the Unhooker.';
	}
}

// Initialize hooks by the class.
Example_Class::init_hooks();

remove_class_hooks( [
    [
        'hook'        => 'wp_footer',
        'class_name'  => 'Example_Class',
        'method_name' => 'footer_action',
    ]
], 'init' );
```

#### Advanced Removal

[](#advanced-removal)

Remove multiple actions with one call, each with specific conditions and priorities.

```
remove_actions( [
    [ 'hook' => 'wp_head', 'function' => 'wp_generator', 'priority' => 1 ],
    [ 'hook' => 'wp_head', 'function' => 'rel_canonical' ],
    [ 'hook' => 'wp_footer', 'function' => 'wp_print_footer_scripts', 'priority' => 20 ]
], 'wp_loaded', 15 );
```

#### Conditional and Delayed Removal

[](#conditional-and-delayed-removal)

Remove an action only if a certain condition is met, and bind it to a specific hook with a custom priority:

```
remove_actions([
    [ 'hook' => 'wp_footer', 'function' => 'wp_print_footer_scripts', 'priority' => 20 ]
], 'wp_loaded', 15, function() { return is_page( 'home' ); } );
```

### Conditional Removal

[](#conditional-removal)

```
remove_actions( [
    [ 'hook' => 'wp_head', 'function' => 'wp_generator' ]
    ], 'wp', 10, function() { return is_singular('download'); } );
```

### Setting Filters

[](#setting-filters)

#### Basic Filter Setting

[](#basic-filter-setting)

Immediately apply a filter returning a boolean value:

```
set_filters( [ 'show_admin_bar' => false ] );

// Apply multiple filters, each with specific conditions and priorities.
set_filters([
    'show_admin_bar' => [ 'value' => false, 'condition' => function() { return ! current_user_can( 'administrator' ); } ],
    'excerpt_length' => [ 'value' => 20, 'condition' => function() { return is_home(); } ]
], 'init', 20, function() {
    return is_user_logged_in();
} );
```

#### Conditionally Applying Filters on a Hook

[](#conditionally-applying-filters-on-a-hook)

Apply a filter only if a certain condition is met, during a specific hook:

```
set_filters( [ 'show_admin_bar' => false ], 'init', 20, function() { return ! is_user_logged_in(); } );
```

#### Advanced Filter Setting with Error Handling

[](#advanced-filter-setting-with-error-handling)

Set a filter with error handling and conditional logic:

```
set_filters( [
    'comment_post' => true
], 'comments_open', 10, function() {
    return current_user_can( 'moderate_comments' );
}, function( $error ) {
    error_log(' Failed to set filter: ' . $error->getMessage() );
} );
```

Contributions
-------------

[](#contributions)

Contributions to this library are highly appreciated. Raise issues on GitHub or submit pull requests for bug fixes or new features. Share feedback and suggestions for improvements.

License: GPLv2 or later
-----------------------

[](#license-gplv2-or-later)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

###  Health Score

14

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (9 commits)")

### Embed Badge

![Health badge](/badges/arraypress-unhooker/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-unhooker/health.svg)](https://phpackages.com/packages/arraypress-unhooker)
```

###  Alternatives

[coduo/php-humanizer

Humanize values that are readable only for developers

1.7k865.8k25](/packages/coduo-php-humanizer)[amstaffix/pagination

Simple pagination

43293.9k6](/packages/amstaffix-pagination)[dzava/lighthouse

Interface for the Google Lighthouse project

4011.2k](/packages/dzava-lighthouse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
