Updated on 19 February, 2025
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 theme’s functions.php file or to your site plugin, in case you have one, 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__MELAPRESS_LOGIN_SECURITY_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 / site plugin
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 root of your theme folder, or if you have a site plugin, the file will be in the plugins directory in the /wp-content/plugins/ folder. 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__MELAPRESS_LOGIN_SECURITY_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 = 'melapress_login_security_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.