2017 © Pedro PelĂĄez
 

library wordpress-sdk

Freemius WordPress SDK

image

freemius/wordpress-sdk

Freemius WordPress SDK

  • Tuesday, July 17, 2018
  • by freemius
  • Repository
  • 20 Watchers
  • 62 Stars
  • 1,679 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 37 Forks
  • 40 Open issues
  • 53 Versions
  • 1 % Grown

The README.md

Freemius WordPress SDK

Welcome to the official repository for the Freemius SDK! Adding the SDK to your WordPress plugin, theme, or add-ons, enables all the benefits that come with using the Freemius platform such as:, (*1)

Freemius truly empowers developers to create prosperous subscription-based businesses., (*4)

If you're new to Freemius then we recommend taking a look at our Getting Started guide first., (*5)

If you're a WordPress plugin or theme developer and are interested in monetizing with Freemius then you can sign-up for a FREE account:, (*6)

https://dashboard.freemius.com/register/, (*7)

Once you have your account setup and are familiar with how it all works you're ready to begin integrating Freemius into your WordPress product, (*8)

You can see some of the existing WordPress.org plugins & themes that are already utilizing the power of Freemius here:, (*9)

  • https://profiles.wordpress.org/freemius/#content-plugins
  • https://includewp.com/freemius/#focus

Code Documentation

You can find the SDK's documentation here: https://freemius.com/help/documentation/wordpress-sdk/, (*10)

Integrating & Initializing the SDK

As part of the integration process, you'll need to add the latest version of the Freemius SDK into your WordPress project., (*11)

Then, when you've completed the SDK integration form a snippet of code is generated which you'll need to copy and paste into the top of your main plugin's PHP file, right after the plugin's header comment., (*12)

Note: For themes, this will be in the root functions.php file instead., (*13)

A typical SDK snippet will look similar to the following (your particular snippet may differ slightly depending on your integration):, (*14)

if ( ! function_exists( 'my_prefix_fs' ) ) {
    // Create a helper function for easy SDK access.
    function my_prefix_fs() {
        global $my_prefix_fs;

        if ( ! isset( $my_prefix_fs ) ) {
            // Include Freemius SDK.
            require_once dirname(__FILE__) . '/freemius/start.php';

            $my_prefix_fs = fs_dynamic_init( array(
                'id'                  => '1234',
                'slug'                => 'my-new-plugin',
                'premium_slug'        => 'my-new-plugin-premium',
                'type'                => 'plugin',
                'public_key'          => 'pk_bAEfta69seKymZzmf2xtqq8QXHz9y',
                'is_premium'          => true,
                // If your plugin is a serviceware, set this option to false.
                'has_premium_version' => true,
                'has_paid_plans'      => true,
                'is_org_compliant'    => true,
                'menu'                => array(
                    'slug'           => 'my-new-plugin',
                    'parent'         => array(
                        'slug' => 'options-general.php',
                    ),
                ),
                // Set the SDK to work in a sandbox mode (for development & testing).
                // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
                'secret_key'          => 'sk_ubb4yN3mzqGR2x8#P7r5&@*xC$utE',
            ) );
        }

        return $my_prefix_fs;
    }

    // Init Freemius.
    my_prefix_fs();
    // Signal that SDK was initiated.
    do_action( 'my_prefix_fs_loaded' );
}

Usage example

You can call any SDK methods by prefixing them with the shortcode function for your particular plugin/theme (specified when completing the SDK integration form in the Developer Dashboard):, (*15)

<?php my_prefix_fs()->get_upgrade_url(); ?>

Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:, (*16)

<?php
    global $my_prefix_fs;
    $my_prefix_fs->get_account_url();
?>

There are many other SDK methods available that you can use to enhance the functionality of your WordPress product. Some of the more common use-cases are covered in the Freemius SDK Gists documentation., (*17)

Adding license-based logic examples

