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 ( $this->is_dash_activated() && method_exists( 'WPMUDEV_Dashboard_Site', 'allowed_user' ) ) { return WPMUDEV_Dashboard::$site->allowed_user( get_current_user_id() ); } return false; } /** * Bring the plugin menu title. * * @return string Menu title. */ public function get_menu_title(): string { if ( $this->is_pro() ) { $menu_title = esc_html__( 'Defender Pro', 'defender-security' ); } else { // Check if it's Pro but user logged the WPMU DEV Dashboard out. require_once ABSPATH . 'wp-admin/includes/plugin.php'; $menu_title = file_exists( $this->get_abs_plugin_path_by_slug( WP_DEFENDER_PRO_PATH ) ) && is_plugin_active( WP_DEFENDER_PRO_PATH ) ? esc_html__( 'Defender Pro', 'defender-security' ) : esc_html__( 'Defender', 'defender-security' ); } return $menu_title; } /** * 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 = $this->get_site_id(); 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 ! $this->is_dash_activated() || ! $this->is_site_connected_to_hub(); } /** * Get remote access. */ public function get_remote_access() { // 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 is connected. * * @return bool True if connected, false otherwise. */ public static function get_status(): bool { return API::get()->is_logged_in(); } /** * 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 { if ( $this->is_dash_activated() ) { $dash_api = WPMUDEV_Dashboard::$api; $connected = (bool) $dash_api->has_key(); } else { $connected = self::get_status(); } return $connected; } /** * Upgrade the method to get api key from Dashboard plugin or Hub Connector module. * * @return string */ public function get_api_key(): string { if ( $this->is_dash_activated() ) { $api_key = WPMUDEV_Dashboard::$api->get_key(); } else { $api_key = API::get()->get_api_key(); } return $api_key; } /** * Get Membership type. * * @return string */ public function get_membership_type() { if ( $this->is_dash_activated() ) { return WPMUDEV_Dashboard::$api->get_membership_status(); } elseif ( self::get_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_status(); } }