d changes after the implementation of TFH on the hub. * @since 3.4.0 */ public function is_site_connected_to_hub(): bool { // The case if Pro version is activated, it is TFH account and a site is from 3rd party hosting. if ( WP_DEFENDER_PRO_PATH === DEFENDER_PLUGIN_BASENAME && method_exists( $this, 'is_another_hosted_site_connected_to_tfh' ) && $this->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(); } }