← All changes
|
includes/integrations/forminator/class-convertkit-forminator-admin-section.php
+85
-0
3.3.4
→
3.4.5
View file →
| @@ -115,8 +115,11 @@ | ||
| 115 | 115 | $this->render_container_end(); |
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | + // Warn the user if any Forminator Form subscribes to Kit, and has no Captcha field. | |
| 120 | + $this->maybe_output_spam_protection_warning( $forminator_forms ); | |
| 121 | + | |
| 119 | 122 | // Get Creator Network Recommendations script. |
| 120 | 123 | $creator_network_recommendations = new ConvertKit_Resource_Creator_Network_Recommendations( 'forminator' ); |
| 121 | 124 | $creator_network_recommendations_enabled = $creator_network_recommendations->enabled(); |
| 122 | 125 | |
| @@ -181,8 +184,90 @@ | ||
| 181 | 184 | $this->render_container_end(); |
| 182 | 185 | |
| 183 | 186 | // Render submit button. |
| 184 | 187 | submit_button(); |
| 188 | + | |
| 189 | + } | |
| 190 | + | |
| 191 | + /** | |
| 192 | + * Outputs a warning if one or more Forminator Forms subscribe email addresses | |
| 193 | + * to Kit, and have no Captcha field. | |
| 194 | + * | |
| 195 | + * @since 3.4.5 | |
| 196 | + * | |
| 197 | + * @param array $forminator_forms Forminator Forms. | |
| 198 | + */ | |
| 199 | + private function maybe_output_spam_protection_warning( $forminator_forms ) { | |
| 200 | + | |
| 201 | + // Build a list of Forminator Forms that subscribe to Kit, with no Captcha field. | |
| 202 | + $unprotected_forms = array(); | |
| 203 | + foreach ( $forminator_forms as $forminator_form ) { | |
| 204 | + if ( ! $this->settings->get_convertkit_subscribe_setting_by_forminator_form_id( $forminator_form['id'] ) ) { | |
| 205 | + continue; | |
| 206 | + } | |
| 207 | + | |
| 208 | + if ( $this->form_has_spam_protection( $forminator_form['id'] ) ) { | |
| 209 | + continue; | |
| 210 | + } | |
| 211 | + | |
| 212 | + $unprotected_forms[] = $forminator_form['name']; | |
| 213 | + } | |
| 214 | + | |
| 215 | + // Bail if all Forminator Forms subscribing to Kit have a Captcha field. | |
| 216 | + if ( ! count( $unprotected_forms ) ) { | |
| 217 | + return; | |
| 218 | + } | |
| 219 | + | |
| 220 | + $this->output_warning( | |
| 221 | + sprintf( | |
| 222 | + '%s <strong>%s</strong>. %s <a href="%s" target="_blank">%s</a>', | |
| 223 | + esc_html__( 'The following Forminator Forms subscribe email addresses to Kit, but have no spam protection:', 'convertkit' ), | |
| 224 | + esc_html( implode( ', ', $unprotected_forms ) ), | |
| 225 | + esc_html__( 'Bots may submit fake email addresses, which are then added to your Kit account.', 'convertkit' ), | |
| 226 | + 'https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#captcha-field', | |
| 227 | + esc_html__( 'Add a Captcha field, or enable honeypot protection, in Forminator.', 'convertkit' ) | |
| 228 | + ), | |
| 229 | + 'convertkit-spam-protection-warning' | |
| 230 | + ); | |
| 231 | + | |
| 232 | + } | |
| 233 | + | |
| 234 | + /** | |
| 235 | + * Determines if the given Forminator Form has spam protection, by way of a | |
| 236 | + * Captcha field or Forminator's honeypot setting. | |
| 237 | + * | |
| 238 | + * @since 3.4.5 | |
| 239 | + * | |
| 240 | + * @param int $forminator_form_id Forminator Form ID. | |
| 241 | + * @return bool | |
| 242 | + */ | |
| 243 | + private function form_has_spam_protection( $forminator_form_id ) { | |
| 244 | + | |
| 245 | + if ( ! class_exists( 'Forminator_API' ) ) { | |
| 246 | + return false; | |
| 247 | + } | |
| 248 | + | |
| 249 | + $form = Forminator_API::get_form( $forminator_form_id ); | |
| 250 | + | |
| 251 | + // Assume the form is protected if it can't be read, so we don't warn incorrectly. | |
| 252 | + if ( is_wp_error( $form ) ) { | |
| 253 | + return true; | |
| 254 | + } | |
| 255 | + | |
| 256 | + // Determine if the form has honeypot protection enabled. | |
| 257 | + if ( isset( $form->settings['honeypot'] ) && filter_var( $form->settings['honeypot'], FILTER_VALIDATE_BOOLEAN ) ) { | |
| 258 | + return true; | |
| 259 | + } | |
| 260 | + | |
| 261 | + // Determine if the form has a Captcha field. | |
| 262 | + foreach ( $form->get_fields() as $field ) { | |
| 263 | + $field_array = $field->to_formatted_array(); | |
| 264 | + if ( ! empty( $field_array['type'] ) && $field_array['type'] === 'captcha' ) { | |
| 265 | + return true; | |
| 266 | + } | |
| 267 | + } | |
| 268 | + | |
| 269 | + return false; | |
| 185 | 270 | |
| 186 | 271 | } |
| 187 | 272 | |
| 188 | 273 | /** |