PHPackages                             wrd/wp-objective - 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. wrd/wp-objective

ActiveLibrary[Framework](/categories/framework)

wrd/wp-objective
================

A set of classes for building consistent WordPress plugins.

1.2.24(1mo ago)1361MITPHPPHP ^8.2.0

Since Oct 23Pushed 3mo agoCompare

[ Source](https://github.com/WRD-Agency/wp-objective)[ Packagist](https://packagist.org/packages/wrd/wp-objective)[ RSS](/packages/wrd-wp-objective/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (31)Used By (0)

WP-Objective
============

[](#wp-objective)

> ⚠️ This package is currently experimental.

Objective is a batteries-included framework for building consistent WordPress plugins.

It includes setup for many common plugin requirements - such as Custom Post Types, Admin Actions, HTTP Clients, Rest API Development, Migrations - all wrapped in a Laravel inspired API.

Created by Kyle Cooper at [WRD Studio](https://wrd.studio).

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

[](#installation)

This project is available for installation via Composer.

```
composer require wrd/wp-objective
```

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

[](#getting-started)

Objective uses a global plugin which serves as a container to manage global objects. You can use the `plugin()` utility to grab the current instance.

The plugin is a container responsible for instantiating objects &amp; injecting their dependencies, using it's bindings to do so.

### Bindings

[](#bindings)

You can also register bindings, allowing every part of Objective to use the correct object/class when looking for it. Objective comes with a range a default bindings to provide sensible defaults and will also look for unbound classes directly when needed.

You can use this functionality override the default `Plugin` instance or any other piece of functionality. For example, by switching the `Logging_Manager` to store to the database.

> ⚠️ You should always bind your own extension of the base `Plugin` class. This allows Objective to keep track of your plugin file/directory.

### Service Providers

[](#service-providers)

You can add in your service providers which come with convenient methods for the WordPress plugin lifecycle. Your service providers allow ways for separate 'components' too hook into the plugin lifecycle without needing to define loose hooks.

### Configuration

[](#configuration)

You can configure your plugin's bindings &amp; service providers by create an extension of the `Plugin` class, like below. In your plugin's entrypoint file you can then create a global instance and boot it.

```
// my-plugin/src/Foundation/My_Plugin.php
use Wrd\WpObjective\Foundation\Plugin;

class My_Plugin extends Plugin {
	/**
	 * Files to include when the plugin is loaded.
	 *
	 * @var string[]
	 */
	public array $files = array(
		// Any files you want to include outside of your typical autoloading.
	);

	/**
	 * Bindings to bind upon boot.
	 *
	 * @var array
	 */
	public array $bindings = array(
		// Any bindings you want to configure.
		// For example, changing the defaut logger:
		Log_Manager::class => My_Log_Manager::class,
	);

	/**
	 * Service providers to register upon boot.
	 *
	 * @var (class-string|Service_Provider)[]
	 */
	public array $providers = array(
		// Any service providers you want to provide.
		My_Post_State::class,
	);
}
```

```
// my-plugin/my-plugin.php
use MyVendor\MyPlugin\Foundation\My_Plugin;

require_once 'vendor/autoload.php';

My_Plugin::create( __FILE__, __DIR__ )->attach();
```

### Plugin Class

[](#plugin-class)

Your plugin should include your own extension of the base `Plugin` class. This is the only item that is required be bound in your config.

The plugin class is primarily responsible for storing your plugin file, directory and version.

It also comes with a range of pre-built hooks for you enqueue assets or spin off any effects need (though it's recommended to use service providers if possible).

```
// my-plugin/src/Plugin.php

namespace MyPlugin;

use Wrd\WpObjective\Foundation\Plugin;

/**
 * Base implementation for a plugin.
 */
class My_Plugin extends Plugin {
	/**
	 * Files to include when the plugin is loaded.
	 *
	 * @var string[]
	 */
	public array $files = array();

	/**
	 * Bindings to bind upon boot.
	 *
	 * @var array
	 */
	protected array $bindings = array();

	/**
	 * Service providers to register upon boot.
	 *
	 * @var (class-string|Service_Provider)[]
	 */
	protected array $providers = array();

	/**
	 * Migrations to load in.
	 *
	 * @var class-string[]
	 */
	protected array $migrations = array();

	/**
	 * Runs on the load.
	 *
	 * @return void
	 */
	public function boot(): void {
		// This page left intentionally blank.
	}

	/**
	 * Runs on the 'init' hook.
	 *
	 * @return void
	 */
	public function init(): void {
		// This page left intentionally blank.
	}

	/**
	 * Runs on the 'init' hook in an admin screen.
	 *
	 * @return void
	 */
	public function admin(): void {
		// This page left intentionally blank.
	}

	/**
	 * Runs on the 'rest_api_init' hook in the rest API.
	 *
	 * @return void
	 */
	public function api(): void {
		// This page left intentionally blank.
	}

	/**
	 * Runs on the 'init' hook in an public screen.
	 *
	 * @return void
	 */
	public function public(): void {
		// This page left intentionally blank.
	}
}
```

### Facades

[](#facades)

Many of the Plugin's bindings can be easily accessed via Laravel-style Facades. Simply call these statically and your call will be mapped to the function in the current instance.

```
Plugin::version();

Flash::success( __('Changes saved successfully.') );

Log::add( message: "Action initiated" );

Migration::add_migration( My_Migration::class );

Settings::set( 'admin_email', 'hello@wrd.agency' );
```

Deeper Dive
-----------

[](#deeper-dive)

### Actions

[](#actions)

It's common for plugins to need to allow their users to perform actions that can be triggered from WordPress. Objective includes the 'Action' class to make this easier.

A permissions callback is required to ensure the user is allowed to perform the action.

You can provide the URL the user should be redirected to upon successful completion.

You can provide arguments, in the same format as the REST API. These will be sanitized &amp; validated before they react your `handle` function.

Define your action like so,

```
/**
 * Action for toggling between dark & light theme.
 */
class Toggle_Theme_Action extends Action {
	/**
	 * Called to check if the current user can undertake this action.
	 *
	 * @return WP_Error|bool
	 */
	public function permissions_callback(): WP_Error | bool {
		return current_user_can( "manage_options" );
	}

	/**
	 * Get the redirection URL upon success.
	 *
	 * @param array $args The arguments passed to the action.
	 *
	 * @return string
	 */
	public function get_destination( array $args ): string {
		return admin_url();
	}

	/**
	 * Get the arguments for the action.
	 *
	 * @return array
	 */
	public function get_arguments(): array {
		return array(
			'theme' => [
				'type' => 'enum',
				'enum' => array(
					'light',
					'dark',
					'context'
				),
			]
		);
	}

	/**
	 * Execute the action.
	 *
	 * @param array $args The arguments passed to the action.
	 *
	 * @return WP_Error|null
	 */
	public function handle( array $args ): WP_Error|null {
		Settings::set( $t )
	}
}
```

You'll need to make sure you either bind or provide your class. Objects that inherit from the `Service_Provider` class (which Action does) will automatically be provided when they're bound.

```
class My_Plugin extends Plugin {
	public $providers = [
		Toggle_Theme_Action::class
	]
}

// OR

plugin()->provide( Toggle_Theme_Action::class );
```

### Collections

[](#collections)

Many of Objective's methods will return a Collection object, rather than an array. This is a class which includes many utility functions for manipulating the data in a fluent API.

You can create your own collection like so,

```
new Collection( array( 1, 2, 3 ) );

// OR

Collection::from( array( 1, 2, 3 ) );
```

If you need to access the raw array underneath, you can always call `$collection->all()`.

### Migrations

[](#migrations)

Migrations allow you to lay out the steps your plugin needs to make for every new version. For example, you might want to create a database table in version 1.0.0 and then you may need to add an additional column to the table in version 1.1.0.

You simply define a migration for each new plugin version that needs to be migrated and Objective will handle running through them upon activation and storing the version currently migrated to.

```
/**
 * Contains the Migration class.
 *
 * @package wrd/wp-objective
 */

namespace Wrd\WpObjective\Foundation\Migrate;

use Wrd\WpObjective\Database\Database_Manager;

/**
 * Migrates to version 1.0.0
 */
class Migration_1_0_0 {
	/**
	 * Get version of the plugin this migration sets up for.
	 *
	 * @return string
	 */
	public function get_version(): string{
		return '1.0.0';
	}

	/**
	 * Run the migration.
	 *
	 * @return void
	 */
	public function up(){
		// Create your custom database table, etc.
	}
}
```

### Learn More

[](#learn-more)

More documentation is coming soon. In the meantime dive into the code to learn more about,

- Post States
- Flashes
- List Tables
- Metaboxes
- Notices
- API Routes
- API Endpoints
- API Objects
- Emails
- HTTP Requests, Responses &amp; Clients
- Money &amp; Currency
- Post Types
- Posts
- Templates
- Settings
- HTML Building

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance84

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.8% 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 ~5 days

Recently: every ~26 days

Total

30

Last Release

47d ago

PHP version history (3 changes)1.0.1PHP &gt;=8.2

1.1.1PHP ^8.3.0

1.2.24PHP ^8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/32ef50777a788e63fcc43cbdb552375205c6c7d50d6ec9b3a23079c0d9a993a1?d=identicon)[kyletcooper](/maintainers/kyletcooper)

---

Top Contributors

[![wrd-sodapixel](https://avatars.githubusercontent.com/u/161863489?v=4)](https://github.com/wrd-sodapixel "wrd-sodapixel (169 commits)")[![kyletcooper](https://avatars.githubusercontent.com/u/100929592?v=4)](https://github.com/kyletcooper "kyletcooper (2 commits)")

---

Tags

packagewordpress

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/wrd-wp-objective/health.svg)

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

###  Alternatives

[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.7k3.7M389](/packages/pimcore-pimcore)[microweber/microweber

New generation CMS with drag and drop

3.4k13.8k1](/packages/microweber-microweber)[imiphp/imi

imi 是一款支持长连接微服务分布式的 PHP 开发框架，可在 PHP-FPM、Swoole、Workerman 和 RoadRunner 等多种容器环境下运行。它支持 HttpApi、WebSocket、TCP、UDP、MQTT 服务的开发。

1.2k46.8k30](/packages/imiphp-imi)[oro/platform

Business Application Platform (BAP)

644134.8k84](/packages/oro-platform)[typo3/cms-extbase

TYPO3 CMS Extbase - Extension framework to create TYPO3 frontend plugins and TYPO3 backend modules.

1812.2M534](/packages/typo3-cms-extbase)[thelia/thelia

Thelia is an ecommerce CMS.

8715.1k](/packages/thelia-thelia)

PHPackages © 2026

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