Add marketing content that encourages your users to upgrade to a paid version:, (*18)

<?php
    if ( my_prefix_fs()->is_not_paying() ) {
        echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
        echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
            esc_html__('Upgrade Now!', 'my-plugin-slug') .
            '</a>';
        echo '</section>';
    }
?>

Add logic which will only be available in your premium plugin version:, (*19)

<?php
    // This "if" block will be auto removed from the Free version.
    if ( my_prefix_fs()->is__premium_only() ) {

        // ... premium only logic ...

    }
?>

To add a function which will only be available in your premium plugin version, add __premium_only as the suffix of the function name. Ensure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:, (*20)

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() {
            ...
        }
    }
?>

Add logic which will only be executed for customers in your 'professional' plan:, (*21)

<?php
    if ( my_prefix_fs()->is_plan('professional', true) ) {
        // .. logic related to Professional plan only ...
    }
?>

Add logic which will only be executed for customers in your 'professional' plan or higher plans:, (*22)

<?php
    if ( my_prefix_fs()->is_plan('professional') ) {
        // ... logic related to Professional plan and higher plans ...
    }
?>

Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):, (*23)

<?php
    // This "if" block will be auto removed from the Free version.
    if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
        // ... logic related to Professional plan and higher plans ...
    }
?>

Add logic only for users in trial:, (*24)

<?php
    if ( my_prefix_fs()->is_trial() ) {
        // ... logic for users in trial ...
    }
?>

Add logic for specified paid plan:, (*25)

is__premium_only() ) {
        if ( my_prefix_fs()->is_plan( 'professional', true ) ) {

            // ... logic related to Professional plan only ...

        } else if ( my_prefix_fs()->is_plan( 'business' ) ) {

            // ... logic related to Business plan and higher plans ...

        }
    }
?>

Excluding files and folders from the free plugin version

There are two ways to exclude files from your free version., (*26)

  1. Add __premium_only just before the file extension. For example, functions__premium_only.php will be included only in the premium plugin version. This works for all types of files, not only PHP.
  2. Add @fs_premium_only a special meta tag to the plugin's main PHP file header. Example:

In the example plugin header above, the file /lib/functions.php and the directory /premium-files/ will be removed from the free plugin version., (*27)

Hooks: Actions and Filters

Similar to WordPress’ filters and actions hooks, the Freemius WordPress SDK provides a collection of filters and actions that enable you to customize and extend its functionality in your WordPress plugins or themes., (*28)

WordPress.org Compliance

Based on WordPress.org Guidelines you are not allowed to submit a plugin that has premium code in it:, (*29)

All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers., (*30)

Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with if ( my_prefix_fs()->{{ method }}__premium_only() ) or use some of the other methods provided by the SDK to exclude premium features & files from the free version., (*31)

Deployment

Zip your Freemius product’s root folder and upload it in the Deployment section in the Freemius Developer's Dashboard. The plugin/theme will automatically be scanned and processed by a custom-developed PHP Processor which will auto-generate two versions of your plugin:, (*32)

  1. Premium version: Identical to your uploaded version, including all code (except your secret_key). Will be enabled for download ONLY for your paying or in trial customers.
  2. Free version: The code stripped from all your paid features (based on the logic added wrapped in { method }__premium_only()).

The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org compliant and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo., (*33)

License

Copyright (c) FreemiusÂź, Inc., (*34)

Licensed under the GNU general public license (version 3)., (*35)

Contributing

Please see our contributing guide., (*36)

The Versions

17/07 2018

dev-develop

dev-develop https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0 GPL-2.0+ GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

15/07 2018

dev-feature/ms-network-premium-update-fix

dev-feature/ms-network-premium-update-fix https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

15/07 2018

dev-master

9999999-dev https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0 GPL-2.0+ GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

15/07 2018

2.1.2

2.1.2.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

01/06 2018

2.1.1

2.1.1.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

25/05 2018

2.1.0

