: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2015, Freemius, Inc.
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
if ( ! defined( 'ABSPATH' ) ) {
class FS_Admin_Menu_Manager {
protected $_module_unique_affix;
private $_is_override_exact;
* @var array<string,bool>
private $_default_submenu_items;
private $_first_time_path;
private $_network_menu_exists;
* @var FS_Admin_Menu_Manager[]
private static $_instances = array();
* @param number $module_id
* @param string $module_type
* @param string $module_unique_affix
* @return FS_Admin_Menu_Manager
static function instance( $module_id, $module_type, $module_unique_affix ) {
$key = 'm_' . $module_id;
if ( ! isset( self::$_instances[ $key ] ) ) {
self::$_instances[ $key ] = new FS_Admin_Menu_Manager( $module_id, $module_type, $module_unique_affix );
return self::$_instances[ $key ];
protected function __construct( $module_id, $module_type, $module_unique_affix ) {
$this->_logger = FS_Logger::get_logger( WP_FS__SLUG . '_' . $module_id . '_admin_menu', WP_FS__DEBUG_SDK, WP_FS__ECHO_DEBUG_SDK );
$this->_module_id = $module_id;
$this->_module_type = $module_type;
$this->_module_unique_affix = $module_unique_affix;
private function get_option( &$options, $key, $default = false ) {
return ! empty( $options[ $key ] ) ? $options[ $key ] : $default;
private function get_bool_option( &$options, $key, $default = false ) {
return isset( $options[ $key ] ) && is_bool( $options[ $key ] ) ? $options[ $key ] : $default;
function init( $menu, $is_addon = false ) {
$this->_menu_exists = ( isset( $menu['slug'] ) && ! empty( $menu['slug'] ) );
$this->_network_menu_exists = ( ! empty( $menu['network'] ) && true === $menu['network'] );
$this->_menu_slug = ( $this->_menu_exists ? $menu['slug'] : $this->_module_unique_affix );
$this->_default_submenu_items = array();
$this->_is_top_level = true;
$this->_is_override_exact = false;
$this->_parent_slug = false;
$this->_parent_type = 'page';
$this->_default_submenu_items = array(
'contact' => $this->get_bool_option( $menu, 'contact', true ),
'support' => $this->get_bool_option( $menu, 'support', true ),
'affiliation' => $this->get_bool_option( $menu, 'affiliation', true ),
'account' => $this->get_bool_option( $menu, 'account', true ),
'pricing' => $this->get_bool_option( $menu, 'pricing', true ),
'addons' => $this->get_bool_option( $menu, 'addons', true ),
$this->_type = $this->get_option( $menu, 'type', 'page' );
$this->_is_override_exact = $this->get_bool_option( $menu, 'override_exact' );
if ( isset( $menu['parent'] ) ) {
$this->_parent_slug = $this->get_option( $menu['parent'], 'slug' );
$this->_parent_type = $this->get_option( $menu['parent'], 'type', 'page' );
// If parent's slug is different, then it's NOT a top level menu item.
$this->_is_top_level = ( $this->_parent_slug === $this->_menu_slug );
* If no parent then top level if:
* - Has custom admin menu ('page')
* - CPT menu type ('cpt')
// $this->_is_top_level = in_array( $this->_type, array(
$first_path = $this->get_option( $menu, 'first-path', false );
if ( ! empty( $first_path ) && is_string( $first_path ) ) {
$this->_first_time_path = $first_path;
* Check if top level menu.
* @author Vova Feldman (@svovaf)
* @return bool False if submenu item.
function is_top_level() {
return $this->_is_top_level;
* Check if the page should be override on exact URL match.
* @author Vova Feldman (@svovaf)
* @return bool False if submenu item.
function is_override_exact() {
return $this->_is_override_exact;
* Get the path of the page the user should be forwarded to after first activation.
* @author Vova Feldman (@svovaf)
* @param bool $is_network Since 2.4.5
function get_first_time_path( $is_network = false ) {
if ( empty ( $this->_first_time_path ) ) {
return $this->_first_time_path;
return network_admin_url( $this->_first_time_path );
return admin_url( $this->_first_time_path );
* Check if plugin's menu item is part of a custom top level menu.
* @author Vova Feldman (@svovaf)
function has_custom_parent() {
return ! $this->_is_top_level && is_string( $this->_parent_slug );
* @author Leo Fajardo (@leorw)
return $this->_menu_exists;
* @author Vova Feldman (@svovaf)
function has_network_menu() {
return $this->_network_menu_exists;
* @author Leo Fajardo (@leorw)
* @param string $menu_slug
function set_slug_and_network_menu_exists_flag($menu_slug ) {
$this->_menu_slug = $menu_slug;
$this->_network_menu_exists = false;
* @author Vova Feldman (@svovaf)
* @param bool $ignore_menu_existence Since 1.2.2.7 If true, check if the submenu item visible even if there's no parent menu.
function is_submenu_item_visible( $id, $default = true, $ignore_menu_existence = false ) {
if ( ! $ignore_menu_existence && ! $this->has_menu() ) {
$this->_module_unique_affix,
$this->get_bool_option( $this->_default_submenu_items, $id, $default ),
* Calculates admin settings menu slug.
* If plugin's menu slug is a file (e.g. CPT), uses plugin's slug as the menu slug.
* @author Vova Feldman (@svovaf)
function get_slug( $page = '' ) {
return ( ( false === strpos( $this->_menu_slug, '.php?' ) ) ?
$this->_module_unique_affix ) . ( empty( $page ) ? '' : ( '-' . $page ) );
* @author Vova Feldman (@svovaf)
function get_parent_slug() {
return $this->_parent_slug;
* @author Vova Feldman (@svovaf)
* @author Vova Feldman (@svovaf)
return ( 0 === strpos( $this->_menu_slug, 'edit.php?post_type=' ) ||
* @author Vova Feldman (@svovaf)
function get_parent_type() {
return $this->_parent_type;
* @author Vova Feldman (@svovaf)
function get_raw_slug() {
return $this->_menu_slug;
* Get plugin's original menu slug.
* @author Vova Feldman (@svovaf)
function get_original_menu_slug() {
if ( 'cpt' === $this->_type ) {
return add_query_arg( array(
'post_type' => $this->_menu_slug
if ( false === strpos( $this->_menu_slug, '.php?' ) ) {
return $this->_menu_slug;
return $this->_module_unique_affix;
* @author Vova Feldman (@svovaf)
function get_top_level_menu_slug() {
return $this->has_custom_parent() ?
$this->get_parent_slug() :
* Is user on plugin's admin activation page.
* @author Vova Feldman (@svovaf)
* @param bool $show_opt_in_on_themes_page Since 2.3.1
* @deprecated Please use is_activation_page() instead.
function is_main_settings_page( $show_opt_in_on_themes_page = false ) {
return $this->is_activation_page( $show_opt_in_on_themes_page );
* Is user on product's admin activation page.
* @author Vova Feldman (@svovaf)
* @param bool $show_opt_in_on_themes_page Since 2.3.1
function is_activation_page( $show_opt_in_on_themes_page = false ) {
if ( $show_opt_in_on_themes_page ) {
* In activation only when show_optin query string param is given.
( WP_FS__MODULE_TYPE_THEME === $this->_module_type ) &&
Freemius::is_themes_page() &&
fs_request_get_bool( $this->_module_unique_affix . '_show_optin' )
if ( $this->_menu_exists &&
( fs_is_plugin_page( $this->_menu_slug ) || fs_is_plugin_page( $this->_module_unique_affix ) )
* Module has a settings menu and the context page is the main settings page, so assume it's in
* activation (doesn't really check if already opted-in/skipped or not).
* Override submenu's action.
* @author Vova Feldman (@svovaf)
* @param string $parent_slug
* @param string $menu_slug
* @param callable $function
* @return false|string If submenu exist, will return the hook name.