$code, 'message' => self::message( $code ), 'actions' => self::actions( $code ), ); } /** * Translated message for a normalised code. * * @param string $code Known code or `unknown`. */ private static function message( string $code ): string { switch ( $code ) { case 'expired': return __( 'The connection took too long and expired. Click Connect to start again.', 'agentmysite' ); case 'already_used': return __( 'This connection link was already used. If the plugin shows Connected, you are done; otherwise click Connect to start again.', 'agentmysite' ); case 'verifier_mismatch': return __( 'We could not verify the connection came from this site. Start again, or enter your site key manually.', 'agentmysite' ); case 'site_url_mismatch': return __( 'The site address does not match the one that started the connection. Check Settings, General, Site Address and try again.', 'agentmysite' ); case 'rate_limited': return __( 'Too many attempts. Wait a minute and try again.', 'agentmysite' ); case 'plan_limit_reached': return __( 'Your plan\'s site limit is reached.', 'agentmysite' ); case 'upstream': return __( 'AgentMySite had a problem completing the connection. Please try again in a moment.', 'agentmysite' ); case 'unreachable': return __( 'Your server could not reach AgentMySite. Outbound HTTPS may be blocked by your host; you can enter your site key manually instead.', 'agentmysite' ); case 'host_not_allowed': return __( 'AgentMySite cannot connect to this address. It must be a public https site, without a port, IP address or login in the URL. You can enter your site key manually instead.', 'agentmysite' ); default: return __( 'Something went wrong connecting to AgentMySite. Please try again.', 'agentmysite' ); } } /** * Recovery actions for a normalised code. * * @param string $code Known code or `unknown`. * @return string[] */ private static function actions( string $code ): array { switch ( $code ) { case 'host_not_allowed': return array( 'manual_key' ); case 'plan_limit_reached': return array( 'billing', 'manual_key' ); default: return array( 'retry', 'manual_key' ); } } }