*/ public function get_codes(): array { return array( self::HONEYPOT_FILLED, self::TOO_FAST, self::MISSING_TOKEN, self::INVALID_TOKEN, self::RATE_LIMIT_EXCEEDED, self::EXCESSIVE_LINKS, ); } /** * Check whether a reason code is known. * * @param string $reason_code Reason code. */ public function has( string $reason_code ): bool { return in_array( $reason_code, $this->get_codes(), true ); } /** * Get safe labels for admin display. * * @return array */ public function get_labels(): array { return array( self::HONEYPOT_FILLED => function_exists( '__' ) ? __( 'Hidden field was completed.', '2o2code-spamless-forms' ) : 'Hidden field was completed.', self::TOO_FAST => function_exists( '__' ) ? __( 'Submission was completed too quickly.', '2o2code-spamless-forms' ) : 'Submission was completed too quickly.', self::MISSING_TOKEN => function_exists( '__' ) ? __( 'Form verification could not be confirmed.', '2o2code-spamless-forms' ) : 'Form verification could not be confirmed.', self::INVALID_TOKEN => function_exists( '__' ) ? __( 'Form verification was invalid or expired.', '2o2code-spamless-forms' ) : 'Form verification was invalid or expired.', self::RATE_LIMIT_EXCEEDED => function_exists( '__' ) ? __( 'Too many submissions were received in a short period.', '2o2code-spamless-forms' ) : 'Too many submissions were received in a short period.', self::EXCESSIVE_LINKS => function_exists( '__' ) ? __( 'The submission contained an unusually high number of links.', '2o2code-spamless-forms' ) : 'The submission contained an unusually high number of links.', ); } /** * Get one safe label. * * @param string $reason_code Reason code. */ public function get_label( string $reason_code ): string { $labels = $this->get_labels(); if ( isset( $labels[ $reason_code ] ) ) { return $labels[ $reason_code ]; } if ( function_exists( '__' ) ) { return __( 'An unrecognized spam signal was detected.', '2o2code-spamless-forms' ); } return 'An unrecognized spam signal was detected.'; } }