Noptin_WP_Comment_Form::subscribe_from_comment( int $comment_id,  $comment_approved = '' )

Subscribes from WP Registration Form


Parameters Parameters

$comment_id

(int) (Required)


Top ↑

Return Return

(int|null)


Top ↑

Source Source

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

	public function subscribe_from_comment( $comment_id, $comment_approved = '' ) {

		// is this a spam comment?
		if ( $comment_approved === 'spam' ) {
			return false;
		}

		// Check if the user exists.
		$author = get_comment_author( $comment_id );

		if ( 'Anonymous' === $author ) {
			$author = '';
		}


		// Prepare subscriber fields.
		$noptin_fields = array(
			'_subscriber_via' => 'comment',
			'comment_id'      => $comment_id,
			'email'           => get_comment_author_email( $comment_id ),
			'name'            => $author,
			'website'         => get_comment_author_url( $comment_id ),
			'ip_address'      => get_comment_author_IP( $comment_id ),
		);

		$noptin_fields = array_filter( $noptin_fields );
		$subscriber_id = get_noptin_subscriber_id_by_email( $noptin_fields['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, $comment_id );
			}
			return null;

		}

		// Else, update the existing subscriber.
		unset( $noptin_fields['_subscriber_via'] );
		return $this->update_subscriber( $subscriber_id, $noptin_fields, $comment_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