madvault / 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-09-30 07:48:23 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 */