2.1.0.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

15/05 2018

dev-feature/opt-in-eu

dev-feature/opt-in-eu https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

08/05 2018

dev-feature/latest-premium-version-dialog-box

dev-feature/latest-premium-version-dialog-box https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

25/03 2018

2.0.1

2.0.1.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

02/03 2018

dev-feature/multi-site

dev-feature/multi-site https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0 GPL-3.0-only

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

05/02 2018

dev-feature/version-update-fix

dev-feature/version-update-fix https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

17/01 2018

1.2.4

1.2.4.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

19/12 2017

1.2.3

1.2.3.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-3.0

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

01/11 2017

dev-feature/store-install-ip

dev-feature/store-install-ip https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

30/10 2017

dev-feature/user-recovery

dev-feature/user-recovery https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

04/10 2017

dev-feature/affiliation-submenu-v2

dev-feature/affiliation-submenu-v2 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

03/10 2017

dev-feature/affiliation-submenu

dev-feature/affiliation-submenu https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

28/09 2017

dev-feature/license-activation-fixes

dev-feature/license-activation-fixes https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

10/09 2017

dev-feature/account-billing-invoice-bug-fix

dev-feature/account-billing-invoice-bug-fix https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

31/08 2017

1.2.2.9

1.2.2.9 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

30/08 2017

1.2.2.8

1.2.2.8 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

24/08 2017

dev-feature/big-merge-fixes

dev-feature/big-merge-fixes https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

19/08 2017

dev-feature/fs-theme-mode-v7

dev-feature/fs-theme-mode-v7 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

06/06 2017

dev-feature/fs-theme-mode-v6

dev-feature/fs-theme-mode-v6 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

12/04 2017

dev-feature/fs-theme-mode-v5

dev-feature/fs-theme-mode-v5 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

13/03 2017

dev-feature/fs-theme-mode-v4

dev-feature/fs-theme-mode-v4 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

10/03 2017

1.2.1.6

1.2.1.6 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

22/02 2017

dev-feature/fs-theme-mode-v3

dev-feature/fs-theme-mode-v3 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

22/02 2017

dev-feature/fs-theme-mode-v2

dev-feature/fs-theme-mode-v2 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

13/02 2017

dev-feature/secure-redirects-process-for-license-activation

dev-feature/secure-redirects-process-for-license-activation https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

13/12 2016

1.2.1.5

1.2.1.5 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

22/09 2016

1.2.1

1.2.1.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

24/08 2016

dev-feature/ngg

dev-feature/ngg https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

17/08 2016

1.2.0

1.2.0.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

01/08 2016

dev-feature/fs-theme-mode

dev-feature/fs-theme-mode https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

18/06 2016

dev-feature/license-key-activation

dev-feature/license-key-activation https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

11/06 2016

1.1.9

1.1.9.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

04/05 2016

1.1.8.1

1.1.8.1 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

19/04 2016

1.1.8

1.1.8.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

05/04 2016

1.1.7.5

1.1.7.5 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

28/03 2016

1.1.7.4

1.1.7.4 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

28/03 2016

1.7.4

1.7.4.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

28/03 2016

dev-feature/ninja-forms

dev-feature/ninja-forms https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

01/03 2016

1.1.7.3

1.1.7.3 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

01/03 2016

1.7.3

1.7.3.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

01/02 2016

dev-pr/24

dev-pr/24 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

25/01 2016

1.1.6.5

1.1.6.5 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

15/01 2016

1.1.6

1.1.6.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

12/01 2016

1.1.5

1.1.5.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

11/12 2015

1.1.4

1.1.4.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

09/12 2015

1.1.3

1.1.3.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

30/10 2015

1.1.2

1.1.2.0 https://freemius.com

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius

14/10 2015

1.1.1

1.1.1.0 https://github.com/freemius/wordpress-sdk

Freemius WordPress SDK

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.2

 

plugin wordpress sdk freemius