PHPackages                             wedevs/wp-utils - 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. wedevs/wp-utils

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

wedevs/wp-utils
===============

Various WordPress classes and traits for WordPress

v2.0.0(2mo ago)95.3k↓29.2%1[1 PRs](https://github.com/weDevsOfficial/wp-utils/pulls)GPL-3.0-or-laterPHPPHP &gt;=7.4

Since Jun 6Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/weDevsOfficial/wp-utils)[ Packagist](https://packagist.org/packages/wedevs/wp-utils)[ Docs](https://wedevs.com/)[ RSS](/packages/wedevs-wp-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (16)Versions (4)Used By (0)

WordPress Utils
===============

[](#wordpress-utils)

[![License: LGPL v3](https://camo.githubusercontent.com/7b8bafba66ad667644f929650e95999ed543861daa523111404f5f1d5f9b6fd4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d47504c5f76332d626c75652e737667)](https://www.gnu.org/licenses/gpl-3.0)[![Packagist](https://camo.githubusercontent.com/771769e06cef4709056b90960594e337aff3d90014443e9a591503c5b48d2b9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7765646576732f77702d7574696c732e737667)](https://packagist.org/packages/wedevs/wp-utils)[![GitHub all releases](https://camo.githubusercontent.com/301a64a82daa340daa7bc68b99e61a5d4ac1058f2809717404d5343ea4fe40e6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f7765446576734f6666696369616c2f77702d7574696c732f746f74616c3f6c6162656c3d476974487562253230446f776e6c6f616473)](https://camo.githubusercontent.com/301a64a82daa340daa7bc68b99e61a5d4ac1058f2809717404d5343ea4fe40e6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f7765446576734f6666696369616c2f77702d7574696c732f746f74616c3f6c6162656c3d476974487562253230446f776e6c6f616473)[![Packagist Downloads](https://camo.githubusercontent.com/29e3e0d08098a960032068acc8ecb45e6e89c75e3e7d4a5c79d294f205dbdce0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765646576732f77702d7574696c733f6c6162656c3d5061636b6167697374)](https://camo.githubusercontent.com/29e3e0d08098a960032068acc8ecb45e6e89c75e3e7d4a5c79d294f205dbdce0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765646576732f77702d7574696c733f6c6162656c3d5061636b6167697374)

A collection of useful utilities for WordPress plugin development. Includes an Eloquent-inspired ORM, reusable traits, and common helpers.

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

[](#installation)

```
composer require wedevs/wp-utils
```

Models &amp; ORM
----------------

[](#models--orm)

An Eloquent-inspired ORM built for WordPress. Define models, query with a fluent builder, and get results as typed collections.

```
use WeDevs\WpUtils\Models\Model;
use WeDevs\WpUtils\Models\Traits\HasTimestamps;
use WeDevs\WpUtils\Models\Traits\SoftDeletes;

class Contact extends Model {
    use HasTimestamps, SoftDeletes;

    protected static $table = 'crm_contacts';

    protected $fillable = [ 'first_name', 'last_name', 'email', 'phone' ];

    protected $casts = [
        'id' => 'int',
        'is_active' => 'bool',
    ];

    protected static function getHookPrefix() {
        return 'myplugin';
    }
}
```

### Quick Examples

[](#quick-examples)

```
// Create
$contact = Contact::create( [ 'first_name' => 'John', 'email' => 'john@example.com' ] );

// Find
$contact = Contact::find( 1 );
$contact = Contact::findBy( 'email', 'john@example.com' );

// Query
$contacts = Contact::query()
    ->where( 'status', 'active' )
    ->where( 'age', '>=', 18 )
    ->orderBy( 'created_at', 'DESC' )
    ->limit( 10 )
    ->get();

// Update
$contact->update( [ 'phone' => '555-1234' ] );

// Soft delete & restore
$contact->trash();
$contact->restore();

// Aggregates
$count = Contact::query()->where( 'active', 1 )->count();
$total = Contact::query()->sum( 'amount' );

// Pagination
$result = Contact::query()->paginate( 20, 1 );
// [ 'data' => Collection, 'total' => 150, 'per_page' => 20, ... ]
```

### Available Traits

[](#available-traits)

TraitDescription`HasTimestamps`Auto-manages `created_at` and `updated_at` columns`SoftDeletes`Soft-delete via `deleted_at` with auto-scoping`HasHash`Auto-generates UUID v4 hash on creation### Full Documentation

[](#full-documentation)

See **[docs/models.md](docs/models.md)** for the complete guide covering:

- Model definition and configuration
- Hook prefix system for namespaced WordPress hooks
- Query builder (WHERE, ORDER, LIMIT, aggregates, pagination, bulk operations)
- Accessors, mutators, and dirty tracking
- Collections API
- Trait details (SoftDeletes, HasTimestamps, HasHash)
- Lifecycle hooks and filters reference

---

Traits
------

[](#traits)

### Container

[](#container)

Dynamic property storage via `__get`, `__set`, `__isset`, and `__unset` magic methods.

```
use WeDevs\WpUtils\Container;

class MyPlugin {
    use Container;

    public function __construct() {
        $this->my_service = new MyService();
        $this->my_service->doSomething();
    }
}
```

### Hooks

[](#hooks)

Convenience methods for WordPress action and filter hooks.

```
use WeDevs\WpUtils\Hooks;

class MyPlugin {
    use Hooks;

    public function __construct() {
        $this->add_action( 'init', 'on_init' );
        $this->add_filter( 'the_title', 'filter_title' );
    }

    public function on_init() {
        // ...
    }

    public function filter_title( $title ) {
        return $title . ' - Modified';
    }
}
```

### Logger

[](#logger)

Simple logging with level support and optional context data. Debug messages only log when `WP_DEBUG` is enabled.

```
use WeDevs\WpUtils\Logger;

class MyPlugin {
    use Logger;

    public function some_method() {
        $this->log_info( 'User logged in', [ 'user_id' => 5 ] );
        $this->log_error( 'Payment failed', [ 'order_id' => 123 ] );
        $this->log_warning( 'Rate limit approaching' );
        $this->log_debug( 'Query executed' ); // only when WP_DEBUG is on
    }
}

// Output: [INFO][MyPlugin] User logged in {"user_id":5}
```

### Singleton

[](#singleton)

Singleton pattern with proper per-class instance isolation.

```
use WeDevs\WpUtils\Singleton;

class MySingletonClass {
    use Singleton;
}

$instance = MySingletonClass::instance();
```

License
-------

[](#license)

This project is licensed under the GPL 2.0 or Later License.

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance87

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~506 days

Total

3

Last Release

66d ago

Major Versions

v1.1 → v2.0.02026-03-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/55963648efea4511889f497782980f9a8776a911dd500cba980e1840cb6c92d5?d=identicon)[tareq1988](/maintainers/tareq1988)

---

Top Contributors

[![tareq1988](https://avatars.githubusercontent.com/u/153669?v=4)](https://github.com/tareq1988 "tareq1988 (5 commits)")

---

Tags

wordpressutilsclassestraits

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wedevs-wp-utils/health.svg)

```
[![Health](https://phpackages.com/badges/wedevs-wp-utils/health.svg)](https://phpackages.com/packages/wedevs-wp-utils)
```

###  Alternatives

[php-stubs/wordpress-stubs

WordPress function and class declaration stubs for static analysis.

19513.0M263](/packages/php-stubs-wordpress-stubs)[wpsitecare/carelib

A collection of helpful functions to make creating an awesome theme more enjoyable.

164.6k](/packages/wpsitecare-carelib)

PHPackages © 2026

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