Deploying Paid Plugins


Paid plugins often rely on license keys for automatic updates and support requests. However it’s the wild west when it comes to how their licensing systems work. Seems like every plugin author ends up implementing their own licensing system.

I discovered this as I was recently creating bash scripts to automate deploying various paid plugins. Let’s look at a few popular plugins and their internal licensing mechanisms with suggestions on how to automate deployments. This will cover Advanced Custom Fields Pro, Event Calendar Pro, SearchWP Pro, WP Smush Pro and WP101.

Creating your own downloadable links using zip and crontab.

If you want to install a plugin on the WordPress.org directory you simply pass it’s slug into WP-CLI. Running wp plugin install jetpack will install Jetpack. There is no central directory for paid plugins. Some plugin authors have private link which you can pass into WP-CLI however many require manual download and installation.

To overcome this limitation we can piggyback on a website we own to serve out proper ZIP files for all of our paid plugins. On the backend of https://anchor.host I have a number of paid plugin installed for such purposes. Each night a cron job loops through these paid plugins and generates a zip file which I can then pass down to my deployment scripts.

My actual implementation is a bit different as I use a command with CaptainCore to pull this off. However you can do this manually by creating the following script plugins-zip.sh on your local computer.

plugins=(plugin-slug-1 plugin-slug-2 plugin-slug-3)
cd wp-content/plugins
for plugin in ${plugins[@]}; do
	zip -r ${plugin}.zip $plugin
done

Then run the script on the remote server using SSH.

ssh username@sitename.net "bash -s" < plugins-zip.sh

This will generate zip files for all of the paid plugin listed in plugins-zip.sh. These will be publicly accessible given the correct format /wp-content/plugins/plugin-slug-1.zip. I recommend adding the above ssh command to crontab and run nightly. That will make sure these zip files are keep up to date.

Remote SSH scripts to install and activate license keys.

Now that we have a way to generate zip files for paid addons the next step is to create scripts to install and activate license keys. I’ll walk through this process for each paid addons I’ll be covering. For each code example you’ll need to replace my_secret_license_key_here and https://sitename.net with your proper license keys and piggyback server address.

1. Advanced Custom Fields Pro

ACF Pro seems to have quite an advanced licensing system. It starts by making a web request to ACF’s server with some basic info like site’s domain and license key. Once processed it then store the license info locally within the wp_options table in the key acf_pro_license. You can see what’s stored in this field using maybe_unserialize and base64_decode functions with WP-CLI.

wp eval '$acf_license = get_option( "acf_pro_license" ); \
print_r( maybe_unserialize( base64_decode ( $acf_license ) ) );'
WP-CLI output of ACF Pro license details

Attempting to add this info to the wp_options table directly won’t work as ACF’s servers need to know about the site first. You can see more about that web request if your read the code acf_updates()->request('v2/plugins/activate?p=pro', $post). Read more details here. The full deployable script may look a bit messy however it works

wp plugin install https://sitename.net/wp-content/plugins/advanced-custom-fields-pro.zip --force --activate
read -r -d '' php_code << 'heredoc'
<?php

// Loads ACF plugin
include_once( ABSPATH . 'wp-content/plugins/advanced-custom-fields-pro/acf.php');

// connect
$post = array(
    'acf_license'   => 'my_secret_license_key_here',
    'acf_version'   => acf_get_setting('version'),
    'wp_name'       => get_bloginfo('name'),
    'wp_url'        => home_url(),
    'wp_version'    => get_bloginfo('version'),
    'wp_language'   => get_bloginfo('language'),
    'wp_timezone'   => get_option('timezone_string'),
);

// connect
$response = acf_updates()->request('v2/plugins/activate?p=pro', $post);

// ensure response is expected JSON array (not string)
if( is_string($response) ) {
    $response = new WP_Error( 'server_error', esc_html($response) );
}

// error
if( is_wp_error($response) ) {
    echo $response->get_error_message();
}

// success
if( $response['status'] == 1 ) {
    echo wp_strip_all_tags( $response['message'] );
    acf_pro_update_license( $response['license'] ); // update license
} else {
    echo wp_strip_all_tags( $response['message'] );
}
heredoc

echo -n "$php_code" > run.php
wp eval-file run.php
rm run.php
wp plugin update advanced-custom-fields-pro

2. Event Calendar Pro

This plugin is pretty smart. In fact you can install both the free and paid plugins using just WP-CLI. The Pro version has a special formatted link which looks like https://pue.tri.be/api/plugins/v2/download?plugin=events-calendar-pro&key=my_secret_license_key_here. Simply replace my_secret_license_key_here with your actual Event Calendar Pro license key. This will install the Event Calendar Pro and also automatically activate with the proper license key.

wp plugin install the-events-calendar --force --activate
wp plugin install "https://pue.tri.be/api/plugins/v2/download?plugin=events-calendar-pro&key=my_secret_license_key_here" --force --activate

3. SearchWP Pro

SearchWP Pro needs the license key added the wp_options table then some code to trigger the license activation. The following 3 lines of WP-CLI will handle that.

wp plugin install https://sitename.net/wp-content/plugins/searchwp.zip --force --activate
wp option set searchwp_license_key my_secret_license_key_here
wp eval '$license_manager = new SearchWP_Settings_Implementation_License(); $license_manager->activate("my_secret_license_key_here");'

4. WP Smush Pro

WP Smush Pro is part of the WPMU DEV family which has it’s own plugin WPMU DEV Dashboard for taking care of plugin updates. Luckily you can define WPMUDEV_APIKEY within wp-config.php which will take care of adding license info. Just need to install WP Smush Pro and WPMU DEV Dashboard.

wp config set WPMUDEV_APIKEY my_secret_license_key_here
wp plugin install https://sitename.net/wp-content/plugins/wp-smush-pro.zip https://sitename.net/wp-content/plugins/wpmudev-updates.zip --force --activate

5. WP101

WP101 is by far the easiest to deploy. Even though the plugin requires a paid subscription for the API key, it’s a free plugin and available through the WordPress.org directory. The license can be added by define WP101_API_KEY within wp-config.php.

wp config set WP101_API_KEY my_secret_license_key_here
wp plugin install wp101 --force --activate

Bundling these into my maintenance panel.

The point of all of this is make installing paid plugins as easy a click of a button. Anchor Hosting customer can now handle running these deployments with a click of a button from the maintenance panel.

Deploying paid plugins
Video Thumbnail
CaptainCore deploy custom script
Paid plugins often rely on license keys for automatic updates and support requests. However it's the wild west when it comes to how their licensing systems work. Seems like every plugin author ends up implementing their own licensing system. I discovered this as I was recently creating bash scripts