freemius / wordpress-sdk
Freemius WordPress SDK
Requires
- php: >=5.6
Requires (Dev)
- dev-master
- 2.8.1
- 2.8.0
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.12
- 2.5.11
- 2.5.10
- 2.5.9
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.4-rc.1
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0-rc.2
- 2.5.0-rc.1
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 1.7.4
- 1.7.3
- 1.2.4
- 1.2.3
- 1.2.2.9
- 1.2.2.8
- 1.2.1.6
- 1.2.1.5
- 1.2.1
- 1.2.0
- 1.1.9
- 1.1.8.1
- 1.1.8
- 1.1.7.5
- 1.1.7.4
- 1.1.7.3
- 1.1.6.5
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- dev-develop
- dev-feature/daniele-fix-huge-cache
- dev-hotfix/swas/sdk-iframe-removal
- dev-feature/daniele/avoid-sending-name-and-email-if-not-required
- dev-feature/static-analysis-level-1-fixes
- dev-feature/free-premium-parallel-activation-support-enhancements
- dev-feature/swas/try-parallel-activation
- dev-feature/menu-url-fix
- dev-hotfix/account-template-escaping-fix
- dev-feature/license-dialog-selected-license-fix
- dev-feature/daniele-fix-trial-box-layout
- dev-feature/enrich-debug-page-with-site-url-and-cron
- dev-free
- dev-feature/cleanup-styling
- dev-feature/supported-localhost-urls-updates
- dev-feature/opt-in-moderation-fix
- dev-feature/avoid-sending-name-and-email-if-not-required
- dev-dependabot/npm_and_yarn/multi-a9f852c250
- dev-feature/fix-dialog-box-heading-size
- dev-dependabot/npm_and_yarn/postcss-8.4.38
- dev-feature/incomplete-class-typed-objects-fix
- dev-feature/fix-loading-pluggable-on-theme-preview
- dev-feature/update-gulp-dependencies
- dev-feature/code-conventions-fix
- dev-feature/translation-fixes
- dev-feature/backward-compatibility-fix
- dev-feature/newest-sdk-version-loader-compatibility
- dev-feature/version-254-preparation
- dev-feature/storage-layer-optimization
- dev-feature/main-file-location-active_plugin-enhancement
- dev-feature/multisite-clone-detection-fix
- dev-feature/options-cache-enhancements
- dev-hotfix/php8.1-fs-key-value-storage
- dev-feature/security-patch-develop-2.5.0-rc.2
- dev-feature/view-details-issue-for-premium-only-non-add-on-plugin-fix
- dev-feature/multisite-related-fixes
- dev-feature/clone-resolution
- dev-features/clone-resolution-admin-notices
- dev-feature/purchase-details-admin-notice
- dev-feature/fix-cta-url-plugin-info-dialog
- dev-feature/curl-tester
- dev-feature/whitelabel-mode-filter
- dev-feature/user-localhost-site
- dev-feature/highlight-package-of-single-plan
- dev-feature/bundle-license-activation-enhancements
- dev-feature/network-migration-enhancements
- dev-feature/optin-enhancements
- dev-feature/developer-license
- dev-feature/license-key-and-email-activation
- dev-feature/beta-mode-enhancements
- dev-feature/ms-network-admin-detection-fix
- dev-feature/license-sync-updates
- dev-feature/beta-mode
- dev-feature/premium-theme-details-dialog
- dev-feature/function-definition-fixes
- dev-feature/redirection-fixes
- dev-feature/theme-fixes2
- dev-feature/theme-fixes
- dev-feature/optin-fixes
- dev-feature/network-plugin-version-updates
- dev-feature/options-network-migration
- dev-feature/opt-in-eu
- dev-feature/latest-premium-version-dialog-box
- dev-feature/store-install-ip
- dev-feature/user-recovery
- dev-feature/affiliation-submenu-v2
- dev-feature/affiliation-submenu
- dev-feature/fs-theme-mode-v7
- dev-feature/secure-redirects-process-for-license-activation
- dev-feature/ninja-forms
- dev-pr/24
This package is auto-updated.
Last update: 2024-09-26 10:23:26 UTC
README
欢迎使用Freemius SDK官方仓库!将SDK添加到您的WordPress插件、主题或附加组件中,将使您能够享受到使用Freemius平台带来的所有好处,例如
Freemius真正赋予开发者创建繁荣的订阅制业务的能力。
如果您是Freemius的新用户,我们建议您首先查看我们的入门指南。
如果您是WordPress插件或主题开发者,并且对使用Freemius进行货币化感兴趣,您可以免费注册账户
https://dashboard.freemius.com/register/
一旦您设置了账户并熟悉了所有操作,您就可以开始将Freemius集成到您的WordPress产品中
您可以在以下位置查看一些已利用Freemius功能的现有WordPress.org插件和主题
代码文档
您可以在以下位置找到SDK的文档:https://freemius.com/help/documentation/wordpress-sdk/
集成 & 初始化SDK
作为集成过程的一部分,您需要将Freemius SDK的最新版本添加到您的WordPress项目中。
然后,当您完成SDK集成表单后,将生成一段代码,您需要将其复制并粘贴到主插件的PHP文件顶部,在插件头部注释之后。
注意:对于主题,这将是根目录下的functions.php
文件。
典型的SDK片段将类似于以下内容(您的特定片段可能略有不同,具体取决于您的集成)
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' ); }
使用示例
您可以通过在特定插件/主题的短代码函数前加上前缀来调用任何SDK方法(在开发者仪表板中完成SDK集成表单时指定)
<?php my_prefix_fs()->get_upgrade_url(); ?>
或者当在某个范围内多次调用Freemius时,建议使用全局变量
<?php global $my_prefix_fs; $my_prefix_fs->get_account_url(); ?>
SDK还有许多其他方法可供您使用,以增强您的WordPress产品的功能。一些更常见的用例在Freemius SDK Gists文档中有介绍。
添加基于许可证的逻辑示例
添加营销内容,鼓励用户升级到您的付费版本
<?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>'; } ?>
添加仅适用于您高级插件版本的逻辑
<?php // This "if" block will be auto removed from the Free version. if ( my_prefix_fs()->is__premium_only() ) { // ... premium only logic ... } ?>
要添加仅适用于您高级插件版本的功能,只需将__premium_only作为函数名称的后缀即可。只需确保调用该方法的任何直接或通过钩子的方式的行也包含仅高级逻辑即可
<?php class My_Plugin { function init() { ... // This "if" block will be auto removed from the free version. if ( my_prefix_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() { ... } } ?>
添加仅针对您的“专业”计划客户的逻辑
<?php if ( my_prefix_fs()->is_plan('professional', true) ) { // .. logic related to Professional plan only ... } ?>
添加逻辑,仅对处于“专业”计划或更高计划的客户执行
<?php if ( my_prefix_fs()->is_plan('professional') ) { // ... logic related to Professional plan and higher plans ... } ?>
添加逻辑,仅在您的付费插件版本中可用,并且仅对处于“专业”计划(以及更高计划)的客户执行
<?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 ... } ?>
仅针对试用用户添加逻辑
<?php if ( my_prefix_fs()->is_trial() ) { // ... logic for users in trial ... } ?>
为指定的付费计划添加逻辑
<?php // This "if" block will be auto removed from the Free version. if ( my_prefix_fs()->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 ... } } ?>
排除免费插件版本中的文件和文件夹
排除免费版本中的文件有两种方法。
- 在文件扩展名前添加
__premium_only
。例如,functions__premium_only.php 只会在付费插件版本中包含。这适用于所有类型的文件,而不仅仅是 PHP。 - 将特殊元标签
@fs_premium_only
添加到插件的主要 PHP 文件头部。例如
<?php /** * 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 ... ?>
在上面的示例插件头部中,文件 /lib/functions.php
和目录 /premium-files/
将从免费插件版本中删除。
WordPress.org 合规性
根据 WordPress.org 指南,您不允许提交包含付费代码的插件
托管在 WordPress.org 服务器上的所有代码必须是免费且完全功能的。如果您想销售插件的高级功能(如“专业”版本),则必须从您自己的网站销售和提供该代码,我们不会在我们的服务器上托管它。
因此,如果您想将免费插件版本部署到 WordPress.org,请确保您使用 if ( my_prefix_fs()->{{ method }}__premium_only() )
将所有付费代码包装起来,或使用 SDK 提供的其他方法 来排除付费版本中的功能及文件。
部署
压缩 Freemius 产品的根文件夹,并在 Freemius 开发者仪表板 中的“部署”部分上传。插件/主题将被一个自定义开发的 PHP 处理器 自动扫描和处理,该处理器将自动生成您插件的两个版本
- 付费版本:与您上传的版本相同,包括所有代码(除了您的
secret_key
)。将仅对付费或试用客户启用下载。 - 免费版本:从您的付费功能中移除的代码(基于添加的逻辑
{ method }__premium_only()
)。
免费版本是您应该提供给用户下载的版本。因此,下载免费生成的版本并上传到您的网站。或者,如果您的插件符合 WordPress.org 标准,并且您确保使用不同提供的技术排除了所有付费代码,您可以将下载的免费版本部署到 .org 存储库。
许可证
版权所有 © Freemius®,Inc。
许可协议:GNU 通用公共许可证(版本 3)。
贡献
请参阅我们的 贡献指南。