PHPackages                             wecodemore/wordpress-early-hook - 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. wecodemore/wordpress-early-hook

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

wecodemore/wordpress-early-hook
===============================

Small library to safely add WordPress hooks before WordPress is loaded.

1.4.1(4mo ago)9127.1k—2.4%13MITPHPPHP &gt;=7.4 &lt; 8.6CI passing

Since Mar 1Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/wecodemore/wordpress-early-hook)[ Packagist](https://packagist.org/packages/wecodemore/wordpress-early-hook)[ RSS](/packages/wecodemore-wordpress-early-hook/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (5)Versions (7)Used By (3)

WP Early Hook
=============

[](#wp-early-hook)

Small library to safely add WordPress hooks before WordPress is loaded.

[![PHP Quality Assurance](https://github.com/wecodemore/wordpress-early-hook/actions/workflows/php-qa.yml/badge.svg?branch=main)](https://github.com/wecodemore/wordpress-early-hook/actions/workflows/php-qa.yml)

---

What
----

[](#what)

This package provides two functions:

- `WeCodeMore\earlyAddAction()`
- `WeCodeMore\earlyAddFilter()`

Having the same signature of WP's `add_action` and `add_filter`, but they are loaded with Composer autoload, and can add hooks *before* WordPress is actually loaded.

Why
---

[](#why)

When we write code for WordPress with Composer support, we might be tempted to use Composer autoload file functionality to add WordPress action and filters.

When the code we're writing is part of a [WP Starter](https://github.com/wecodemore/wpstarter)project that works well, because WP Starter loads the WP plugin API before loading the Composer autoload.

But if we aim to release the code as "standalone" we don't know where it'll be used and so it might be possible that when the Composer autoload file is required the WP plugin API is not loaded yet, and so calling `add_action`/`add_filter` will result in a fatal error.

How
---

[](#how)

The two functions of this package first check if the actual WP functions are available, if so, it used them.

If WP functions are not available, it checks if `ABSPATH` constant is defined. If so, it uses it to load the `wp-includes/plugin.php` file that defines the hooks API. Since WP 4.7, that file is independent of the rest of WordPress and can be loaded before WP is loaded. After the file is loaded, this package's functions can call the WP functions.

In the case not even `ABSPATH` constant is defined, this package's functions resort to fill the `$wp_filter` global variable, which WordPress will "reconciliate" when loaded using [`WP_Hook::build_preinitialized_hooks`](https://github.com/WordPress/WordPress/blob/6.1/wp-includes/class-wp-hook.php#L408).

System Requirements
-------------------

[](#system-requirements)

- PHP 7.1+
- WordPress 4.7+ (Only tested on 5.9+ for PHP 8.1+)

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

[](#installation)

Via Composer, package name is `wecodemore/wordpress-early-hook`.

License
-------

[](#license)

MIT. See [LICENSE](LICENSE) file.

Who's Behind
------------

[](#whos-behind)

I'm Giuseppe, I deal with PHP since 2005. For questions, rants or chat ping me on Mastodon ([@gmazzap@phpc.social](https://phpc.social/@gmazzap)). Well, it's possible I'll ignore rants.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance76

Regular maintenance activity

Popularity39

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 94.7% 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.

###  Release Activity

Cadence

Every ~208 days

Recently: every ~261 days

Total

6

Last Release

131d ago

PHP version history (5 changes)1.0.0PHP &gt;=7.1 &lt; 8.3

1.2.0PHP &gt;=7.1 &lt; 8.4

1.3.0PHP &gt;=7.1 &lt; 8.5

1.4.0PHP &gt;=7.4 &lt;= 8.5

1.4.1PHP &gt;=7.4 &lt; 8.6

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2208282?v=4)[Giuseppe Mazzapica](/maintainers/gmazzap)[@gmazzap](https://github.com/gmazzap)

---

Top Contributors

[![gmazzap](https://avatars.githubusercontent.com/u/2208282?v=4)](https://github.com/gmazzap "gmazzap (18 commits)")[![nlemoine](https://avatars.githubusercontent.com/u/2526939?v=4)](https://github.com/nlemoine "nlemoine (1 commits)")

---

Tags

wordpresshookswpfiltersactionswordpress hookswordpress filterswp hookswp actionswp filterswordpress actions

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wecodemore-wordpress-early-hook/health.svg)

```
[![Health](https://phpackages.com/badges/wecodemore-wordpress-early-hook/health.svg)](https://phpackages.com/packages/wecodemore-wordpress-early-hook)
```

###  Alternatives

[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/packages/tormjens-eventy)[bainternet/php-hooks

A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system

27621.3k2](/packages/bainternet-php-hooks)[voku/php-hooks

A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system

7637.3k3](/packages/voku-php-hooks)[x-wp/di

The dependency injection container for WordPress

301.1k10](/packages/x-wp-di)[millat/laravel-hooks

The WordPress filter, action system in Laravel

5715.1k](/packages/millat-laravel-hooks)

PHPackages © 2026

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