false, 'has__email' => false, ); $this->walk_blocks_for_email( $blocks, $result ); if ( $result['has_email'] ) { if ( $result['has__email'] ) { return self::FIELD; } return '_email'; } return 'email'; } private function walk_blocks_for_email( array $blocks, array &$result ) { foreach ( $blocks as $block ) { if ( ! is_array( $block ) ) { continue; } if ( isset( $block['attrs']['name'] ) ) { if ( 'email' === $block['attrs']['name'] ) { $result['has_email'] = true; } if ( '_email' === $block['attrs']['name'] ) { $result['has__email'] = true; } } if ( ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) { $this->walk_blocks_for_email( $block['innerBlocks'], $result ); } } } public function on_render_field( string $content, string $field_name, array $attrs ): string { $type = $attrs['action_type'] ?? ''; if ( 'submit-field' !== $field_name || 'submit' !== $type ) { return $content; } $args = jet_form_builder()->post_type->get_args(); if ( empty( $args['use_honeypot'] ) ) { return $content; } $name = $this->find_email_field_name( Live_Form::instance()->blocks ); $field = Live_Form::force_render_field( 'text-field', array( 'field_type' => 'email', 'name' => $name, 'autocomplete' => 'off', ) ); $content .= sprintf( '
%s
', $field ); return $content; } /** * @param array $request * * @return array * @throws Spam_Exception */ public function handle_request( array $request ): array { $args = jet_form_builder()->post_type->get_args(); if ( empty( $args['use_honeypot'] ) ) { return $request; } $honeypot_name = $this->find_email_field_name( jet_form_builder()->form_handler->request_handler->_fields ); if ( ! empty( $request[ $honeypot_name ] ) ) { // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped throw new Spam_Exception( self::SPAM_EXCEPTION ); } unset( $request[ $honeypot_name ] ); return $request; } public function handle_global_messages( array $types ): array { $types[ self::SPAM_EXCEPTION ] = array( 'label' => __( 'Honeypot validation failed', 'jet-form-builder' ), 'value' => __( 'You are not allowed to fill in the honeypot field', 'jet-form-builder' ), ); return $types; } }