Search for answers or browse our knowledge base.
How to activate Melapress plugin licenses programmatically
If you’re installing Melapress premium plugins on multiple websites, you may want to activate site licenses programmatically. Using this method you’ll avoid having to enter license keys one-by-one on every site you want to activate plugins on.
The process is the same for all plugins. Of course, we’ll need to change variable and constant names depending on the plugins we want to automate license activation for. All required information is provided in the step-by-step instructions as follows:
Step 1: Install the plugin/s on the desired websites.
First, install the Melapress premium plugins you want to activate on the desired websites. You can do so manually or by uploading the plugin .ZIP file to the /wp-content/plugins folder using S/FTP.
Step 2: Add your license key to the wp-config.php file
Next, we need to add the plugin license to the wp-config.php file. Each plugin has its own constant name, which you can find below. In the following step, we’ll add a php function to the functions.php file, which checks for the license key we add in this step.
You’ll be able to easily find the wp-config.php file in the root directory of your WordPress website. It is important to add this before the require_once ABSPATH.’wp-settings.php’; line.
WP Activity Log:
define (‘WP__WSAL_FREEMIUS_LICENSE_KEY’,’<YOUR_LICENSE_KEY>’);
CAPTCHA 4WP:
define (‘WP__C4WP_FS__LICENSE_KEY’,’<YOUR_LICENSE_KEY>’);
Melapress Login Security:
define (‘WP__PPM_FREEMIUS__LICENSE_KEY’,’<YOUR_LICENSE_KEY>’);
WP 2FA:
define (‘WP__WP2FA_FREEMIUS__LICENSE_KEY’,’<YOUR_LICENSE_KEY>’);
Where <YOUR_LICENSE_KEY> is your plugin license key.
How to find your license key
License keys are sent via email upon plugin purchase. Alternatively, you can log in to your My Account where you will find all of your license keys along with the premium plugin download links. Use the email address used during purchase to log in. If you cannot remember your password, kindly use the Forgot your password? option to reset it.
Step 3: Update the functions.php file
Now that we have updated the wp-config.php file, it is time to update the functions.php file. You will find this file in the wp-includes folder, which resides in the WordPress root directory. Add the below text at the very end of the functions.php file.
WP Activity Log
if ( ! class_exists( 'Freemius_License_Auto_Activator' ) ) {
class Freemius_License_Auto_Activator {
private $_shortcode;
function __construct( $shortcode ) {
$this->_shortcode = $shortcode;
}
function license_key_auto_activation() {
if ( ! function_exists( $this->_shortcode ) ) {
return;
}
$fs = ($this->_shortcode)();
if ( $fs->is_registered() ) {
// No connectivity OR the user already opted-in to Freemius.
return;
}
$option_key = "{$this->_shortcode}_auto_license_activation";
if ( 'pending' != get_option( $option_key, 'pending' ) ) {
return;
}
try {
$next_page =$fs->activate_migrated_license( WP__WSAL_FREEMIUS__LICENSE_KEY );
} catch (Exception $e) {
update_option( $option_key, 'unexpected_error' );
return;
}
if ( $fs->can_use_premium_code() ) {
update_option( $option_key, 'done' );
if ( is_string( $next_page ) ) {
fs_redirect( $next_page );
}
} else {
update_option( $option_key, 'failed' );
}
}
}
}
// Replace shortcode with product's shortcode.
$fs_shortcode = 'wsal_freemius';
if ( defined( 'WP__' . strtoupper( $fs_shortcode ) . '__LICENSE_KEY' ) ) {
$fs_license_activator = new Freemius_License_Auto_Activator( $fs_shortcode );
add_action( 'admin_init', array( $fs_license_activator, 'license_key_auto_activation' ) );
}
CAPTCHA 4WP
if ( ! class_exists( 'Freemius_License_Auto_Activator' ) ) {
class Freemius_License_Auto_Activator {
private $_shortcode;
function __construct( $shortcode ) {
$this->_shortcode = $shortcode;
}
function license_key_auto_activation() {
if ( ! function_exists( $this->_shortcode ) ) {
return;
}
$fs = ($this->_shortcode)();
if ( $fs->is_registered() ) {
// No connectivity OR the user already opted-in to Freemius.
return;
}
$option_key = "{$this->_shortcode}_auto_license_activation";
if ( 'pending' != get_option( $option_key, 'pending' ) ) {
return;
}
try {
$next_page =$fs->activate_migrated_license( WP__C4WP_FS__LICENSE_KEY );
} catch (Exception $e) {
update_option( $option_key, 'unexpected_error' );
return;
}
if ( $fs->can_use_premium_code() ) {
update_option( $option_key, 'done' );
if ( is_string( $next_page ) ) {
fs_redirect( $next_page );
}
} else {
update_option( $option_key, 'failed' );
}
}
}
}
// Replace shortcode with product's shortcode.
$fs_shortcode = '’c4wp_fs';
if ( defined( 'WP__' . strtoupper( $fs_shortcode ) . '__LICENSE_KEY' ) ) {
$fs_license_activator = new Freemius_License_Auto_Activator( $fs_shortcode );
add_action( 'admin_init', array( $fs_license_activator, 'license_key_auto_activation' ) );
}
Melapress Login Security
if ( ! class_exists( 'Freemius_License_Auto_Activator' ) ) {
class Freemius_License_Auto_Activator {
private $_shortcode;
function __construct( $shortcode ) {
$this->_shortcode = $shortcode;
}
function license_key_auto_activation() {
if ( ! function_exists( $this->_shortcode ) ) {
return;
}
$fs = ($this->_shortcode)();
if ( $fs->is_registered() ) {
// No connectivity OR the user already opted-in to Freemius.
return;
}
$option_key = "{$this->_shortcode}_auto_license_activation";
if ( 'pending' != get_option( $option_key, 'pending' ) ) {
return;
}
try {
$next_page =$fs->activate_migrated_license( WP__PPM_FREEMIUS__LICENSE_KEY );
} catch (Exception $e) {
update_option( $option_key, 'unexpected_error' );
return;
}
if ( $fs->can_use_premium_code() ) {
update_option( $option_key, 'done' );
if ( is_string( $next_page ) ) {
fs_redirect( $next_page );
}
} else {
update_option( $option_key, 'failed' );
}
}
}
}
// Replace shortcode with product's shortcode.
$fs_shortcode = 'ppm_freemius';
if ( defined( 'WP__' . strtoupper( $fs_shortcode ) . '__LICENSE_KEY' ) ) {
$fs_license_activator = new Freemius_License_Auto_Activator( $fs_shortcode );
add_action( 'admin_init', array( $fs_license_activator, 'license_key_auto_activation' ) );
}
WP 2FA
if ( ! class_exists( 'Freemius_License_Auto_Activator' ) ) {
class Freemius_License_Auto_Activator {
private $_shortcode;
function __construct( $shortcode ) {
$this->_shortcode = $shortcode;
}
function license_key_auto_activation() {
if ( ! function_exists( $this->_shortcode ) ) {
return;
}
$fs = ($this->_shortcode)();
if ( $fs->is_registered() ) {
// No connectivity OR the user already opted-in to Freemius.
return;
}
$option_key = "{$this->_shortcode}_auto_license_activation";
if ( 'pending' != get_option( $option_key, 'pending' ) ) {
return;
}
try {
$next_page =$fs->activate_migrated_license( WP__WP2FA_FREEMIUS__LICENSE_KEY );
} catch (Exception $e) {
update_option( $option_key, 'unexpected_error' );
return;
}
if ( $fs->can_use_premium_code() ) {
update_option( $option_key, 'done' );
if ( is_string( $next_page ) ) {
fs_redirect( $next_page );
}
} else {
update_option( $option_key, 'failed' );
}
}
}
}
// Replace shortcode with product's shortcode.
$fs_shortcode = 'wp2fa_freemius';
if ( defined( 'WP__' . strtoupper( $fs_shortcode ) . '__LICENSE_KEY' ) ) {
$fs_license_activator = new Freemius_License_Auto_Activator( $fs_shortcode );
add_action( 'admin_init', array( $fs_license_activator, 'license_key_auto_activation' ) );
}
Quick note about Freemius
Freemius is Melapress’ licensing partner and handles all of our plugin licensing processes. This is why you’ll see their name in variable and constant names.
Step 4: Enable the plugin
All that’s left to do now is to enable the plugin. The license will then be activated automatically.
Getting more help
If you need more information or assistance setting up license key activation, get in touch with us by opening a support ticket.