: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2022, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
if ( ! defined( 'ABSPATH' ) ) {
* This class is responsible for managing the user permissions.
* @author Vova Feldman (@svovaf)
class FS_Permission_Manager {
* @var array<number,self>
private static $_instances = array();
const PERMISSION_USER = 'user';
const PERMISSION_SITE = 'site';
const PERMISSION_EVENTS = 'events';
const PERMISSION_ESSENTIALS = 'essentials';
const PERMISSION_DIAGNOSTIC = 'diagnostic';
const PERMISSION_EXTENSIONS = 'extensions';
const PERMISSION_NEWSLETTER = 'newsletter';
static function instance( Freemius $fs ) {
if ( ! isset( self::$_instances[ $id ] ) ) {
self::$_instances[ $id ] = new self( $fs );
return self::$_instances[ $id ];
protected function __construct( Freemius $fs ) {
$this->_storage = FS_Storage::instance( $fs->get_module_type(), $fs->get_slug() );
static function get_all_permission_ids() {
self::PERMISSION_ESSENTIALS,
self::PERMISSION_DIAGNOSTIC,
self::PERMISSION_EXTENSIONS,
self::PERMISSION_NEWSLETTER,
static function get_api_managed_permission_ids() {
self::PERMISSION_EXTENSIONS,
* @param string $permission
static function is_supported_permission( $permission ) {
return in_array( $permission, self::get_all_permission_ids() );
function is_premium_context() {
return ( $this->_fs->is_premium() || $this->_fs->can_use_premium_code() );
* @param bool $is_license_activation
* @param array[] $extra_permissions
function get_permissions( $is_license_activation, array $extra_permissions = array() ) {
return $is_license_activation ?
$this->get_license_activation_permissions( $extra_permissions ) :
$this->get_opt_in_permissions( $extra_permissions );
#--------------------------------------------------------------------------------
#region Opt-In Permissions
#--------------------------------------------------------------------------------
* @param array[] $extra_permissions
function get_opt_in_permissions(
array $extra_permissions = array(),
$load_default_from_storage = false,
$permissions = array_merge(
$this->get_opt_in_required_permissions( $load_default_from_storage ),
$this->get_opt_in_optional_permissions( $load_default_from_storage, $is_optional ),
return $this->get_sorted_permissions_by_priority( $permissions );
* @param bool $load_default_from_storage
function get_opt_in_required_permissions( $load_default_from_storage = false ) {
return array( $this->get_user_permission( $load_default_from_storage ) );
* @param bool $load_default_from_storage
* @param bool $is_optional
function get_opt_in_optional_permissions(
$load_default_from_storage = false,
$this->get_opt_in_diagnostic_permissions( $load_default_from_storage, $is_optional ),
array( $this->get_extensions_permission(
$load_default_from_storage
* @param bool $load_default_from_storage
* @param bool $is_optional
function get_opt_in_diagnostic_permissions(
$load_default_from_storage = false,
$permissions[] = $this->get_permission(
$fs->get_text_inline( 'View Basic Website Info', 'permissions-site' ),
$fs->get_text_inline( 'Homepage URL & title, WP & PHP versions, and site language', 'permissions-site_desc' ),
/* translators: %s: 'Plugin' or 'Theme' */
$fs->get_text_inline( 'To provide additional functionality that\'s relevant to your website, avoid WordPress or PHP version incompatibilities that can break your website, and recognize which languages & regions the %s should be translated and tailored to.', 'permissions-site_tooltip' ),
$fs->get_module_label( true )
$load_default_from_storage
$permissions[] = $this->get_permission(
'admin-' . ( $fs->is_plugin() ? 'plugins' : 'appearance' ),
sprintf( $fs->get_text_inline( 'View Basic %s Info', 'permissions-events' ), $fs->get_module_label() ),
/* translators: %s: 'Plugin' or 'Theme' */
$fs->get_text_inline( 'Current %s & SDK versions, and if active or uninstalled', 'permissions-events_desc' ),
$fs->get_module_label( true )
$load_default_from_storage
#--------------------------------------------------------------------------------
#region License Activation Permissions
#--------------------------------------------------------------------------------
* @param array[] $extra_permissions
function get_license_activation_permissions(
array $extra_permissions = array(),
$include_optional_label = true
$permissions = array_merge(
$this->get_license_required_permissions(),
$this->get_license_optional_permissions( $include_optional_label ),
return $this->get_sorted_permissions_by_priority( $permissions );
* @param bool $load_default_from_storage
function get_license_required_permissions( $load_default_from_storage = false ) {
$permissions[] = $this->get_permission(
self::PERMISSION_ESSENTIALS,
$fs->get_text_inline( 'View License Essentials', 'permissions-essentials' ),
/* translators: %s: 'Plugin' or 'Theme' */
'Homepage URL, %s version, SDK version',
'permissions-essentials_desc'
/* translators: %s: 'Plugin' or 'Theme' */
$fs->get_text_inline( 'To let you manage & control where the license is activated and ensure %s security & feature updates are only delivered to websites you authorize.', 'permissions-essentials_tooltip' ),
$fs->get_module_label( true )
$load_default_from_storage
$permissions[] = $this->get_permission(
'admin-' . ( $fs->is_plugin() ? 'plugins' : 'appearance' ),
sprintf( $fs->get_text_inline( 'View %s State', 'permissions-events' ), $fs->get_module_label() ),
/* translators: %s: 'Plugin' or 'Theme' */
$fs->get_text_inline( 'Is active, deactivated, or uninstalled', 'permissions-events_desc-paid' ),
$fs->get_module_label( true )
sprintf( $fs->get_text_inline( 'So you can reuse the license when the %s is no longer active.', 'permissions-events_tooltip' ), $fs->get_module_label( true ) ),
$load_default_from_storage
function get_license_optional_permissions(
$include_optional_label = false,
$load_default_from_storage = false
$this->get_diagnostic_permission( $include_optional_label, $load_default_from_storage ),
$this->get_extensions_permission( true, $include_optional_label, $load_default_from_storage ),
* @param bool $include_optional_label
* @param bool $load_default_from_storage
function get_diagnostic_permission(
$include_optional_label = false,
$load_default_from_storage = false
return $this->get_permission(
self::PERMISSION_DIAGNOSTIC,
$this->_fs->get_text_inline( 'View Diagnostic Info', 'permissions-diagnostic' ) . ( $include_optional_label ? ' (' . $this->_fs->get_text_inline( 'optional' ) . ')' : '' ),
$this->_fs->get_text_inline( 'WordPress & PHP versions, site language & title', 'permissions-diagnostic_desc' ),
/* translators: %s: 'Plugin' or 'Theme' */
$this->_fs->get_text_inline( 'To avoid breaking your website due to WordPress or PHP version incompatibilities, and recognize which languages & regions the %s should be translated and tailored to.', 'permissions-diagnostic_tooltip' ),
$this->_fs->get_module_label( true )
$load_default_from_storage
#--------------------------------------------------------------------------------
#region Common Permissions
#--------------------------------------------------------------------------------
* @param bool $is_license_activation
* @param bool $include_optional_label
* @param bool $load_default_from_storage
function get_extensions_permission(
$include_optional_label = false,
$load_default_from_storage = false
$is_on_by_default = ! $is_license_activation;
return $this->get_permission(
self::PERMISSION_EXTENSIONS,
$this->_fs->get_text_inline( 'View Plugins & Themes List', 'permissions-extensions' ) . ( $is_license_activation ? ( $include_optional_label ? ' (' . $this->_fs->get_text_inline( 'optional' ) . ')' : '' ) : '' ),
$this->_fs->get_text_inline( 'Names, slugs, versions, and if active or not', 'permissions-extensions_desc' ),
$this->_fs->get_text_inline( 'To ensure compatibility and avoid conflicts with your installed plugins and themes.', 'permissions-events_tooltip' ),
$load_default_from_storage
* @param bool $load_default_from_storage
function get_user_permission( $load_default_from_storage = false ) {
return $this->get_permission(
$this->_fs->get_text_inline( 'View Basic Profile Info', 'permissions-profile' ),
$this->_fs->get_text_inline( 'Your WordPress user\'s: first & last name, and email address', 'permissions-profile_desc' ),
$this->_fs->get_text_inline( 'Never miss important updates, get security warnings before they become public knowledge, and receive notifications about special offers and awesome new features.', 'permissions-profile_tooltip' ),
$load_default_from_storage
#--------------------------------------------------------------------------------
#region Optional Permissions
#--------------------------------------------------------------------------------
function get_newsletter_permission() {
return $this->get_permission(
self::PERMISSION_NEWSLETTER,
$this->_fs->get_text_inline( 'Newsletter', 'permissions-newsletter' ),
$this->_fs->get_text_inline( 'Updates, announcements, marketing, no spam', 'permissions-newsletter_desc' ),
#--------------------------------------------------------------------------------
#region Permissions Storage
#--------------------------------------------------------------------------------
* @param int|null $blog_id
function is_extensions_tracking_allowed( $blog_id = null ) {
return $this->is_permission_allowed( self::PERMISSION_EXTENSIONS, ! $this->_fs->is_premium(), $blog_id );
* @param int|null $blog_id
function is_essentials_tracking_allowed( $blog_id = null ) {
return $this->is_permission_allowed( self::PERMISSION_ESSENTIALS, true, $blog_id );
function is_diagnostic_tracking_allowed( $default = true ) {
return $this->is_premium_context() ?
$this->is_permission_allowed( self::PERMISSION_DIAGNOSTIC, $default ) :
$this->is_permission_allowed( self::PERMISSION_SITE, $default );
* @param int|null $blog_id
function is_homepage_url_tracking_allowed( $blog_id = null ) {
return $this->is_permission_allowed( $this->get_site_permission_name(), true, $blog_id );
* @param int|null $blog_id
function update_site_tracking( $is_enabled, $blog_id = null, $only_if_not_set = false ) {
$permissions = $this->get_site_tracking_permission_names();
foreach ( $permissions as $permission ) {
if ( ! $only_if_not_set || ! $this->is_permission_set( $permission, $blog_id ) ) {
$result = ( $result && $this->update_permission_tracking_flag( $permission, $is_enabled, $blog_id ) );
* @param string $permission
* @param int|null $blog_id
function is_permission_allowed( $permission, $default = false, $blog_id = null ) {
if ( ! self::is_supported_permission( $permission ) ) {
return $this->is_permission( $permission, true, $blog_id );
* @param string $permission
* @param bool $is_allowed
* @param int|null $blog_id
function is_permission( $permission, $is_allowed, $blog_id = null ) {
if ( ! self::is_supported_permission( $permission ) ) {