Skip to content

Commit

Permalink
Merge pull request #438 from Freemius/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vovafeldman authored Jul 28, 2020
2 parents 1e317f3 + f507a25 commit 1c7e0bc
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 58 deletions.
115 changes: 72 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,99 @@
Freemius WordPress SDK
======================

[Monetization](https://freemius.com/wordpress/), [analytics](https://freemius.com/wordpress/insights/), and marketing automation platform for plugin & theme developers. Freemius empower developers to create prosperous subscription based businesses.
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](https://freemius.com) such as:

You can see some of the WordPress.org plugins & themes that are utilizing the power of Freemius here:
* [Software Licensing](https://freemius.com/wordpress/software-licensing/)
* [Secure Checkout](https://freemius.com/wordpress/checkout/)
* [Subscriptions](https://freemius.com/wordpress/recurring-payments-subscriptions/)
* [Automatic Updates](https://freemius.com/wordpress/automatic-software-updates/)
* [Seamless EU VAT](https://freemius.com/wordpress/collecting-eu-vat-europe/)
* [Cart Abandonment Recovery](https://freemius.com/wordpress/cart-abandonment-recovery/)
* [Affiliate Platform](https://freemius.com/wordpress/affiliate-platform/)
* [Analytics & Usage Tracking](https://freemius.com/wordpress/insights/)
* [User Dashboard](https://freemius.com/wordpress/user-dashboard/)

https://includewp.com/freemius/#focus
* [Monetization](https://freemius.com/wordpress/)
* [Analytics](https://freemius.com/wordpress/insights/)
* [More...](https://freemius.com/wordpress/features-comparison/)

If you are a WordPress plugin or theme developer and you are interested to monetize with Freemius you can [sign-up here for free](https://dashboard.freemius.com/register/):
Freemius truly empowers developers to create prosperous subscription-based businesses.

If you're new to Freemius then we recommend taking a look at our [Getting Started](https://freemius.com/help/documentation/getting-started/) guide first.

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](https://dashboard.freemius.com/register/):

https://dashboard.freemius.com/register/

**Below you'll find the integration instructions for our WordPress SDK.**
Once you have your account setup and are familiar with how it all works you're ready to begin [integrating Freemius](https://freemius.com/help/documentation/wordpress-sdk/integrating-freemius-sdk/) into your WordPress product

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

* 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/

## Initializing the SDK
## Integrating & Initializing the SDK

As part of the integration process, you'll need to [add the latest version](https://freemius.com/help/documentation/getting-started/#add_the_latest_wordpress_sdk_into_your_product) of the Freemius SDK into your WordPress project.

Then, when you've completed the [SDK integration form](https://freemius.com/help/documentation/getting-started/#fill_out_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.

Copy the code below and paste it into the top of your main plugin's PHP file, right after the plugin's header comment:
Note: For themes, this will be in the root `functions.php` file instead.

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

```php
<?php
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-plugin-slug',
'menu_slug' => 'my_menu_slug', // You can also use __FILE__
'public_key' => 'pk_MY_PUBLIC_KEY',
'is_live' => true,
'is_premium' => true,
'has_addons' => false,
'has_paid_plans' => false,
'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_MY_SECRET_KEY',
'secret_key' => 'sk_ubb4yN3mzqGR2x8#P7r5&@*xC$utE',
) );
}

return $my_prefix_fs;
}

// Init Freemius.
my_prefix_fs();
?>
```

- **1234** - Replace with your plugin's ID.
- **pk_MY_PUBLIC_KEY** - Replace with your plugin's public key.
- **sk_MY_SECRET_KEY** - Replace with your plugin's secret key.
- **my-plugin-slug** - Replace with your plugin's WordPress.org slug.
- **my_menu_slug** - Replace with your admin dashboard settings menu slug.
// Signal that SDK was initiated.
do_action( 'my_prefix_fs_loaded' );
}

```

## Usage example

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

```php
<?php my_prefix_fs()->get_upgrade_url(); ?>
Expand All @@ -78,6 +108,8 @@ Or when calling Freemius multiple times in a scope, it's recommended to use it w
?>
```

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](https://freemius.com/help/documentation/wordpress-sdk/gists/) documentation.

## Adding license based logic examples

Add marketing content to encourage your users to upgrade for your paid version:
Expand Down Expand Up @@ -200,10 +232,10 @@ Add logic for specified paid plan:
```

## Excluding files and folders from the free plugin version
There are two ways to exclude files from your free version.
There are [two ways](https://freemius.com/help/documentation/wordpress-sdk/software-licensing/#excluding_files_and_folders_from_the_free_plugin_version) 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 version. This works for all type of files, not only PHP.
2. Add `@fs_premium_only` a sepcial meta tag to the plugin's main PHP file header. Example:
1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included 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:
```php
<?php
/**
Expand All @@ -227,27 +259,24 @@ There are two ways to exclude files from your free version.
// ... my code ...
?>
```
The file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
In the example plugin header above, the file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.

# WordPress.org Compliance
Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
> 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.
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 the other methods provided to exclude premium features & files from the free version.
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](https://freemius.com/help/documentation/wordpress-sdk/software-licensing/) provided by the SDK to exclude premium features & files from the free version.

## Deployment
Zip your plugin's root folder and upload it in the Deployment section in the *Freemius Developer's Dashboard*.
The plugin will be scanned and processed by a custom developed *PHP Processor* which will auto-generate two versions of your plugin:
Zip your Freemius product’s root folder and [upload it in the Deployment section](https://freemius.com/help/documentation/selling-with-freemius/deployment/) 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:

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 complaint 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.

## Reporting Bugs
Email dev [at] freemius [dot] com
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.

## FAQ
## License
Copyright (c) Freemius®, Inc.

## Copyright
Freemius, Inc.
Licensed under the GNU general public license (version 3).
23 changes: 15 additions & 8 deletions includes/class-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -5481,7 +5481,10 @@ private function reconnect_locally( $is_context_single_site = false ) {
* @return bool
*/
function is_extensions_tracking_allowed() {
return (true === $this->_storage->get( 'is_extensions_tracking_allowed', true ) );
return ( true === $this->apply_filters(
'is_extensions_tracking_allowed',
$this->_storage->get( 'is_extensions_tracking_allowed', true )
) );
}

/**
Expand Down Expand Up @@ -23324,14 +23327,18 @@ function _add_tracking_links() {
return;
}

if ( $this->is_registered() && $this->is_tracking_allowed() ) {
if ( ! $this->is_enable_anonymous() ) {
// If opted in and tracking is allowed, don't allow to opt out if anonymous mode is disabled.
return;
}
if (
$this->is_activation_mode() &&
$this->is_premium() &&
! $this->is_registered()
) {
// If not yet registered and running the premium code base, a license activation link will already be shown.
return;
}

if ( ! $this->is_free_plan() ) {
// Don't allow to opt out if running in paid plan.
if ( $this->is_registered() && $this->is_tracking_allowed() ) {
if ( ! $this->is_premium() && ! $this->is_enable_anonymous() ) {
// If opted in and tracking is allowed, don't allow to opt out if not premium and anonymous mode is disabled.
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion start.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @var string
*/
$this_sdk_version = '2.4.0';
$this_sdk_version = '2.4.0.1';

#region SDK Selection Logic --------------------------------------------------------------------

Expand Down
13 changes: 7 additions & 6 deletions templates/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,12 @@ class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'S
}

$permissions['extensions'] = array(
'icon-class' => 'dashicons dashicons-menu',
'label' => $fs->get_text_inline( 'Plugins & Themes', 'permissions-extensions' ),
'desc' => $fs->get_text_inline( 'Title, slug, version, and is active', 'permissions-extensions_desc' ),
'priority' => 25,
'optional' => true,
'icon-class' => 'dashicons dashicons-menu',
'label' => $fs->get_text_inline( 'Plugins & Themes', 'permissions-extensions' ),
'desc' => $fs->get_text_inline( 'Title, slug, version, and is active', 'permissions-extensions_desc' ),
'priority' => 25,
'optional' => true,
'default' => $fs->apply_filters( 'permission_extensions_default', true )
);

// Allow filtering of the permissions list.
Expand All @@ -429,7 +430,7 @@ class="button button-secondary" tabindex="2"><?php fs_esc_html_echo_x_inline( 'S
class="fs-permission fs-<?php echo esc_attr( $id ); ?>">
<i class="<?php echo esc_attr( $permission['icon-class'] ); ?>"></i>
<?php if ( isset( $permission['optional'] ) && true === $permission['optional'] ) : ?>
<div class="fs-switch fs-small fs-round fs-on">
<div class="fs-switch fs-small fs-round fs-<?php echo (! isset( $permission['default'] ) || true === $permission['default'] ) ? 'on' : 'off' ?>">
<div class="fs-toggle"></div>
</div>
<?php endif ?>
Expand Down

0 comments on commit 1c7e0bc

Please sign in to comment.