1. Go to this page and download the library: Download hsm/wplite 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/ */
hsm / wplite example snippets
/**
* Plugin Name: My Plugin
* Description: Built with WPLite.
* Version: 1.0.0
*/
if (!defined('ABSPATH')) exit;
ath(plugin_dir_path(__FILE__));
App::boot();
use MyPlugin\WPLite\Contracts\Middleware;
use MyPlugin\WPLite\Pipeline;
class AuthMiddleware implements Middleware
{
public function handle($request, Pipeline $pipeline)
{
if (!is_user_logged_in()) {
return wp_send_json_error('Unauthorized', 401);
}
return $pipeline->next($request);
}
}
use MyPlugin\WPLite\Facades\App;
// Auto-resolve with dependency injection
$service = App::make(OrderService::class);
// Manual bindings
App::bind('mailer', fn() => new SmtpMailer(appConfig('mail.host')));
$mailer = App::resolve('mailer');
use MyPlugin\WPLite\Provider;
class PaymentProvider extends Provider
{
public function register() { /* bind services */ }
public function bootEarly() { /* before init */ }
public function onInit() { /* on init hook */ }
public function boot() { /* after wp_loaded */ }
public function admin() { /* admin only */ }
public function ajax() { /* ajax only */ }
public function rest() { /* rest api init */ }
public function activate() { /* plugin activation */ }
public function deactivate() { /* plugin deactivation */ }
public function uninstall() { /* plugin uninstall */ }
}
use MyPlugin\WPLite\Model;
class Order extends Model
{
protected $table = 'wp_orders';
public function items()
{
return $this->hasMany('wp_order_items', 'order_id');
}
public function customer()
{
return $this->belongsTo('wp_customers', 'customer_id');
}
}