get_apikey() !== false;
}
/**
* Check if user is a paid one in WPMU DEV.
*
* @return bool
*/
public function is_member(): bool {
if (
$this->is_dash_activated() && method_exists( WPMUDEV_Dashboard::$upgrader, 'user_can_install' )
) {
return WPMUDEV_Dashboard::$upgrader->user_can_install(
Config_Hub_Helper::WDP_ID,
true
);
}
return false;
}
/**
* Check if user is a WPMU DEV admin.
*
* @return bool
* @since 2.6.3
*/
public function is_wpmu_dev_admin(): bool {
if (
'dashboard' === $this->resolve_connection_mode() &&
is_object( WPMUDEV_Dashboard::$site ) &&
method_exists( WPMUDEV_Dashboard::$site, 'allowed_user' )
) {
return WPMUDEV_Dashboard::$site->allowed_user( get_current_user_id() );
}
return false;
}
/**
* Returns whether the current install is a Pro version.
*
* @return bool
*/
protected function is_pro_install(): bool {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$is_pro = file_exists( $this->get_abs_plugin_path_by_slug( WP_DEFENDER_PRO_PATH ) )
&& is_plugin_active( WP_DEFENDER_PRO_PATH );
return $is_pro;
}
/**
* Returns the page title.
*
* @return string Page title.
*/
public function get_page_title(): string {
return $this->is_pro_install()
? esc_html__( 'Defender Pro', 'defender-security' )
: esc_html__( 'Defender', 'defender-security' );
}
/**
* Returns the sidebar menu title, including a "Pro" badge span when on a Pro install.
*
* @return string Menu title.
*/
public function get_menu_title(): string {
if ( $this->is_pro_install() ) {
return sprintf(
'%1$s',
esc_html__( 'Defender', 'defender-security' ),
esc_html__( 'Pro', 'defender-security' )
);
}
return esc_html__( 'Defender', 'defender-security' );
}
/**
* Return icon svg image.
*
* @return string
*/
public function get_menu_icon(): string {
ob_start();
?>
is_another_hosted_site_connected_to_tfh()
) {
return '' !== $this->get_api_key();
} else {
$hub_site_id = method_exists( $this, 'get_site_id' ) ? $this->get_site_id() : null;
return is_int( $hub_site_id ) && $hub_site_id > 0;
}
}
/**
* Check if HUB option is disabled, e.g. Global IP.
*
* @return bool
*/
public function is_disabled_hub_option(): bool {
return 'none' === $this->resolve_connection_mode();
}
/**
* Get remote access.
*/
public function get_remote_access() {
if ( ! class_exists( 'WPMUDEV_Dashboard' ) ) {
return false;
}
// Use backward compatibility.
if ( WPMUDEV_Dashboard::$version > '4.11.9' ) {
return WPMUDEV_Dashboard::$settings->get( 'remote_access' );
} else {
return WPMUDEV_Dashboard::$site->get_option( 'remote_access' );
}
}
/**
* Checks if the Hub connector module (HCM) is connected.
*
* @return bool True if connected, false otherwise.
*/
public static function get_hcm_status(): bool {
return class_exists( 'WPMUDEV\Hub\Connector\API' ) && API::get()->is_logged_in();
}
/**
* Checks if the Dashboard plugin has a usable Hub connection.
*
* @return bool
*/
protected function is_dashboard_connected(): bool {
return $this->is_dash_activated()
&& is_object( WPMUDEV_Dashboard::$api )
&& WPMUDEV_Dashboard::$api->has_key()
&& (int) WPMUDEV_Dashboard::$api->get_site_id() > 0;
}
/**
* Resolve the active Hub connection mode for this request.
*
* @return string 'dashboard' | 'hub_connector' | 'none'
* @since 6.0.0
*/
public function resolve_connection_mode(): string {
if ( $this->is_dashboard_connected() ) {
return 'dashboard';
} elseif ( self::get_hcm_status() ) {
return 'hub_connector';
}
return 'none';
}
/**
* Checks if Hub Connector is connected. If Dash plugin is not installed Hub connector can take over.
*
* @return bool
*/
public function hub_connector_connected(): bool {
return 'none' !== $this->resolve_connection_mode();
}
/**
* Upgrade the method to get api key from Dashboard plugin or Hub Connector module.
*
* @return string
*/
public function get_api_key(): string {
if ( 'dashboard' === $this->resolve_connection_mode() ) {
$api_key = WPMUDEV_Dashboard::$api->get_key();
} elseif ( class_exists( 'WPMUDEV\Hub\Connector\API' ) ) {
$api_key = API::get()->get_api_key();
} else {
$api_key = '';
}
return $api_key;
}
/**
* Get Membership type.
*
* @return string
*/
public function get_membership_type() {
if ( 'dashboard' === $this->resolve_connection_mode() ) {
return WPMUDEV_Dashboard::$api->get_membership_status();
} elseif ( self::get_hcm_status() ) {
return Data::get()->membership_type();
}
return 'free';
}
/**
* Check if the membership type is expired.
*
* @return bool True if membership is expired, false otherwise.
*/
public function is_expired_membership_type(): bool {
return 'expired' === $this->get_membership_type();
}
/**
* Logout from hub.
*
* @return array|bool|\WP_Error
*/
public function logout() {
return API::get()->logout();
}
/**
* Check if site is connected to HUB via HCM or Dash.
*
* @return bool
*/
public function is_site_connected_to_hub_via_hcm_or_dash(): bool {
return $this->hub_connector_connected() || self::get_hcm_status();
}
}