{"id":28138786,"url":"https://github.com/wedevsofficial/wp-utils","last_synced_at":"2026-03-14T07:08:02.966Z","repository":{"id":182384578,"uuid":"650153933","full_name":"weDevsOfficial/wp-utils","owner":"weDevsOfficial","description":"A collection of useful codes and utilities for WordPress plugin development..","archived":false,"fork":false,"pushed_at":"2023-06-23T07:13:38.000Z","size":8,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T19:50:16.212Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/wedevs/wp-utils","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weDevsOfficial.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-06-06T13:05:45.000Z","updated_at":"2024-05-23T08:50:23.000Z","dependencies_parsed_at":"2023-07-20T06:31:13.077Z","dependency_job_id":null,"html_url":"https://github.com/weDevsOfficial/wp-utils","commit_stats":null,"previous_names":["wedevsofficial/wp-utils"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weDevsOfficial%2Fwp-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weDevsOfficial%2Fwp-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weDevsOfficial%2Fwp-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weDevsOfficial%2Fwp-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weDevsOfficial","download_url":"https://codeload.github.com/weDevsOfficial/wp-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254190422,"owners_count":22029639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-14T17:14:59.057Z","updated_at":"2026-03-14T07:08:02.961Z","avatar_url":"https://github.com/weDevsOfficial.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WordPress Utils\n\n[![License: LGPL v3](https://img.shields.io/badge/License-GPL_v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n[![Packagist](https://img.shields.io/packagist/v/wedevs/wp-utils.svg)](https://packagist.org/packages/wedevs/wp-utils)\n![GitHub all releases](https://img.shields.io/github/downloads/weDevsOfficial/wp-utils/total?label=GitHub%20Downloads)\n![Packagist Downloads](https://img.shields.io/packagist/dt/wedevs/wp-utils?label=Packagist)\n\nA collection of useful utilities for WordPress plugin development. Includes an Eloquent-inspired ORM, reusable traits, and common helpers.\n\n## Installation\n\n```bash\ncomposer require wedevs/wp-utils\n```\n\n## Models \u0026 ORM\n\nAn Eloquent-inspired ORM built for WordPress. Define models, query with a fluent builder, and get results as typed collections.\n\n```php\nuse WeDevs\\WpUtils\\Models\\Model;\nuse WeDevs\\WpUtils\\Models\\Traits\\HasTimestamps;\nuse WeDevs\\WpUtils\\Models\\Traits\\SoftDeletes;\n\nclass Contact extends Model {\n    use HasTimestamps, SoftDeletes;\n\n    protected static $table = 'crm_contacts';\n\n    protected $fillable = [ 'first_name', 'last_name', 'email', 'phone' ];\n\n    protected $casts = [\n        'id' =\u003e 'int',\n        'is_active' =\u003e 'bool',\n    ];\n\n    protected static function getHookPrefix() {\n        return 'myplugin';\n    }\n}\n```\n\n### Quick Examples\n\n```php\n// Create\n$contact = Contact::create( [ 'first_name' =\u003e 'John', 'email' =\u003e 'john@example.com' ] );\n\n// Find\n$contact = Contact::find( 1 );\n$contact = Contact::findBy( 'email', 'john@example.com' );\n\n// Query\n$contacts = Contact::query()\n    -\u003ewhere( 'status', 'active' )\n    -\u003ewhere( 'age', '\u003e=', 18 )\n    -\u003eorderBy( 'created_at', 'DESC' )\n    -\u003elimit( 10 )\n    -\u003eget();\n\n// Update\n$contact-\u003eupdate( [ 'phone' =\u003e '555-1234' ] );\n\n// Soft delete \u0026 restore\n$contact-\u003etrash();\n$contact-\u003erestore();\n\n// Aggregates\n$count = Contact::query()-\u003ewhere( 'active', 1 )-\u003ecount();\n$total = Contact::query()-\u003esum( 'amount' );\n\n// Pagination\n$result = Contact::query()-\u003epaginate( 20, 1 );\n// [ 'data' =\u003e Collection, 'total' =\u003e 150, 'per_page' =\u003e 20, ... ]\n```\n\n### Available Traits\n\n| Trait | Description |\n|-------|-------------|\n| `HasTimestamps` | Auto-manages `created_at` and `updated_at` columns |\n| `SoftDeletes` | Soft-delete via `deleted_at` with auto-scoping |\n| `HasHash` | Auto-generates UUID v4 hash on creation |\n\n### Full Documentation\n\nSee **[docs/models.md](docs/models.md)** for the complete guide covering:\n\n- Model definition and configuration\n- Hook prefix system for namespaced WordPress hooks\n- Query builder (WHERE, ORDER, LIMIT, aggregates, pagination, bulk operations)\n- Accessors, mutators, and dirty tracking\n- Collections API\n- Trait details (SoftDeletes, HasTimestamps, HasHash)\n- Lifecycle hooks and filters reference\n\n---\n\n## Traits\n\n### Container\n\nDynamic property storage via `__get`, `__set`, `__isset`, and `__unset` magic methods.\n\n```php\nuse WeDevs\\WpUtils\\Container;\n\nclass MyPlugin {\n    use Container;\n\n    public function __construct() {\n        $this-\u003emy_service = new MyService();\n        $this-\u003emy_service-\u003edoSomething();\n    }\n}\n```\n\n### Hooks\n\nConvenience methods for WordPress action and filter hooks.\n\n```php\nuse WeDevs\\WpUtils\\Hooks;\n\nclass MyPlugin {\n    use Hooks;\n\n    public function __construct() {\n        $this-\u003eadd_action( 'init', 'on_init' );\n        $this-\u003eadd_filter( 'the_title', 'filter_title' );\n    }\n\n    public function on_init() {\n        // ...\n    }\n\n    public function filter_title( $title ) {\n        return $title . ' - Modified';\n    }\n}\n```\n\n### Logger\n\nSimple logging with level support and optional context data. Debug messages only log when `WP_DEBUG` is enabled.\n\n```php\nuse WeDevs\\WpUtils\\Logger;\n\nclass MyPlugin {\n    use Logger;\n\n    public function some_method() {\n        $this-\u003elog_info( 'User logged in', [ 'user_id' =\u003e 5 ] );\n        $this-\u003elog_error( 'Payment failed', [ 'order_id' =\u003e 123 ] );\n        $this-\u003elog_warning( 'Rate limit approaching' );\n        $this-\u003elog_debug( 'Query executed' ); // only when WP_DEBUG is on\n    }\n}\n\n// Output: [INFO][MyPlugin] User logged in {\"user_id\":5}\n```\n\n### Singleton\n\nSingleton pattern with proper per-class instance isolation.\n\n```php\nuse WeDevs\\WpUtils\\Singleton;\n\nclass MySingletonClass {\n    use Singleton;\n}\n\n$instance = MySingletonClass::instance();\n```\n\n## License\n\nThis project is licensed under the GPL 2.0 or Later License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwedevsofficial%2Fwp-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwedevsofficial%2Fwp-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwedevsofficial%2Fwp-utils/lists"}