PHPackages                             wp-kit/invoker - 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. wp-kit/invoker

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

wp-kit/invoker
==============

A wp-kit component that handles the invoking of controllers and closures

2.0.6(5y ago)02.5k↓92.9%2MITPHPPHP ^7.4

Since Sep 18Pushed 5y ago1 watchersCompare

[ Source](https://github.com/wp-kit/invoker)[ Packagist](https://packagist.org/packages/wp-kit/invoker)[ Docs](https://github.com/wp-kit/invoker)[ RSS](/packages/wp-kit-invoker/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (1)Versions (8)Used By (2)

wp-kit/invoker
==============

[](#wp-kitinvoker)

This is a wp-kit component that handles the invoking of controllers and closures based on a condition.

This component was built to run within an [`Illuminate\Container\Container`](https://github.com/illuminate/container/blob/master/Container.php) so is perfect for frameworks such as [`Themosis`](http://framework.themosis.com/), [`Assely`](https://assely.org/) and [`wp-kit/theme`](https://github.com/wp-kit/theme).

Often, WordPress developers want to group their [actions and filters](https://codex.wordpress.org/Plugin_API) in a more defined context but do not want to use a traditional controller and would rather invoke a controller based on a condition rather than a path.

Sure, if we are using `Themosis` we can use [`Routes`](http://framework.themosis.com/docs/master/routing/), but we cannot pass in closures directly into the `Route` condition. With `wp-kit/invoker`, you can invoke controllers more easily. Examples are below.

Lastly, as expected a [`Controller`](https://github.com/wp-kit/invoker/blob/master/src/Invoker/Controller.php) is invoked once, and once only during the lifecycle of the application regardless of the number of times the condition is met to invoke the `Controller`.

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

[](#installation)

If you're using `Themosis`, install via [`Composer`](https://getcomposer.org/) in the root fo your `Themosis` installtion, otherwise install in your `Composer` driven theme folder:

```
composer require "wp-kit/invoker"
```

Setup
-----

[](#setup)

### Add Service Provider

[](#add-service-provider)

Just register the service provider and facade in the providers config and theme config:

```
//inside theme/resources/config/providers.config.php

return [
	WPKit\Invoker\InvokerServiceProvider::class, // make sure it's first
    Theme\Providers\RoutingService::class
];
```

### Add Facade

[](#add-facade)

If you are using Themosis or another `Iluminate` driven framework, you may want to add `Facades`, simply add them to your aliases:

```
//inside theme/resource/config/theme.config.php

'aliases' => [
    //
    'Invoker' => WPKit\Invoker\Facades\Invoker::class,
    //
]
```

### Add Config File

[](#add-config-file)

The recommended method of installing config files for `wp-kit` components is via `wp kit vendor:publish` command.

First, [install WP CLI](http://wp-cli.org/), and then install this component, `wp kit vendor:publish` will automatically be installed with `wp-kit/utils`, once installed you can run:

`wp kit vendor:publish`

For more information, please visit [`wp-kit/utils`](https://github.com/wp-kit/utils#commands).

Alternatively, you can place the [config file(s)](config) in your `theme/resources/config` directory manually.

How To Use
----------

[](#how-to-use)

### Invoking

[](#invoking)

```
use WPKit\Invoker\Facades\Invoker;

// as php function as below

// $callback 	( string / array / callable )
// $hook 		( string )
// $condition 	( string / callable )
// $priority 	( int )
// invoke( $callback, $hook, $condition, $priority );

invoke( 'AppController' );

invoke( 'ProductController@someMethod' );

invoke( function() {

	add_filter( 'pre_get_posts', function($query) {

		$query->posts_per_page = 10;

	});

}, 'wp', 'is_front_page', 80 );

invoke( 'App\Controllers\SingleProductController', 'wp', 'is_product' );

invoke( \App\Controllers\CartController::class, 'wp', 'is_cart' );

invoke( 'ShopController', 'wp', function() {

	return is_shop() || is_post_type_archive( 'product') || is_tax( 'product_cat' ) || is_tax( 'product_tag' ) || is_tax( 'product_brand' ) || is_tax( 'company_portal' );

} );

// using facade

Invoker::match( 'SingleProductController@someMethod', 'wp', 'is_product' );

Invoker::match( 'ShopController', 'wp', function() {

	return is_shop() || is_post_type_archive( 'product') || is_tax( 'product_cat' ) || is_tax( 'product_tag' ) || is_tax( 'product_brand' ) || is_tax( 'company_portal' );

} );
```

This may see back to front in terms of how [`Router::match`](https://github.com/illuminate/routing/blob/master/Router.php#L255) works however we feel it is more intuitive to lead with the callback when using the Invoker.

### Controllers

[](#controllers)

`wp-kit/invoker` comes shipped with a [`Controller`](https://github.com/wp-kit/invoker/blob/master/src/Invoker/Controller.php) that you can extend too to enable you to benefit from the enqueue scripts feature which helps to reduce the amount of code you need to write to output scripts and styles through `wp_enqueue_scripts`.

Helpfully, wp-kit comes with two functions to more easily add hooks with reference to the current class. These two functions are `action` and `filter`; these functions fallback to the traditional functions `add_action` and `add_filter` which means they can be used 100% of the time.

```
namespace App\Controllers;

use WPKit\Invoker\Controller;

class FrontPageController extends Controller {

	var $scripts = [
    	'scripts/vendor/modernizr.min.js',
    	'scripts/vendor/foundation.min.js',
    	'scripts/vendor/autocomplete.min.js',
    	'app' => [
    	    'file' => 'scripts/app.min.js'
        ],
    	'scripts/framework/foundation.min.css',
    	'styles/style.css',
	];

	public function getScripts() {

    	wp_deregister_script('jquery-serialize-object');

    	$this->scripts['app']['localize'] = [
            'name' => 'myAjax',
            'data' => [
                'ajax_url' => admin_url( 'admin-ajax.php' )
            ]
        ];

        return parent::getScripts();

	}

	public function beforeFilter() {

		add_action( 'woocommerce_thankyou', array($this, 'bigThanks'), 5 );

		action( 'woocommerce_thankyou', 'smallThanks', 5 );

		add_filter( 'body_class', array($this, 'addBodyClasses') );

		filter( 'body_class', 'addMoreBodyClasses' );

	}

	public function bigThanks() {

		echo 'THANKS';

	}

	public function smallThanks() {

		echo 'thanks!';

	}

	public function addBodyClasses( $classes ) {

		$classes[] = 'some-class';

	    return $classes;

	}

	public function addMoreBodyClasses( $classes ) {

		$classes[] = 'some-other-class';

	    return $classes;

	}

}
```

Get Involved
------------

[](#get-involved)

To learn more about how to use `wp-kit` check out the docs:

[View the Docs](https://github.com/wp-kit/theme/tree/docs/README.md)

Any help is appreciated. The project is open-source and we encourage you to participate. You can contribute to the project in multiple ways by:

- Reporting a bug issue
- Suggesting features
- Sending a pull request with code fix or feature
- Following the project on [GitHub](https://github.com/wp-kit)
- Sharing the project around your community

For details about contributing to the framework, please check the [contribution guide](https://github.com/wp-kit/theme/tree/docs/Contributing.md).

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

[](#requirements)

Wordpress 4+

PHP 5.6+

License
-------

[](#license)

wp-kit/invoker is open-sourced software licensed under the MIT License.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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 ~173 days

Recently: every ~249 days

Total

7

Last Release

2169d ago

PHP version history (3 changes)2.0.0PHP &gt;=5.6.4

2.0.5PHP &gt;=7.2

2.0.6PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b4cf98026bd84498477fafbfb9648807bf87c5ec9a0a404db2e3b7e2739cc8f9?d=identicon)[terence1990](/maintainers/terence1990)

---

Top Contributors

[![terence1990](https://avatars.githubusercontent.com/u/8171301?v=4)](https://github.com/terence1990 "terence1990 (93 commits)")

---

Tags

wordpressinvokerroutingOOPthemosiswp-kitassely

### Embed Badge

![Health badge](/badges/wp-kit-invoker/health.svg)

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

###  Alternatives

[samueltissot/wp_route

2018.9k](/packages/samueltissot-wp-route)[joanrodas/plubo-routes

WordPress routes made simple.

142.8k](/packages/joanrodas-plubo-routes)[szepeviktor/sentencepress

OOP toolkit for daily tasks in WordPress development.

111.4k](/packages/szepeviktor-sentencepress)

PHPackages © 2026

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