1. Home
  2. Documentation
  3. Getting Started with Freemius
  4. Integration with SDK

Integration with SDK

Add the latest WordPress SDK into your Product

The Freemius WordPress SDK contains an impressive set of features to help you sell your plugins and themes, and it’s regularly updated with new features and improvements.

To get notified about new SDK releases it is recommended to Watch the GitHub repository. You can also Star the repository to bookmark it on your GitHub account.

Freemius WordPress SDK -Watch and star GitHub repo

As soon as you’ve added your plugin or theme, you’ll automatically be taken to the SDK INTEGRATION page.

Freemius Dashboard - SDK Integration

This part of the integration process involves adding Freemius specific code to your plugin or theme. This is split into three parts:

  • Add the core Freemius WordPress SDK.
  • Add an auto-generated snippet of code to your product’s main PHP file.
  • Wrap premium only code with the proper logic.

In this section, we’ll focus on adding the core Freemius WordPress SDK. The other two steps are covered in the following sections.

Download the latest version of the WordPress SDK and extract the zip file.

Rename the wordpress-sdk-master extracted folder to freemius and copy the entire folder as-is to the root folder of your WordPress plugin or theme.

3. Fill out the SDK Integration Form

With the WordPress SDK in place in your plugin or theme, fill out all the form fields in the Init SDK section. It’s pretty straightforward as each field is self-explanatory, but if you have questions, please email us or ask for details in the #integration channel in our DEV Slack.

Freemius Dashboard - plugin SDK Integration

Note: This is the SDK integration page for a plugin. The theme SDK integration page is very similar, as you can see in the screenshot below.

Freemius Dashboard - theme SDK Integration

Once you have filled out all form fields, a product-specific snippet of code will be auto-generated, which can then be added to your plugin or theme.

Don’t copy the code just yet, as when you create your pricing plans (in the next section) this will update the auto-generated SDK snippet. So, to save you from having to copy the SDK integration snippet twice, hold off until you’ve created your pricing plans. We’ll come back to this later.

Note: You might have noticed that there is no save button on the SDK integration page. This is actually deliberate because changes are auto-saved when any field is edited, which regenerates the SDK code snippet on demand.

5. Insert the Auto-Generated SDK Integration Snippet

Once you’ve filled out the fields on the SDK integration page and you’ve created your pricing plans, the next step is to add the auto-generated SDK integration snippet to the main plugin or theme file.

Note: For themes, this will be in the root functions.php file.

Freemius Dashboard - SDK integration code snippet

6. Designate Your Premium Only Code

The last step in the integration process is to designate sections of your code that are premium only so that Freemius knows what features are associated with each plan.

The benefit of this is that you can manage a single codebase and use the deployment feature to effectively “strip” premium-only features out of your Free version for easy deployment on WordPress.org. This way, you don’t have to manage two versions of your product separately.

There are various methods available to specify your premium code. For PHP, JavaScript and CSS code you can wrap specific sections of code with the corresponding premium logic.

This is usually in the form of conditional statements for PHP code and special meta comments for JavaScript and CSS. You can also choose to exclude entire files and folders from specific plans. This gives you a lot of flexibility in how to define premium-only features in your plugin or theme.

In addition, you can selectively ignore individual files and entire folders that should be included in all plans. This is ideal if your WordPress product contains vendor-specific code (e.g. 3rd party libraries) that should always be included in all your plans.

You can view the full range of functionality for designating premium-only sections of code with Freemius logic here.

Once completed, this step forms the full, premium version of your plugin or theme. This deployment logic is a powerful tool that results in a very efficient workflow, allowing you to maintain a single codebase.

This tool is core to the Freemius concept, enabling a natural workflow of development and release cycles for both free and premium versions of your product.

If you already developed free and premium versions that are fundamentally different, you can either merge the versions into a single code base or ignore the free version generated by Freemius. If you go with the 2nd option, make sure also to integrate the SDK into your free version and set the is_premium flag to false to indicate the SDK that it is running in the scope of the free version.