Noptin_WP_Registration_Form::subscribe_from_registration( int $user_id )

Subscribes from WP Registration Form


Parameters Parameters

$user_id

(int) (Required)


Top ↑

Return Return

(int|null)


Top ↑

Source Source

File: includes/integrations/class-noptin-wp-registration-form.php

	public function subscribe_from_registration( $user_id ) {

		// Check if the user exists.
		$user = get_userdata( $user_id );

		if ( ! $user instanceof WP_User ) {
			return false;
		}

		// Prepare subscriber fields.
		$noptin_fields = array(
			'_subscriber_via' => 'registration',
			'wp_user_id'      => $user->ID,
			'email'           => $user->user_email,
			'name'            => $user->display_name,
			'first_name'      => $user->user_firstname,
			'last_name'       => $user->user_lastname,
		);

		$noptin_fields = array_filter( $noptin_fields );
		$subscriber_id = get_noptin_subscriber_id_by_email( $user->user_email );

		// If the subscriber does not exist, create a new one.
		if ( empty( $subscriber_id ) ) {

			// Ensure the subscription checkbox was triggered.
			if( $this->triggered() ) {
				return $this->add_subscriber( $noptin_fields, $user_id );
			}
			return null;

		}

		// Else, update the existing subscriber.
		unset( $noptin_fields['_subscriber_via'] );
		return $this->update_subscriber( $subscriber_id, $noptin_fields, $user_id );

	}


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