digitalduz / slswc-client
WooCommerce软件许可服务器
1.1.1
2023-11-13 03:53 UTC
Requires (Dev)
- mockery/mockery: ^1.5
- phpstan/phpstan: ^1.10
This package is not auto-updated.
Last update: 2024-10-01 06:35:29 UTC
README
这是必须包含在您的插件或主题中以提供许可和更新检查的类文件。
用法
使用composer包管理器安装SDK。
composer require digitalduz/slswc-client
然后,以下是如何作为插件使用客户端的示例
$license_server_url = 'http://example.com';
$license_details = array(
'license_key' => 'LICENSE_KEY', // Required
'domain' => 'THE_CURRENT_DOMAIN', // Optional: will default to WordPress site url.
'slug' => 'plugin-slug', // optional. Will use plugin text domain. Must be the product slug on license server.
);
$plugin = Plugin::get_instance( $license_server_url, __FILE__, $license_details );
$plugin->init_hooks();
$license_server_url - 是许可服务器的域名。$base_file - 是插件的主要文件或主题的根文件夹。$license_details - 是许可证详细信息的数组。如果未在插件标题中设置,可能包括插件详细信息。
插件示例
$plugin = Plugin::get_instance( 'http://example.test/', __FILE__, $license_details );
$plugin->init_hooks();
主题示例
$license_details = array(
'license_key' => 'THE_LICENSE_KEY'
);
$theme = Theme::get_instance( 'http://example.test/', WP_CONTENT_DIR . '/themes/theme-directory-name', $license_details );
$theme->init_hooks();
激活许可证
这是激活许可证的示例。您可以在保存许可证密钥后将其挂钩到表单保存。
// Example of how to update the plugin. Run this on a hook.
if ( $plugin->license->get_license_status() !== 'active' ) {
$plugin->license->validate_license();
}
插件标题。
客户端还会搜索其他主题或插件标题以获取有关插件的信息,以下标题如下
- SLSWC - 指定这是插件还是主题,并用于区分SLSWC插件/主题与其他插件/主题。
- 文档URL - 此插件或主题的文档链接
- 所需WP - WordPress所需的最小版本
- 兼容至 - 最大兼容WordPress版本
以下是在插件中使用此功能的完整示例
/** * Plugin Name : Test Plugin Name * Plugin URI : https://example.com/plugins/plugin-name * Description : Basic WordPress plugin to test Software License Server for WooCommerce * Text Domain : text_domain * Author URI : https://example.com * License : https://gnu.ac.cn/licenses/gpl-2.0.html * Version : 1.0.0 * Author : Author Name * Domain Path : /languages * SLSWC : plugin * Documentation URL: https://gnu.ac.cn/licenses/gpl-2.0.html * Required WP : 5.8 * Compatible To: 5.8.1 */ require __DIR__ . '/vendor/autoload.php'; use Digitalduz\Slswc\Client\Plugin; function test_slswc_client_for_plugin() { $license_server_url = 'http://example.com'; $license_details = array( 'license_key' => 'LICENSE_KEY', // Required 'domain' => 'THE_CURRENT_DOMAIN', // Optional: will default to WordPress site url. 'slug' => 'plugin-slug', // optional. Will use plugin text domain. Must be the product slug on license server. ); $plugin = Plugin::get_instance( $license_server_url, __FILE__, $license_details ); $plugin->init_hooks(); } add_action( 'plugins_loaded', 'test_slswc_client_for_plugin', 11 );
以及主题的示例
将其放在functions.php中
require __DIR__ . '/vendor/autoload.php'; use Digitalduz\Slswc\Client\Theme; function theme_slswc_client() { $license_details = array( 'license_key' => 'LICENSE_KEY', // Required 'domain' => 'THE_CURRENT_DOMAIN', // Optional: will default to WordPress site url. 'slug' => 'plugin-slug', // optional. Will use plugin text domain. Must be the product slug on license server. ); $theme = Theme::get_instance( 'http://example.com', WP_CONTENT_DIR . '/themes/theme-folder-name', $license_details ); } add_action( 'wp_loaded', 'theme_slswc_client', 11 );
将其添加到style.css
/* Theme Name : Theme Name Theme URI : https://example.test/themes/your-theme-name/ Author : Author Name Author URI : https://example.test/ Description : Software License Server for WooCommerce Test Theme Version : 1.0 License : GNU General Public License v2 or later License URI : https://gnu.ac.cn/licenses/gpl-2.0.html Tags : blog, two-columns, left-sidebar Text Domain : test-theme SLSWC : theme Documentation URL: https://example.test/docs/test-theme Tested WP : 5.8 Requires WP : 5.8.1 */