caspahouzer/license-checker
Composer 安装命令:
composer require caspahouzer/license-checker
包简介
A comprehensive WordPress license checking and management module with LemonSqueezy integration, automatic validation, admin UI integration, and multi-plugin support.
README 文档
README
License module with hook-based admin menu integration for WordPress plugins.
Namespace
SLK\LicenseChecker
Classes
- LicenseChecker - Main singleton controller for license management
- LicenseHelper - HTTP API client for license server communication
- LicenseAdminPage - Admin interface renderer for license page
Features
- ✅ License activation/deactivation/validation
- ✅ Automatic validation every 12 hours (transient-based)
- ✅ REST API integration with license server
- ✅ WordPress admin UI integration
- ✅ Secure form handling with nonces
- ✅ Data storage via WordPress Options API
- ✅ Hook-based menu registration (new architecture)
- ✅ Separate licenses per plugin with unique option names
API Configuration
- Base URL:
https://slk-communications.de/ - Endpoints:
POST /activate- Activate licensePOST /deactivate- Deactivate licensePOST /validate- Validate license
Installation & Setup
1. Instantiating LicenseChecker
In your plugin main file or bootstrap:
// In your plugin file (e.g., slk-my-plugin.php) if (file_exists(__DIR__ . '/modules/LicenseChecker/LicenseChecker.php')) { require_once __DIR__ . '/modules/LicenseChecker/LicenseChecker.php'; if (class_exists('\SLK\LicenseChecker\LicenseChecker')) { // Instantiate with your own text domain \SLK\LicenseChecker\LicenseChecker::instance('my-plugin-domain'); } }
2. Hook-based Menu Registration
The module automatically triggers the TEXTDOMAIN_WITH_UNDERSCORES_admin_menu hook. Register a handler in your admin setup:
// In the admin_menu hook or later do_action('slk_content_bitch_admin_menu', $parent_slug);
Or simpler: Let the fallback system do it automatically - if no handler is registered, it will handle it itself!
Usage
Check License Status via PHP
// Check license for your plugin if (\SLK\LicenseChecker\LicenseChecker::is_active('my-plugin-domain')) { // License is active for your plugin } else { // License is not activated or expired } // Or use the instance directly $license = \SLK\LicenseChecker\LicenseChecker::instance('my-plugin-domain'); if ($license->get_license_status() === 'active') { // Your plugin is licensed }
Access Admin Page
The license admin page is automatically registered as a submenu under the parent menu:
Admin Menu
└── Your Menu
├── Menu Item 1
├── Menu Item 2
└── License (at the end) ← Automatically positioned
Manual Registration (optional)
If you need more control:
$license_manager = \SLK\LicenseChecker\LicenseChecker::instance('my-plugin-domain'); $license_manager->register_submenu('edit.php?post_type=my_cpt');
Option Names
Each plugin stores its license data with a unique prefix:
slk_{plugin_slug}_license_checker_license_key
slk_{plugin_slug}_license_checker_license_status
slk_{plugin_slug}_license_checker_activation_hash
slk_{plugin_slug}_license_checker_license_counts
Example for slk-content-bitch:
slk_content_bitch_license_checker_license_key
slk_content_bitch_license_checker_license_status
slk_content_bitch_license_checker_activation_hash
slk_content_bitch_license_checker_license_counts
Hooks & Actions
slk_register_license_submenu
Triggers license submenu registration:
do_action('slk_register_license_submenu', $parent_slug, $license_manager);
Parameters:
$parent_slug(string) - Parent menu slug (e.g., 'edit.php?post_type=my_cpt')$license_manager(LicenseChecker) - LicenseChecker instance
Example:
add_action('slk_register_license_submenu', function($parent_slug, $license_manager) { $license_manager->register_submenu($parent_slug); }, 10, 2);
slk_register_license_submenu_done_{option_prefix}
Triggers after successful submenu registration:
do_action('slk_register_license_submenu_done_slk_content_bitch_license_checker');
AJAX Actions
JavaScript communication uses the following AJAX actions (varies per plugin):
- slk-license-manager:
slk_license_manager_manage_license - slk-content-bitch:
slk_content_bitch_manage_license
These are automatically registered by the module based on the plugin context.
LicenseChecker Class Methods
Public Methods
// Get singleton instance $instance = LicenseChecker::instance($text_domain = 'slk-license-checker'); // Activate license $result = $instance->activate_license('license-key-here'); // Deactivate license $result = $instance->deactivate_license($license_key, $activation_hash); // Validate license $result = $instance->validate_license($license_key); // Get license status ('active', 'inactive', 'invalid') $status = $instance->get_license_status(); // Get activation counts $counts = $instance->get_license_counts(); // ['activated' => 1, 'limit' => 5] // Register admin menu (orchestrates hook-based registration) $instance->add_admin_menu($parent_slug); // Register submenu directly $instance->register_submenu($parent_slug); // Render license page (used internally) $instance->render_license_form();
Static Methods
// Check if license is active (with plugin support) if (LicenseChecker::is_active('my-plugin-domain')) { // ... } // Check for current plugin (uses default) if (LicenseChecker::is_active()) { // ... }
Menu Registration Architecture
Hook-based Design
The new architecture uses a clean hook-based structure:
1. Plugin calls do_action('slk_license_manager_admin_menu', $parent_slug)
↓
2. LicenseChecker triggers do_action('slk_register_license_submenu', $parent_slug, $this)
↓
3. Plugin registers hook handler for 'slk_register_license_submenu'
↓
4. Hook handler calls $license_manager->register_submenu($parent_slug)
↓
5. License submenu is registered
↓
6. Menu is moved to the end (reorder_submenu_to_end)
↓
7. Active menu item is highlighted (register_active_menu_handler)
Separate Licenses per Plugin (Multi-Plugin Setup)
Both plugins can be active simultaneously with separate and independent licenses:
// In slk-license-manager/slk-license-manager.php \SLK\LicenseChecker\LicenseChecker::instance('slk-license-manager'); // In slk-content-bitch/slk-content-bitch.php \SLK\LicenseChecker\LicenseChecker::instance('slk-content-bitch'); // Each plugin has its own license if (\SLK\LicenseChecker\LicenseChecker::is_active('slk-license-manager')) { // License Manager is licensed } if (\SLK\LicenseChecker\LicenseChecker::is_active('slk-content-bitch')) { // Content Bitch is licensed }
Debugging
Enable the SLK_DEBUG constant for logging:
define('SLK_DEBUG', true);
Logs are output via error_log() (check wp-content/debug.log).
Auto-loading
Classes are automatically loaded via PSR-4 autoloader. No manual require needed, except when initially loading the module.
caspahouzer/license-checker 适用场景与选型建议
caspahouzer/license-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「wordpress」 「validation」 「license」 「license-management」 「license-checker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 caspahouzer/license-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 caspahouzer/license-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 caspahouzer/license-checker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
A Laravel validator for delimiter-separated list of emails.
A CakePHP behavior to validate foreign keys
PHP Validator for stuff.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-01-08