|
1 | 1 | # EDD Software Licensing SDK
|
2 | 2 |
|
3 |
| -## Example Usage |
| 3 | +A drop-in solution for WordPress plugin and theme developers to quickly integrate Easy Digital Downloads Software Licensing into their products without complex setup or custom admin interfaces. |
4 | 4 |
|
5 |
| -```php |
6 |
| -use EDD_SL_SDK\SDK; |
7 |
| - |
8 |
| -require_once 'edd-sl-sdk-main/src/Loader.php'; |
9 |
| - |
10 |
| -add_action( 'edd_sl_sdk_loaded', function ( SDK $sdk ) { |
11 |
| - try { |
12 |
| - $sdk->registerStore( array( |
13 |
| - 'id' => 'sandhillsdev.com', |
14 |
| - 'api_url' => 'https://sandhillsdev.com/wp-json/edd-sl/v2', |
15 |
| - 'author' => 'Sandhills Development, LLC', |
16 |
| - 'products' => array( |
17 |
| - /* Plugin Example */ |
18 |
| - [ |
19 |
| - 'type' => 'plugin', |
20 |
| - 'product_id' => 123, |
21 |
| - 'file' => __FILE__, |
22 |
| - 'version' => '1.0', |
23 |
| - 'beta' => false, |
24 |
| - |
25 |
| - /* |
26 |
| - * Optionally have an admin menu managed for you. |
27 |
| - * Accepts all the same arguments as `add_submenu_page()` |
28 |
| - * @link https://developer.wordpress.org/reference/functions/add_submenu_page/ |
29 |
| - */ |
30 |
| - 'menu' => [ |
31 |
| - 'parent_slug' => 'options-general.php', |
32 |
| - 'page_title' => 'My Plugin License', |
33 |
| - 'menu_title' => 'My Plugin License', |
34 |
| - 'menu_slug' => 'my-plugin-license', |
35 |
| - ], |
36 |
| - ], |
37 |
| - /* Theme Example */ |
38 |
| - [ |
39 |
| - 'type' => 'theme', |
40 |
| - 'product_id' => 125, |
41 |
| - 'beta' => false |
42 |
| - ] |
43 |
| - ) |
44 |
| - ) ); |
45 |
| - } catch ( \Exception $e ) { |
46 |
| - // Optionally do something error messages. |
47 |
| - } |
48 |
| -} ); |
49 |
| -``` |
| 5 | +## Overview |
50 | 6 |
|
51 |
| -## Store Arguments |
52 |
| - |
53 |
| -- `id` - Optional. Unique ID for your store. If omitted, it's generated from your API URL. |
54 |
| -- `api_url` - **Required.** API endpoint. Should be `https://yoursite.com/wp-json/edd-sl/v2` |
55 |
| -- `author` - Optional. Plugin author name. |
56 |
| -- `products` - Optional. Array of product registrations. |
57 |
| -- `update_cache_duration` - Optional. Length of time, in seconds, to cache update API responses. Default is `180` (3 hours). Set to `0` to disable caching. If disabled, a fresh API request is made every time WordPress core checks for plugin/theme updates. |
58 |
| - |
59 |
| -## Product Arguments |
60 |
| - |
61 |
| -- `type` - **Required.** Either `plugin` or `theme` |
62 |
| -- `product_id` - **Required.** ID of the product in your Software Licensing store. |
63 |
| -- `file` - **Required for plugins.** Path to the main plugin file. |
64 |
| -- `version` - **Required for plugins.** Current version number. If omitted for a theme, the version will be parsed from the stylesheet. |
65 |
| -- `slug` - Optional. Name of the theme or plugin directory. |
66 |
| -- `beta` - Optional. Whether to receive beta versions. |
67 |
| -- `menu` - Optional. If set, the SDK will handle rendering an admin page UI, which does license activation and deactivation. This can be set to `true` for all default arguments, or can accept an array of any arguments used by [add_submenu_page()](https://developer.wordpress.org/reference/functions/add_submenu_page/). |
68 |
| -- `license_option_name` - Optional. Name of the option used for saving the license key. By default, it's built using this format: `sl_{type}_{slug}_license`. |
69 |
| -- `license_object_option_name` - Optional. Name of the option used for saving license data. This is the response data from the API when activating/checking a license key. By default, it's built using this format: `sl_{type}_{slug}_license_object`. |
70 |
| -- `license_getter` - Optional. Closure used for retrieving the license key. This can be set if you do not want to save the license key in the options table (such as if you're using a custom table). |
71 |
| -- `license_setter` - Optional. Closure used for setting the license key. |
72 |
| -- `i18n` - Optional. Array of translation-ready strings. See transaction section for available strings. |
73 |
| - |
74 |
| -### Custom getter & setter |
75 |
| - |
76 |
| -Here's an example of how to use a custom getter and setter. In this example, the reason for using a getter and setter is that we're using custom `edd_get/update_option()` functions instead of the ones from WordPress core. |
77 |
| - |
78 |
| -```php |
79 |
| -[ |
80 |
| - 'license_getter' => static function() { |
81 |
| - return edd_get_option( 'my_license_key' ); |
82 |
| - }, |
83 |
| - 'license_setter' => static function ( $newLicense, $previousLicense ) { |
84 |
| - edd_update_option( 'my_license_key', sanitize_text_field( $newLicense ) ); |
85 |
| - } |
86 |
| -] |
87 |
| -``` |
| 7 | +The EDD Software Licensing SDK streamlines the process of adding licensing functionality to your WordPress plugins and themes. Instead of building custom settings pages and handling license validation manually, this SDK provides a complete licensing solution that seamlessly integrates with existing WordPress admin interfaces. |
88 | 8 |
|
89 |
| -### Main plugin with add-ons example |
| 9 | +### Key Features |
90 | 10 |
|
91 |
| -If you sell "add-on" plugins to a main plugin (such as Easy Digital Downloads with its various extensions) then you can optionally only register your store in the main plugin file. Then each add-on adds a product to that existing store. |
| 11 | +- **Zero-configuration licensing** - Add licensing support with just a few lines of code |
| 12 | +- **Native WordPress integration** - License fields appear directly in plugin action links and theme admin menus |
| 13 | +- **Automatic updates** - Handles secure update delivery for licensed products |
| 14 | +- **No custom admin pages** - Uses WordPress's existing interface patterns |
| 15 | +- **Flexible deployment** - Works as a standalone plugin or Composer package |
| 16 | +- **Developer-friendly** - Minimal code required, maximum functionality provided |
92 | 17 |
|
93 |
| -The benefit of this is that you only need to declare your API URL once in the "parent plugin". |
| 18 | +### How It Works |
94 | 19 |
|
95 |
| -Here's how that would look: |
| 20 | +For **plugins**, the SDK adds a "Manage License" link directly in the plugin list on the Plugins admin screen. Clicking this link opens a modal where users can enter and activate their license key. |
96 | 21 |
|
97 |
| -The parent plugin would register the store like this: |
| 22 | +For **themes**, a "Theme License" menu item is automatically added to the Appearance menu, providing easy access to license management via the modal. |
98 | 23 |
|
99 |
| -```php |
100 |
| -add_action( 'edd_sl_sdk_loaded', function ( \EDD_SL_SDK\SDK $sdk ) { |
101 |
| - try { |
102 |
| - $sdk->registerStore( [ |
103 |
| - // ID: Replace `yoursite.com` with the domain name of the site that has Software Licensing installed. |
104 |
| - 'id' => 'yoursite.com', |
105 |
| - // API URL: Replace `yoursite.com` with the domain of the site that has Software Licensing installed. |
106 |
| - 'api_url' => 'https://yoursite.com/wp-json/edd-sl/v2', |
107 |
| - // Author: Your company's name. |
108 |
| - 'author' => 'Sandhills Development, LLC', |
109 |
| - ] ); |
110 |
| - } catch ( \Exception $e ) { |
| 24 | +The SDK handles all the complex licensing logic behind the scenes: |
| 25 | +- License key validation and activation |
| 26 | +- Automatic update notifications and delivery |
| 27 | +- License status tracking and renewal reminders |
| 28 | +- Secure communication with your EDD store |
| 29 | + |
| 30 | +### Perfect For |
| 31 | + |
| 32 | +- Plugin developers who want to focus on features, not licensing infrastructure |
| 33 | +- Theme authors looking for a professional licensing solution |
| 34 | +- Developers transitioning from other licensing systems |
| 35 | +- Anyone who wants licensing integration without reinventing the wheel |
| 36 | + |
| 37 | +## Installation |
| 38 | + |
| 39 | +You can run the SDK as a standalone plugin on your site, or install it as a Composer package in your theme or plugin: |
111 | 40 |
|
112 |
| - } |
113 |
| -} ); |
114 | 41 | ```
|
| 42 | +{ |
| 43 | + "name": "edd/edd-sample-plugin", |
| 44 | + "license": "GPL-2.0-or-later", |
| 45 | + "repositories": { |
| 46 | + "edd-sl-sdk": { |
| 47 | + "type": "vcs", |
| 48 | + "url": "[email protected]:awesomemotive/edd-sl-sdk.git" |
| 49 | + } |
| 50 | + }, |
| 51 | + "require": { |
| 52 | + "easy-digital-downloads/edd-sl-sdk": "1.0.0" |
| 53 | + } |
| 54 | +} |
115 | 55 |
|
116 |
| -Note that if your parent plugin is also a product in itself and not hosted in the .org repo, you'll also need to register the parent plugin's product like so: |
117 |
| - |
118 |
| -```php |
119 |
| -add_action( 'edd_sl_sdk_loaded', function ( \EDD_SL_SDK\SDK $sdk ) { |
120 |
| - try { |
121 |
| - $sdk->registerStore( [ |
122 |
| - // ID: Replace `yoursite.com` with the domain name of the site that has Software Licensing installed. |
123 |
| - 'id' => 'yoursite.com', |
124 |
| - // API URL: Replace `yoursite.com` with the domain of the site that has Software Licensing installed. |
125 |
| - 'api_url' => 'https://yoursite.com/wp-json/edd-sl/v2', |
126 |
| - // Author: Your company's name. |
127 |
| - 'author' => 'Sandhills Development, LLC', |
128 |
| - 'products' => [ |
129 |
| - [ |
130 |
| - 'type' => 'plugin', |
131 |
| - 'product_id' => 123, // @todo replace |
132 |
| - 'file' => __FILE__, |
133 |
| - 'version' => '1.0', // @todo replace |
134 |
| - ] |
135 |
| - ] |
136 |
| - ] ); |
137 |
| - } catch ( \Exception $e ) { |
| 56 | +### Example Usage |
138 | 57 |
|
| 58 | +Plugin: |
| 59 | +```php |
| 60 | +add_action( |
| 61 | + 'edd_sl_sdk_registry', |
| 62 | + function ( $init ) { |
| 63 | + $init->register( |
| 64 | + array( |
| 65 | + 'id' => 'edd-sample-plugin', // The plugin slug. |
| 66 | + 'url' => 'https://edd.test', // The URL of the site with EDD installed. |
| 67 | + 'item_id' => 83, // The download ID of the product in Easy Digital Downloads. |
| 68 | + 'version' => '1.0.0', // The version of the product. |
| 69 | + 'file' => __FILE__, // The path to the main plugin file. |
| 70 | + ) |
| 71 | + ); |
139 | 72 | }
|
140 |
| -} ); |
| 73 | +); |
141 | 74 | ```
|
142 | 75 |
|
143 |
| -Then, each add-on can skip the store registration and piggyback off the parent, like this: |
144 |
| - |
145 |
| -```php |
146 |
| -add_action( 'edd_sl_after_store_registered', function ( \EDD_SL_SDK\Models\Store $store ) { |
147 |
| - if ( 'yoursite.com' === $store->id ) { |
148 |
| - try { |
149 |
| - $store->addProduct( [ |
150 |
| - 'type' => 'plugin', |
151 |
| - 'product_id' => 123, // @todo replace |
152 |
| - 'file' => __FILE__, |
153 |
| - 'version' => '1.0', // @todo replace |
154 |
| - ] ); |
155 |
| - } catch ( \Exception $e ) { |
156 |
| - |
157 |
| - } |
| 76 | +Theme: |
| 77 | +``` |
| 78 | +add_action( |
| 79 | + 'edd_sl_sdk_registry', |
| 80 | + function ( $init ) { |
| 81 | + $init->register( |
| 82 | + array( |
| 83 | + 'id' => 'edd-sample-theme', |
| 84 | + 'url' => 'https://easydigitaldownloads.com', |
| 85 | + 'item_id' => 123, |
| 86 | + 'version' => '1.0.0', |
| 87 | + 'type' => 'theme', |
| 88 | + ) |
| 89 | + ); |
158 | 90 | }
|
159 |
| -} ); |
| 91 | +); |
160 | 92 | ```
|
161 | 93 |
|
162 |
| -This product will be registered to the store that was created in the parent plugin and use the same API URL. |
163 |
| - |
164 |
| -## Strings |
| 94 | +### Arguments |
165 | 95 |
|
166 |
| -If using an admin menu, all the strings used for displaying statuses and response messages can be customized or made translation-ready. |
167 |
| - |
168 |
| -The list of strings can be found here: https://github.com/easydigitaldownloads/edd-sl-sdk/blob/main/src/Helpers/Strings.php#L15-L30 Any strings in the array can be overridden via the `i18n` array when you register your product. |
169 |
| - |
170 |
| -Example: |
171 |
| - |
172 |
| -```php |
173 |
| -[ |
174 |
| - // Other options here. |
175 |
| - 'i18n' => [ |
176 |
| - 'activate_license' => __( 'Activate License', 'my-plugin-text-domain' ), |
177 |
| - // More strings below, if desired. |
178 |
| - ] |
179 |
| -]; |
180 |
| -``` |
| 96 | +- `id` - Plugin/theme slug. |
| 97 | +- `url` - The store URL. |
| 98 | +- `item_id` - The item ID (on your store). |
| 99 | +- `version` - The current version number. |
| 100 | +- `file` - The main plugin file. Not needed for themes. |
| 101 | +- `type` - `plugin` or `theme`. Not needed for plugins. |
| 102 | +- `weekly_check` - Optional: whether to make a weekly request to confirm the license status. Defaults to true. |
0 commit comments