1. Home
  2. Docs
  3. WooPress License Hub
  4. How to Integrate WooPress License Hub into Your Plugin

How to Integrate WooPress License Hub into Your Plugin

Before integrating, make sure the distribution server is already configured.
Follow this guide to set up GitHub as a distribution server: Setting Up GitHub as a Distribution Server

This guide explains how to integrate WooPress License Hub with your WordPress plugin, allowing you to manage licenses and updates seamlessly.

1. Add Composer Dependency

Add the WooPress License Hub Client to your plugin using Composer:

composer require ziorwebdev/woopress-license-hub-client:dev-main

This will install the client library, which handles license verification and plugin updates.

For more details, visit the package page: WooPress License Hub Client on Packagist

2. Add Integration Code to Your Plugin

Add the following code snippet to your plugin’s main file. This will initialize the license client:

if ( ! function_exists( 'your_prefix_license_hub_client_integration' ) ) {
	function _your_prefix_license_hub_client_integration() {
		global $_your_prefix_license_hub_client;

		if ( ! isset( $_your_prefix_license_hub_client ) ) {
			$_your_prefix_license_hub_client = woopress_license_hub_client(
				array(
					'api_url'           => 'https://your-site.com/wp-json/wc/woopress-license-hub/',
					'product_key'       => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
					'plugin_file'       => __FILE__,
					'plugin_name'       => 'Your Plugin Name',
					'license_url'       => 'admin.php?page=your-plugin-slug',
					'parent_menu_slug'  => 'your-parent-menu-slug',
					'license_menu_slug' => 'your-plugin-slug',
				)
			);
		}

		return $_your_prefix_license_hub_client;
	}

	_your_prefix_license_hub_client_integration();
}

Replace the placeholders with your actual plugin and license details:

  • api_url: Your WooPress License Hub API endpoint.
  • product_key: Your WooCommerce product key.
  • plugin_name: The name of your plugin.
  • license_url: Admin page for your plugin license settings.
  • parent_menu_slug and license_menu_slug: Your plugin menu slugs.

3. Set Up WooCommerce Product

  1. Create a WooCommerce product that will be tied to your plugin.
  2. Go to the product edit page and click on the “Software Integration” tab.
  3. Here, you will find the API URL and Product Key.
    • The API URL is the endpoint your plugin will use to communicate with WooPress License Hub.
    • The Product Key uniquely identifies your plugin product in WooPress License Hub.
  4. Copy these values and replace the corresponding placeholders in your plugin code (api_url and product_key).
  5. Select “Distribution Server”.
  6. Choose the GitHub Repository Name where your plugin is hosted.
    • This ensures your plugin can receive automatic updates through WooPress License Hub.
  7. Click the “Fetch Software Details from Selected Repository” button.
    • This will fetch your plugin details from the distribution server.
    • The fields in the “Software Details” tab will be automatically populated.

4. Verify Integration

After setting up, your plugin should now:

  • Verify licenses via WooPress License Hub.
  • Receive updates automatically when new versions are released.
  • Display license status in the plugin settings page.

This setup ensures your plugin is fully connected with WooPress License Hub for secure license management and automatic updates.