sync_users_to_noptin_subscribers( string|array $users_to_sync = array() )

Synces users to existing subscribers.


Description Description

See also See also


Top ↑

Parameters Parameters

$users_to_sync

(string|array) (Optional) The WordPress users to sync to Noptin.

Default value: array()


Top ↑

Return Return

(void.)


Top ↑

Source Source

File: includes/subscriber.php

function sync_users_to_noptin_subscribers( $users_to_sync = array() ) {

	// Arrays only please.
	$users_to_sync = array_filter( noptin_parse_int_list( $users_to_sync ) );

	foreach ( array_unique( $users_to_sync ) as $user_id ) {

		// Get the user data...
		$user_info = get_userdata( $user_id );

		// ... and abort if it is missing.
		if ( empty( $user_info ) ) {
			continue;
		}

		// If the user is not yet subscribed, subscribe them.
		$subscriber_id = add_noptin_subscriber(
			array(
				'email'           => $user_info->user_email,
				'name'            => $user_info->display_name,
				'active'          => 0,
				'_subscriber_via' => 'users_sync',
			)
		);

		if ( is_numeric( $subscriber_id ) ) {
			update_user_meta( $user_id, 'noptin_subscriber_id', $subscriber_id );
			update_noptin_subscriber_meta( $subscriber_id, 'wp_user_id', $user_id );
		}

	}

}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.2.3Introduced.

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