1. Home
  2. Documentation
  3. Selling with Freemius
  4. Version Deployment

Version Deployment

There are two main reasons why Freemius has its own repository and deployment process:

  1. Being able to securely serve premium plugin or theme downloads and updates to customers who own a valid license

  2. Simplifying code management and maintenance by allowing developers to manage only one code base that contains all of their plugin/theme functionality, and to automatically generate a free, WordPress.org compliant version, using a custom PHP Preprocessor

Deploying to Freemius

  1. Login to your Freemius Dashboard and go over to the Deployment section.

  2. Zip your plugin’s or theme’s root folder and upload it by clicking the [ + Add New Version] button, located at the top.

Here’s what is going to happen:

  1. If you forgot to clear your secret_key and sandbox related code, our PHP Processor will automatically remove it for you.

  2. The same processor will auto-generate two versions of your plugin:

  • A premium version: Identical to your uploaded version, including all of the code (excluding the secret_key). Will be enabled for download ONLY for customers with a valid license (paying or trial).

  • A free version: The same code, stripped from all of your paid features (based on the logic added with { method }__premium_only()). This stripped version is what your users will be able to download first.
    Oh, and in case your original plugin is compatible with the official WordPress.org guidelines – the new free version will also be compatible as all premium code was stripped.

Note: The premium version will not be available to download or update for your customers untill you turn the Is Release switch on.

Free Version Auto Generation / Premium Logic Stripping / PHP Preprocessor

The deployment PHP Preprocessor will automatically strip out any premium code – based on the following rules:

Stripping Premium Only PHP Logic

All logic within if statements containing a usage of license related methods with the __premium_only suffix will automatically be stripped from the free version.

// This IF block will be auto removed from the Free version.
if ( my_fs()->is__premium_only() ) {
    // This IF will be executed only if the user in a trial mode or have a valid license.
    if ( my_fs()->can_use_premium_code() ) {
        // ... premium only logic ...
    }
}

// This "if" block will be auto removed from the Free version.
if ( my_fs()->is_plan__premium_only('starter') ) {
    // ... logic related to starter plan and higher plans ...
}

Stripping Premium Only CSS & JavaScript Logic

Simply wrap the code you’d like to exclude with the following meta comments:

(function($){
    /* <fs_premium_only> */

    // ... my premium only code ...

    /* </fs_premium_only> */
})(jQuery);

In the future, we’ll provide a richer JavaScript SDK that will handle license related logic similarly to how our PHP SDK does.

Stripping Premium Only PHP Functions

To add a function which will only be available in your premium plugin version, simply add the __premium_only suffix to the function’s name. Make sure that all lines that call that method either directly, or by using hooks, are also wrapped in the premium only logic:

class My_Plugin {
    function init() {
        ...

        // This "if" block will be auto removed from the free version.
        if ( my_fs()->is__premium_only() ) {
            // Init premium version.
            $this->admin_init__premium_only();

            add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
        }

        ...
    }

    // This method will be only included in the premium version.
    function admin_init__premium_only() {
        ...
    }

    // This method will be only included in the premium version.
    function admin_init_hook__premium_only() {
        ...
    }
}

Stripping Premium Only Files / Folders

There are two ways to exclude files from your free version:

  1. Add __premium_only just before the file extension. For example: functions__premium_only.php will be only included in the premium plugin/theme version. This works for all type of files, not only PHP.

  2. For plugins, add @fs_premium_only, a special meta tag, to the plugin’s main PHP file header. Example:

/**
 * Plugin Name: My Very Awesome Plugin
 * Plugin URI:  http://my-awesome-plugin.com
 * Description: Create and manage Awesomeness right in WordPress.
 * Version:     1.0.0
 * Author:      Awesomattic
 * Author URI:  http://my-awesome-plugin.com/me/
 * License:     GPLv2
 * Text Domain: myplugin
 * Domain Path: /langs
 *
 * @fs_premium_only /lib/functions.php, /premium-files/
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// ... my code ...

The file /lib/functions.php and the directory /premium-files/ will be removed from the free plugin version.

  1. For themes, add @fs_premium_only, a special meta tag, to the themes’s main style.css file header. Example:
/**
 * Theme Name: My Very Awesome Theme
 * Theme URI:  http://my-awesome-theme.com
 * Description: Create and manage Awesomeness right in WordPress.
 * Version:     1.0.0
 * Author:      Awesomattic
 * Author URI:  http://my-awesome-theme.com/me/
 * License:     GPLv2
 * Text Domain: mytheme
 *
 * @fs_premium_only /premium-functions.php, /premium-files/
 */

body { ... }
span { ... }