Skip to content
CMB2 field type to store and check EDD Software Licensing licenses.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
includes
cmb2-field-edd-license.php
readme.md

readme.md

CMB2 Field Type: EDD License

Custom field for CMB2 to automatically handle EDD Software Licensing license activation and item updates.

Parameters

Field accepts same parameters as field type text, with the addition of the next one:

License fields:

  • server (string, Required) : Server URL to the EDD SL API, for example "http://your-site.com/edd-sl-api" (by default, "")
  • file (string, Required) : Path to the item main file (for example if you call it from your main plugin file, then you can use FILE)
  • item_id (string, Optional) : Item ID from the server
  • item_name (string, Optional) : Item name (same as returned by the function plugin_basename(), example my-plugin/my-plugin.php)
  • version (string, Optional) : Item version of the installed one to check for updates (by default will get the one provided in the main file header)
  • author (string, Optional) : Item author (by default will get the one provided in the main file header)
  • wp_override (bool, Optional) : Set it to true to override WordPress plugin information to get the one provided by your server (by default, false)

Output fields:

  • deactivate_button (string|false, Optional) : Button to deactivate the license (if is valid), set it to false to disable it (by default, "Deactivate License")
  • license_expiration (bool, Optional) : Add a expiration notice with the remaining time (if is valid), set it to false to disable it (by default, true)
  • renew_license (string|false, Optional) : Add a link (if is valid), set it to false to disable it (by default, "Renew your license key.")
  • renew_license_link (string, Optional) : If you set renew_license also you can add a link to your website to allow to your users renew this license (by default, false)
  • renew_license_timestamp (integer|false, Optional) : If you set renew_license also you can set when notice to the user the license renew, set it to false to show the renew notice always (by default, DAY_IN_SECONDS * 30 (means 30 days before expiration))

Examples

add_action( 'cmb2_admin_init', 'cmb2_edd_license_metabox' );
function cmb2_edd_license_metabox() {

	$prefix = 'your_prefix_demo_';

	$cmb_demo = new_cmb2_box( array(
		'id'            => $prefix . 'metabox',
		'title'         => __( 'EDD License Sample', 'cmb2' ),
		'object_types'  => array( 'page', 'post' ), // Post type
	) );

	$cmb_demo->add_field( array(
		'name'                      => __( 'License', 'cmb2' ),
		'desc'                      => __( 'Field description (optional)', 'cmb2' ),
		'id'                        => $prefix . 'license',
		'type'                      => 'edd_license',
		
		// Field specific settings
		'server'                    => 'http://your-site.com/edd-sl-api',
		'file'                      => __DIR__,
		'item_id'                   => 123,
		'item_name'                 => 'my-plugin/my-plugin.php',
		'version'                   => '1.0.0',
		'author'                    => 'rubengc',
		'wp_override'               => true,
		
		// Extra settings
		'deactivate_button'                 => __( 'Deactivate License', 'cmb2-edd-license' ),      // string|false String to set the button text, false to remove it
		'license_expiration'                => true,                                                // bool         True to enable license expiration notice, false to deactivate it
		'renew_license'                     => __( 'Renew your license key.', 'cmb2-edd-license' ), // string|false String to set the renew license text, false to remove it
		'renew_license_timestamp'           => ( DAY_IN_SECONDS * 30 ),                             // int          Minimum time to show the license renewal text, by default 30 days
		
		// Links, used for license errors as a shortcut to business website
		'renew_license_link' 		        => false,                                               // string|false Link where users can renew their licenses, false to remove it
		'license_management_link' 	        => false,                                               // string|false Link where users can manage their licenses, false to remove it
		'contact_link' 				        => false,                                               // string|false Link where users can contact with your team, false to remove it
		
		// Hide license settings
		'hide_license'                      => true,                                                // bool         True to hide the license (just if license is valid), with default settings license will be displayed as: **********1234
		'hide_license_character'            => '*',                                                 // string       Character to hide the license
		'hide_license_visible_characters'   => 4,                                                   // int          Number of visible license characters
	) );

}

Retrieve the license status

You can use the function cmb2_edd_license_data( $license_key ) to see the data returned by the server of this license (is an stdClass object) In Addition, you can use the function cmb2_edd_license_status( $license_key ) to see the status of this license (valid, invalid or false if not license key or license not checked)

Changelog

1.0.5

  • Updated EDD SL Plugin Updater class to version 1.6.18.

1.0.4

  • Prevent to store hidden license value when license is valid.

1.0.3

  • Added the ability to hide license.
  • Update example with new field attributes.

1.0.2

  • Added invalid license error checks.

1.0.1

  • Deactivation functionality.
  • Expiration notice.
  • Renew notice.

1.0.0

  • Initial release.
You can’t perform that action at this time.