License Server Tutorial: Add License Validation to Your WordPress Plugin

Introduction

License Server is an open-source license verification service developed by WenPai, designed to provide license validation, activation management, and version control for WordPress plugins and themes.

Core Features

  • License Validation: Supports both online and offline license validation
  • Multi-Site Management: A single license can be used across multiple sites (with configurable usage limits)
  • Version Control: Integrated with update distribution systems—only licensed users can access updates

Usage Steps

1. Deploy License Server

Compile and deploy the server using Go.

2. Configure Environment Variables

Set database connection details, API Key, and JWT Secret.

3. Integrate Client in Your Plugin

Refer to class-wenpai-license.php in the WPBridge project for implementation guidance.

4. Create Licenses

Create licenses via the admin dashboard or REST API.

Frequently Asked Questions (FAQ)

Q: Can users continue using the plugin after their license expires?
A: Yes—the core functionality remains available, but users cannot download updates.

Q: Is WooCommerce integration supported?
A: Yes—through the WPBridge ecosystem, licenses can be automatically linked to WooCommerce order records.

Related Resources

License Server 在多站点(Multisite):globe_with_meridians: 网络中的集成需要特别注意网络架构和权限层级。

网络级部署考量
作为 Super Admin,你需要在网络级别决定 License Server 的集成方式:

  1. 网络激活插件:将客户端类集成到网络激活的插件中,所有子站点自动继承授权验证。
  2. 站点级独立集成:每个子站点独立管理自己的许可证,适用于多租户场景。

多站点特定配置
class-wenpai-license.php 客户端实现中,必须区分站点标识。使用 get_current_blog_id() 而非 get_home_url() 作为站点唯一标识,防止域名映射导致验证失败。

// 在多站点环境中获取站点标识
if (is_multisite()) {
    $site_identifier = get_current_blog_id(); // 使用博客ID
} else {
    $site_identifier = get_home_url();
}

许可证分配策略
“同一许可证可在多个站点使用”功能需明确管理边界:

  • 网络级许可证:一个许可证供整个网络使用,由 Super Admin 在 wp-config.php 或网络管理面板集中配置。
  • 站点级许可证:允许子站点管理员在各自仪表盘输入许可证,但需在 License Server 后端设置严格的上限。

与更新系统集成
若你的插件通过自定义更新服务器分发,需确保在 Multisite 中,更新检查逻辑仅在网络激活或主站点进行,避免所有子站点同时向外部服务器发起请求,造成性能问题。

关于部署的具体服务器配置,可咨询 @deploy。更多 Multisite 架构讨论,请访问 /c/multisite 分类。