| 1 |
CMB2 Field Type: EDD License |
| 2 |
================== |
| 3 |
|
| 4 |
Custom field for [](https://github.com/WebDevStudios/CMB2CMB2](https://github.com/WebDevStudios/CMB2](https://github.com/WebDevStudios/CMB2) to automatically handle [](https://easydigitaldownloads.com/downloads/software-licensing/EDD Software Licensing](https://easydigitaldownloads.com/downloads/software-licensing/](https://easydigitaldownloads.com/downloads/software-licensing/) license activation and item updates. |
| 5 |
|
| 6 |
## Parameters |
| 7 |
|
| 8 |
Field accepts same parameters as field type text, with the addition of the next one: |
| 9 |
|
| 10 |
License parameters: |
| 11 |
- **server** (string, Required) : Server URL to the EDD SL API, for example "http://your-site.com/edd-sl-api" (by default, "") |
| 12 |
- **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__) |
| 13 |
- **item_id** (string, Optional) : Item ID from the server |
| 14 |
- **item_name** (string, Optional) : Item name (same as returned by the function plugin_basename(), example my-plugin/my-plugin.php) |
| 15 |
- **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) |
| 16 |
- **author** (string, Optional) : Item author (by default will get the one provided in the main file header) |
| 17 |
- **wp_override** (bool, Optional) : Set it to true to override WordPress plugin information to get the one provided by your server (by default, false) |
| 18 |
|
| 19 |
Output parameters: |
| 20 |
- **deactivate_button** (string|false, Optional) : Button to deactivate the license (if is valid), set it to false to disable it (by default, "Deactivate License") |
| 21 |
- **clear_button** (string|false, Optional) : Button to deactivate the license (if is valid), set it to false to disable it (by default, "Deactivate License") |
| 22 |
- **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) |
| 23 |
- **renew_license** (string|false, Optional) : Add a link (if is valid), set it to false to disable it (by default, "Renew your license key.") |
| 24 |
- **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) |
| 25 |
- **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)) |
| 26 |
- **hide_license** (bool, Optional) : Hide the license key entered (by default, true) |
| 27 |
- **hide_license_character** (string, Optional) : Character used to hide the license key (by default, "*") |
| 28 |
- **hide_license_visible_characters** (integer, Optional) : Number of characters to keep visible, set it to 0 to completely hide the license key (by default, 4) |
| 29 |
|
| 30 |
|
| 31 |
## Examples |
| 32 |
|
| 33 |
```php |
| 34 |
add_action( 'cmb2_admin_init', 'cmb2_edd_license_metabox' ); |
| 35 |
function cmb2_edd_license_metabox() { |
| 36 |
|
| 37 |
$prefix = 'your_prefix_demo_'; |
| 38 |
|
| 39 |
$cmb_demo = new_cmb2_box( array( |
| 40 |
'id' => $prefix . 'metabox', |
| 41 |
'title' => __( 'EDD License Sample', 'cmb2' ), |
| 42 |
'object_types' => array( 'page', 'post' ), // Post type |
| 43 |
) ); |
| 44 |
|
| 45 |
$cmb_demo->add_field( array( |
| 46 |
'name' => __( 'License', 'cmb2' ), |
| 47 |
'desc' => __( 'Field description (optional)', 'cmb2' ), |
| 48 |
'id' => $prefix . 'license', |
| 49 |
'type' => 'edd_license', |
| 50 |
|
| 51 |
// Field specific settings |
| 52 |
'server' => 'http://your-site.com/edd-sl-api', |
| 53 |
'file' => __DIR__, |
| 54 |
'item_id' => 123, |
| 55 |
'item_name' => 'my-plugin/my-plugin.php', |
| 56 |
'version' => '1.0.0', |
| 57 |
'author' => 'rubengc', |
| 58 |
'wp_override' => true, |
| 59 |
|
| 60 |
// Extra settings |
| 61 |
'deactivate_button' => __( 'Deactivate License', 'cmb2-edd-license' ), // string|false String to set the button text, false to remove it |
| 62 |
'clear_button' => __( 'Clear License', 'cmb2-edd-license' ), // string|false String to set the button text, false to remove it |
| 63 |
'license_expiration' => true, // bool True to enable license expiration notice, false to deactivate it |
| 64 |
'renew_license' => __( 'Renew your license key.', 'cmb2-edd-license' ), // string|false String to set the renew license text, false to remove it |
| 65 |
'renew_license_timestamp' => ( DAY_IN_SECONDS * 30 ), // int Minimum time to show the license renewal text, by default 30 days |
| 66 |
|
| 67 |
// Links, used for license errors as a shortcut to business website |
| 68 |
'renew_license_link' => false, // string|false Link where users can renew their licenses, false to remove it |
| 69 |
'license_management_link' => false, // string|false Link where users can manage their licenses, false to remove it |
| 70 |
'contact_link' => false, // string|false Link where users can contact with your team, false to remove it |
| 71 |
|
| 72 |
// Hide license settings |
| 73 |
'hide_license' => true, // bool True to hide the license (just if license is valid), with default settings license will be displayed as: **********1234 |
| 74 |
'hide_license_character' => '*', // string Character to hide the license |
| 75 |
'hide_license_visible_characters' => 4, // int Number of visible license characters |
| 76 |
) ); |
| 77 |
|
| 78 |
} |
| 79 |
``` |
| 80 |
|
| 81 |
## Retrieve the license status |
| 82 |
|
| 83 |
You can use the function `rgc_cmb2_edd_license_data( $license_key )` to see the data returned by the server of this license (is an stdClass object) |
| 84 |
In Addition, you can use the function `rgc_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) |
| 85 |
|
| 86 |
## Changelog |
| 87 |
|
| 88 |
### 1.1.1 |
| 89 |
|
| 90 |
* Fixed a bug with the license clear and deactivate functions causing that previous value gets back after save the licenses again. |
| 91 |
|
| 92 |
### 1.1.0 |
| 93 |
|
| 94 |
* Prevent to override WordPress sslverify on requests. |
| 95 |
* Updated EDD SL Plugin Updater class to version 1.8.0. |
| 96 |
|
| 97 |
### 1.0.9 |
| 98 |
|
| 99 |
* Clear field when license gets deactivated included when server responds that license has been already deactivated. |
| 100 |
|
| 101 |
### 1.0.8 |
| 102 |
|
| 103 |
* Added the ability to clear license. |
| 104 |
|
| 105 |
### 1.0.7 |
| 106 |
|
| 107 |
* Make hide_license to work always, indepently of the license status. |
| 108 |
|
| 109 |
### 1.0.6 |
| 110 |
|
| 111 |
* Force update transient data on plugins page and update core. |
| 112 |
|
| 113 |
### 1.0.5 |
| 114 |
|
| 115 |
* Updated EDD SL Plugin Updater class to version 1.6.18. |
| 116 |
|
| 117 |
### 1.0.4 |
| 118 |
|
| 119 |
* Prevent to store hidden license value when license is valid. |
| 120 |
|
| 121 |
### 1.0.3 |
| 122 |
|
| 123 |
* Added the ability to hide license. |
| 124 |
* Update example with new field attributes. |
| 125 |
|
| 126 |
### 1.0.2 |
| 127 |
|
| 128 |
* Added invalid license error checks. |
| 129 |
|
| 130 |
### 1.0.1 |
| 131 |
|
| 132 |
* Deactivation functionality. |
| 133 |
* Expiration notice. |
| 134 |
* Renew notice. |
| 135 |
|
| 136 |
### 1.0.0 |
| 137 |
|
| 138 |
* Initial release. |
| 139 |
|