Skip to main content

WordPress SDK

The PaidCommunities WordPress SDK is a powerful tool for WordPress plugin and theme developers to seamlessly integrate license management and automatic updates into their products. This SDK simplifies the process of handling software licensing, updates, and user activation.

Features​

  • Automatic updates management
  • License activation and validation
  • Flexible UI components for license activation
  • Easy integration with WordPress plugins and themes

The SDK provides everything you need to start selling your WordPress plugins and themes through PaidCommunities. Follow this guide to get up and running quickly.

Installation​

To incorporate the PaidCommunities PHP SDK into your project, use Composer:

command line
composer require paidcommunities/wordpress-sdk
License Key Security

PaidCommunities prioritizes the security of your license keys through a robust protection mechanism:

  1. No Direct Storage: License keys are never stored directly in the WordPress database.

  2. Secret Key Mapping: Instead, PaidCommunities generates a unique secret key that maps to the license key in our secure system.

  3. Enhanced Security: This approach significantly enhances security. Even if a customer's WordPress database is compromised, the actual license key remains protected.

  4. Seamless Functionality: Despite this added security, all license-related functions (validation, updates, etc.) continue to work seamlessly.

Why This Matters:

  • Protects against unauthorized use of license keys
  • Reduces risk in case of data breaches
  • Maintains the integrity of your licensing system

Configuration​

There are three main steps to configure the SDK in your plugin:

  1. Add the Update URI to your plugin header
  2. Initialize the SDK with your plugin information
  3. Optional: Configure any custom overrides

1. Update URI​

In your plugin's main file metadata, add the following line:

 * Update URI: https://paidcommunities.com

This signals WordPress to use PaidCommunities for update checks. Here's a complete example:

awesome-seo.php
<?php
/**
* Plugin Name: Awesome SEO
* Plugin URI: https://awesomeseo.com
* Description: The best SEO plugin for WordPress
* Version: 1.0.0
* Author: SEO Experts, support@awesomeseo.com
* Author URI: https://awesomeseo.com
* Text Domain: awesome-seo
* Domain Path: /i18n/languages/
* Tested up to: 6.6
* Update URI: https://paidcommunities.com
*/

require_once( __DIR__ . '/vendor/autoload.php' );

2. Initialize the SDK​

In your plugin's main file, initialize the SDK:

awesome-seo.php
<?php
/**
* Plugin Name: Awesome SEO
* Plugin URI: https://awesomeseo.com
* Description: The best SEO plugin for WordPress
* Version: 1.0.0
* Author: SEO Experts, support@awesomeseo.com
* Author URI: https://awesomeseo.com
* Text Domain: awesome-seo
* Domain Path: /i18n/languages/
* Tested up to: 6.6
* Update URI: https://paidcommunities.com
*/

require_once( __DIR__ . '/vendor/autoload.php' );

// Initialize the SDK
$paidcommunities = new \PaidCommunities\WordPress\PluginConfig(
__FILE___,
$product_id
);

// you can store the $paidcommunties instance any way you like so it
// can be referenced in other code. $product_id is the ID of your product.

3. Overrides​

The PluginConfig class accepts an optional array as a 3rd argument. In this array, you can provide the following overrides:

template_path​

PaidCommunities uses "templates" to render UI components. You can override these templates to customize the different UI elements.

# $template_path is the custom path to your template overrides
# 'templates' must be an instance of the
# PaidCommunities\WordPress\Admin\Templates class
$paidcommunities = new (
plugin_basename( __FILE__ ),
$version,
[
'template_path' => $template_path
]
)
info

For a list of all templates used by the SDK and examples of how to customize them, see our Templates Guide.

option_name​

By default, PaidCommunities stores license information in WordPress's options table using a predictable naming pattern:

{product_id}_license_settings

For example:

  • Product ID: prd_80y2N3N2L11O2ee1
  • Default option name: prd_80y2N3N2L11O2ee1_license_settings

Custom Option Name

You can override the default option name in your plugin configuration:

awesome-seo.php
$config = new \PaidCommunities\WordPress\PluginConfig(
__FILE___,
'prd_80y2N3N2L11O2ee1',
[
'option_name' => 'my_custom_license_option'
]
);

version​

The SDK parses the version from your main plugin's file's metadata headers. You can override this behavior by providing a version if you like.

awesome-seo.php
$config = new \PaidCommunities\WordPress\PluginConfig(
__FILE___,
'prd_80y2N3N2L11O2ee1',
[
'option_name' => 'my_custom_license_option',
'version' => '1.0.0'
]
);

Usage​

Once configured, you can start implementing license management features in your plugin.

Checking License Status​

if ($paidcommunities->getLicense()->isActive()) {
// License is active, enable premium features
} else {
// License is inactive, limit functionality
}

Rendering License Activation Fields​

The SDK provides multiple options for rendering the license activation UI:

1. PHP Rendering​

$paidcommunities->getLicenseSettings()->render();

This will render a license activation field:

Default license activation field before activation

License activation field after successful activation

2. React Components​

Click here to see our comprehensive guide on how to use our React components.

3. Custom UI​

You can also create your own custom UI using the SDK's API.

Enqueuing Scripts​

If you're using the PHP templates you will want to enqueue the paidcommunities-admin-license handle. This script contains Javascript code that listens for click events on the activation/deactivation buttons. You can also write your own script if you prefer to have more control over this functionality.

php
// enqueue in the PHP file that renders your license activation template
wp_enqueue_script('paidcommunities-admin-license');

Enqueuing Styles​

The PHP SDK comes with some basic styling. To include this styling as part of your license activation screen, enqueue the paidcommunities-wp-components handle:

php
wp_enqueue_style('paidcommunities-wp-components');

Automatic Updates​

The SDK automatically hooks into WordPress's update system. When WordPress checks for updates, the SDK will:

  1. Verify the license status
  2. Check for new versions
  3. Provide update information if available

No additional code is required for basic update functionality.

By leveraging the PaidCommunities WordPress SDK, you can easily implement robust licensing and update systems in your WordPress plugins and themes, enhancing your product's security and user experience.

Domain Metadata​

When a domain is registered, you can add your own custom metadata. This metadata will then be available in webhooks and the admin dashboard.

Example:

// $plugin_basename would be awesome-seo/awesome-seo.php
add_filter('domain_metadata_' . $plugin_basename, function(){
$metadata = [
'site' => get_site_url()
];
return $metadata;
});

Webhook Payload:

{
"id": "evt_83D3lAKqHs2vIXTx",
"api_version": "2024-12-01",
"object": "event",
"data": {
"type": "domain",
"object": {
"id": "dom_83D3dKWNMgyQaTj6",
"domain": "example.com",
"license": null,
"version": null,
"metadata": {
"site": "https://example.com"
},
"created_at": "2024-12-31T04:38:53.948Z",
"ip_address": "99.14.100.135",
"last_check": "2024-12-31T04:38:53.910Z",
"license_id": "lic_829jBLVsPP7ivkd7",
"updated_at": null,
"domain_product_versions": [
{
"id": "dprv_83D3dF9jzmuCB9E4",
"domain": null,
"product": null,
"version": "3.2.58",
"metadata": {},
"domain_id": "dom_83D3dKWNMgyQaTj6",
"created_at": "2024-12-31T04:38:53.964Z",
"last_check": "2024-12-31T04:38:53.910Z",
"product_id": "prd_80jidOmdFitybAHD",
"updated_at": null
}
]
}
}
}