You have an add-on that you want to give away as part of another purchase for certain prices. Yet, you want to allow updates in case there are any. How do you set that up when licenses require a purchase, and licenses need to be activated?
Here’s how I did it using the Easy Digital Downloads Software Licensing extension.
Step 1: Create the download
You’ll want to create the free plugin as a new download under Downloads > Add New. I set the pricing to $0, and set the post as password-protected (since I don’t want want just anyone to download it).
I also enabled software licensing and put a junk key of 1234123412341234 in it, and ensured the license can be activated any number of times and are valid forever:
Save the download but don’t upload your add-on yet, we still need to add in the settings to enable updates.
Step 2: Do a free purchase
Visit the downloads page, add the add-on to the cart, and complete the (free) purchase. This will grab that 1234123412341234 license key and assign it to a purchase so it can be activated.
Step 3: Add Software Licensing to the Add-on
Download a copy of the edd sample plugin that comes with the software licensing extension, and add in the updater. But instead of creating a settings screen, just add in the function to create the updater, along with a modified version of the activate function:
function edd_ecnc_activate_license() { // check if the license is valid if ( 'valid' != get_option( 'ecnc_license_status' ) ) { $license = '1234123412341234'; // data to send in our API request $api_params = array( 'edd_action' => 'activate_license', 'license' => $license, 'item_name' => urlencode( EDD_ECNC_ITEM_NAME ), // the name of our product in EDD 'url' => home_url() ); // Call the custom API. $response = wp_remote_post( EDD_ECNC_STORE_URL, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); // make sure the response came back okay if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) ) { $license_data = json_decode( wp_remote_retrieve_body( $response ) ); // $license_data->license will be either "valid" or "invalid" update_option( 'ecnc_license_status', $license_data->license ); } } } add_action( 'admin_init', 'edd_ecnc_activate_license' );
This will try to activate the license so the updates can work. You don’t need to add in the code for deactivating or the settings screen, just the part to create your EDD_SL_Plugin_Updater with the manually entered license key:
$license_key = '1234123412341234'; // setup the updater $edd_updater = new EDD_ECNC_SL_Plugin_Updater( EDD_SAMPLE_STORE_URL, __FILE__, array( 'version' => '1.0', // current version number 'license' => $license_key, // license key (used get_option above to retrieve from DB) 'item_name' => EDD_SAMPLE_ITEM_NAME, // name of this plugin 'author' => 'Brian Hogg' // author of this plugin ) );
Replacing the EDD_SAMPLE_ITEM_NAME and EDD_SAMPLE_STORE_URL constants with your own.
Step 4: Upload the plugin
Now you can upload the plugin to both the download we just created, and as an option for the variable price you want to include it with.
Step 5: Test
Change the version number to (say) 1.1 and ensure the prompt to update appears under Plugins.
Want to learn more about free and premium (pro) WordPress plugins?
Check out my course, Making Pro Plugins!