PHPackages                             codemystify/wordforge - 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. [Framework](/categories/framework)
4. /
5. codemystify/wordforge

ActiveWordpress-plugin[Framework](/categories/framework)

codemystify/wordforge
=====================

Opinionated, zero-dependency MVC Framework for structured WordPress plugin development

v1.6.0(1y ago)52734MITPHPPHP &gt;=8.0CI passing

Since Apr 27Pushed 1y ago2 watchersCompare

[ Source](https://github.com/codestify/wordforge)[ Packagist](https://packagist.org/packages/codemystify/wordforge)[ RSS](/packages/codemystify-wordforge/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (6)Versions (9)Used By (0)

WordForge
=========

[](#wordforge)

A Laravel-inspired routing system for WordPress REST API with PHP 8 compatibility.

Features
--------

[](#features)

- Laravel-style route definitions
- Parameter constraints and validation
- Route groups and middleware
- Resource routing
- Named routes with URL generation

Usage
-----

[](#usage)

### Basic Routes

[](#basic-routes)

```
use Route;

// Define a simple GET route
Route::get('posts', 'PostController@index');

// Route with parameters
Route::get('posts/{id}', 'PostController@show');

// Route with parameter constraints
Route::get('posts/{year}/{month}', 'PostController@archive')
    ->where('year', '[0-9]{4}')
    ->where('month', '[0-9]{1,2}');
```

### Route Groups

[](#route-groups)

```
Route::group(['prefix' => 'api/v1', 'middleware' => 'auth'], function () {
    Route::get('users', 'UserController@index');
    Route::post('users', 'UserController@store');
    Route::get('users/{id}', 'UserController@show');
});
```

### Resource Routes

[](#resource-routes)

```
// Define a resource route
Route::resource('posts', 'PostController');

// Define an API resource route (no create/edit endpoints)
Route::apiResource('users', 'UserController');
```

### Named Routes

[](#named-routes)

```
// Named route
Route::get('posts/{slug}', 'PostController@showBySlug')->name('posts.slug');

// Generate URL by route name
$url = Route::url('posts.slug', ['slug' => 'hello-world']);
```

Parameter Conversion
--------------------

[](#parameter-conversion)

WordForge automatically converts Laravel-style route parameters to WordPress REST API compatible format:

Laravel FormatWordPress Format`posts/{id}``posts/(?P[0-9]+)``posts/{slug}``posts/(?P[a-z0-9-]+)``posts/{postId}``posts/(?P[0-9]+)``posts/{year}/{month?}``posts/(?P[0-9]{4})(/(?P[0-9]{1,2}))?`Middleware
----------

[](#middleware)

```
// Define middleware directly on routes
Route::get('profile', 'ProfileController@show')->middleware('auth');

// You can also pass an array of middleware
Route::get('admin', 'AdminController@index')->middleware(['auth', 'admin']);
```

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

[](#installation)

```
composer require your-vendor/wordforge
```

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- WordPress 5.5 or higher: An Opinionated SLIM MVC architecture for building WordPress Plugins

[![CI Status](https://github.com/codestify/wordforge/actions/workflows/ci.yml/badge.svg)](https://github.com/codestify/wordforge/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/f32695bd6f65b12545162e869707d33dac6bcb5f6e5dc0d48b6d1f8162b6c247/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e302d626c75652e737667)](https://php.net/)

WordForge is a simple, opinionated SLIM MVC framework for WordPress that brings structure to plugin development. While WordPress is a powerful platform, plugins often become unwieldy and disorganized as they grow in complexity. WordForge addresses this problem by providing a clear architectural pattern inspired by Laravel, but with zero third-party dependencies.

Table of Contents
-----------------

[](#table-of-contents)

- [Why WordForge?](#why-wordforge)
- [Features](#features)
- [Installation](#installation)
- [Getting Started](#getting-started)
    - [Basic Setup](#basic-setup)
    - [Creating Routes](#creating-routes)
    - [Route Parameter Constraints](#route-parameter-constraints)
    - [Creating Controllers](#creating-controllers)
    - [Form Request Validation](#form-request-validation)
    - [Using the Query Builder](#using-the-query-builder)
    - [Middleware](#middleware)
    - [Helper Functions](#helper-functions)
- [Advanced Usage](#advanced-usage)
    - [Service Providers](#service-providers)
    - [Service Management](#service-management)
    - [Custom Validation Rules](#creating-custom-validation-rules)
    - [Working with Views](#working-with-views)
    - [Assets and URLs](#assets-and-urls)
    - [Configuration Management](#configuration-management)
- [Project Structure](#project-structure)
- [Philosophy](#philosophy)
- [Limitations](#limitations)
- [Testing](#testing)
- [License](#license)
- [Credits](#credits)

Why WordForge?
--------------

[](#why-wordforge)

WordPress plugin development often lacks structure. As plugins grow, code becomes scattered across files with no clear organization. WordForge addresses this problem by providing:

- **Clear Structure**: Know exactly where to put your code
- **Zero Dependencies**: No external packages required beyond WordPress core
- **Laravel-inspired Patterns**: Familiar patterns for developers who know Laravel
- **Maintainable Code**: Easier to maintain and extend your plugins
- **Focused Simplicity**: Intentionally lightweight - just what you need

Features
--------

[](#features-1)

- **Structured MVC Architecture** with controllers, views, and a simple model layer
- **Laravel-style Routing** with named routes, route groups, and resource controllers
- **Clean Query Builder** for more readable database interactions
- **Form Request Validation** to simplify data validation
- **Service Providers** with hook-based initialization, similar to Laravel's service container
- **Facades** for cleaner static interfaces
- **Simple Middleware System** for filtering HTTP requests
- **WordPress REST API Integration** with elegant request/response handling
- **Configuration Management** with environment-aware settings
- **Service Management** for organizing dependencies without a full container

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

[](#installation-1)

You can install the package via composer:

```
composer require codemystify/wordforge
```

Getting Started
---------------

[](#getting-started)

### Basic Setup

[](#basic-setup)

After installing the package, you need to initialize WordForge in your plugin with just one line:

```
