| @@ -138,8 +138,49 @@ | ||
| 138 | 138 | return $this->context; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | + * Must the visitor see this error, whatever the site configured? | |
| 143 | + * | |
| 144 | + * Only for errors the visitor caused and can fix on the spot. A refused | |
| 145 | + * consent is one: the form looked sent, no mail ever came, and the only | |
| 146 | + * hint was a toast over a green "Thank you" that vanished after ten | |
| 147 | + * seconds (CF7, Core 5.6.1). Rate limits, blocklists and the like stay | |
| 148 | + * behind `f12_cf7_doubleoptin_show_validation_error` — telling a bot why | |
| 149 | + * it was refused is not always wanted. | |
| 150 | + * | |
| 151 | + * @return bool | |
| 152 | + */ | |
| 153 | + public function isAlwaysShown(): bool { | |
| 154 | + return self::CONSENT_NOT_GIVEN === $this->code; | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Should the form show this error in place of its own success message? | |
| 159 | + * | |
| 160 | + * @param int $formId The form the submission came from. | |
| 161 | + * | |
| 162 | + * @return bool | |
| 163 | + */ | |
| 164 | + public function shouldShowToVisitor( int $formId ): bool { | |
| 165 | + if ( $this->isAlwaysShown() ) { | |
| 166 | + return true; | |
| 167 | + } | |
| 168 | + | |
| 169 | + /** | |
| 170 | + * Whether a refused submission's reason is shown in the form. | |
| 171 | + * | |
| 172 | + * Default false. A refused consent is always shown and never | |
| 173 | + * reaches this filter. | |
| 174 | + * | |
| 175 | + * @param bool $show Show the error. | |
| 176 | + * @param OptInError $error The error (since 5.6.2). | |
| 177 | + * @param int $formId The form (since 5.6.2). | |
| 178 | + */ | |
| 179 | + return (bool) apply_filters( 'f12_cf7_doubleoptin_show_validation_error', false, $this, $formId ); | |
| 180 | + } | |
| 181 | + | |
| 182 | + /** | |
| 142 | 183 | * Get the default translatable messages for all error codes. |
| 143 | 184 | * |
| 144 | 185 | * @return array<string, string> |
| 145 | 186 | */ |