PHP code example of wp-kit / invoker

1. Go to this page and download the library: Download wp-kit/invoker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wp-kit / invoker example snippets


composer 

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

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

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

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


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' );
	
} );



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;
		
	}
	
}