Skip to content

Plugin Integration

Ashley Gibson edited this page Jul 13, 2021 · 3 revisions

Set up your base plugin file

A bare bones plugin might start out like this:

<?php
/**
 * Plugin Name: Sample Plugin
 * Description: Sample plugin using the Software Licensing SDK.
 * Version: 1.0
 */

// Your plugin code here.

Then you need to include the SDK.

SDK integration

Manual installation

Download a zip file of the SDK and extract it. You'll have a folder called edd-sl-sdk-main with the contents inside. Move this file into your plugin folder, so your plugin will look something like this:

sample-plugin/
    sample-plugin.php
    edd-sl-sdk-main/
        src/
        assets/
        composer.json

You may rename the edd-sl-sdk-main directory to whatever you like, but do not modify the contents inside that directory.

Include the SDK by adding this in your plugin file:

require_once dirname( __FILE__ ) . '/edd-sl-sdk-main/src/Loader.php';

Initializing the auto updater

For a plugin, here are the bare minimum settings:

add_action( 'edd_sl_sdk_loaded', function ( \EDD_SL_SDK\SDK $sdk ) {
	try {
		$sdk->registerStore( [
			// API URL: Replace `yoursite.com` with the domain of the site that has Software Licensing installed.
			'api_url'               => 'https://yoursite.com/wp-json/edd-sl/v2',
			// Author: Your company's name.
			'author'                => 'Sandhills Development, LLC',
			'products'              => [
				[
					'type'       => 'plugin',
					// Product ID: ID of the Software Licensing product this plugin corresponds to.
					'product_id' => 9,
					// File: Path and file name to the main plugin file. Update this if your updater code is not in the main plugin file.
					'file'       => __FILE__,
					// Version: Current plugin version number.
					'version'    => '1.0',
				],
			],
		] );
	} catch ( \Exception $e ) {
		
	}
} );

To add a menu, which will handle license activation and deactivation for you, add a menu parameter like this:

add_action( 'edd_sl_sdk_loaded', function ( \EDD_SL_SDK\SDK $sdk ) {
	try {
		$sdk->registerStore( [
			// API URL: Replace `yoursite.com` with the domain of the site that has Software Licensing installed.
			'api_url'  => 'https://yoursite.com/wp-json/edd-sl/v2',
			// Author: Your company's name.
			'author'   => 'Sandhills Development, LLC',
			'products' => [
				[
					'type'       => 'plugin',
					// Product ID: ID of the Software Licensing product this plugin corresponds to.
					'product_id' => 9,
					// File: Path and file name to the main plugin file. Update this if your updater code is not in the main plugin file.
					'file'       => __FILE__,
					// Version: Current plugin version number.
					'version'    => '1.0',
					// License menu
					'menu'       => [
						'parent_slug' => 'options-general.php',
						'page_title'  => 'Sample Plugin License',
						'menu_title'  => 'Sample Plugin License',
					]
				],
			],
		] );
	} catch ( \Exception $e ) {

	}
} );

For a full list of arguments, see here: https://github.com/easydigitaldownloads/edd-sl-sdk#store-arguments

Clone this wiki locally