How can we help?

Search for answers or browse our knowledge base.

Table of Contents

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.

The survey results are in: Find out what your WordPress security gameplan might be missing

Uploading Melapress Login Security as a zip file in WordPress
Melapress Login Security in the WordPress plugin repository
Close

Installing Melapress Login Security Free

Congratulations on taking control of your WordPress website's security by implementing robust login and password policies with Melapress Login Security. You can change your login page URL, limit failed login attempts, and reset passwords.

 

Below are two ways to install Melapress Login Security on your website:

Go to your plugin dashboard on your site, then go to "Add New" and then search for Melapress Login Security.

Download the Melapress Login Security plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading CAPTCHA 4WP as a zip file in WordPress
CAPTCHA 4WP in the WordPress plugin repository
Close

Installing CAPTCHA 4WP Free

Well done you. You're one step closer to safeguarding your WordPress website from spam and automated attacks with CAPTCHA 4WP. You'll be able to effortlessly integrate CAPTCHA into your forms and enjoy a website with enhanced security.

 

Below are two ways to install CAPTCHA 4WP on your website:

Go to your plugin dashboard on your site, then go to "Add New", and then search for CAPTCHA 4WP.

Download the CAPTCHA 4WP plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading WP Activity Log as a zip file in WordPress
WP Activity Log in the WordPress plugin repository
Close

Installing WP Activity Log Free on your website

You deserve a pat on the back for choosing to record user actions and changes on your website. That is the first step towards better user accountability, easier troubleshooting of website security, and many other benefits of issues.

 

Below are the two ways to install WP Activity Log on your website:

Go to your plugin dashboard on your site, then go to "Add New" and then search for WP Activity Log.

Download the WP Activity Log plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading WP 2FA as a zip file in WordPress
WP 2FA in the WordPress plugin repository
Close

Installing WP 2FA Free

Congratulations on taking the first step towards enhancing your WordPress site's security with WP 2FA Free! You're now on your way to protecting your valuable data and ensuring peace of mind. No coding or technical knowledge is required.

 

Below are two ways to install WP 2FA on your website:

Go to your plugin dashboard on your site, then go to "Add New", and then search for WP 2FA.

Download the WP 2FA plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2