Noptin_WPForms::add_subscriber( array $fields, array $entry, array $form_data, int $entry_id )

Save subscriptions


Parameters Parameters

$fields

(array) (Required) List of fields.

$entry

(array) (Required) Submitted form entry.

$form_data

(array) (Required) Form data and settings.

$entry_id

(int) (Required) Saved entry id.


Top ↑

Source Source

File: includes/integrations/class-noptin-wpforms.php

    function add_subscriber( $fields, $entry, $form_data, $entry_id ) {

		// Check that the form was configured for email subscriptions.
		if ( empty( $form_data['settings']['enable_noptin'] ) || '1' != $form_data['settings']['enable_noptin'] ) {
			return;
		}

		// Return early if no email.
        $email_field_id = $form_data['settings']['noptin_field_email'];
		if ( ! isset( $email_field_id ) || empty( $fields[ $email_field_id ]['value'] ) ) {
			return;
		}

		// Or no consent.
		$consent_field_id = $form_data['settings']['noptin_field_gdpr'];
		if ( '' !== $consent_field_id && empty( $fields[ $consent_field_id ]['value'] ) ) {
			return;
		}

		// Prepare Noptin Fields.
		$noptin_fields = array(
			'_subscriber_via' => 'WPForms',
			'email'           => sanitize_email( $fields[ $email_field_id ]['value'] ),
		);

		// Add the subscriber's IP address.
		$address = noptin_get_user_ip();
		if ( ! empty( $address ) && '::1' !== $address ) {
			$subscriber['ip_address'] = $address;
		}

		// Referral page.
		if ( ! empty( $_REQUEST['referrer'] ) ) {
            $subscriber['conversion_page'] = esc_url_raw( $_REQUEST['referrer'] );
        }

		// Maybe include the subscriber name...
		$name_field_id = $form_data['settings']['noptin_field_name'];
		if ( is_numeric( $name_field_id ) ) {
			$noptin_fields['name'] = noptin_clean( $fields[ $name_field_id ]['value'] );
		}

		// ... and their GDPR status.
		if ( is_numeric( $consent_field_id ) && ! empty( $fields[ $consent_field_id ]['value'] ) ) {
			$noptin_fields['GDPR_consent'] = 1;
		}

		// And special fields.
		foreach ( get_special_noptin_form_fields() as $name => $field ) {

			$id         = esc_attr( sanitize_html_class( $name ) );

			if ( isset( $form_data['settings']['noptin_field_' . $id] ) ) {
				$form_field           = $form_data['settings']['noptin_field_' . $id];
				$noptin_fields[ $id ] = noptin_clean( $fields[ $form_field ]['value'] );
			}

		}

		$noptin_fields['integration_data'] = compact( 'fields', 'entry', 'form_data', 'entry_id' );

		$noptin_fields = apply_filters( 'noptin_wpforms_integration_new_subscriber_fields', array_filter( $noptin_fields ) );

		add_noptin_subscriber( $noptin_fields );

    }


Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation