Helper::prepare_emails()

Description #

Get email ids of user. If email passed then add it to email property.

Changelog #

VersionDescription
4.1.0Introduced.

Source #

File: addons/email/class-helper.php

	public function prepare_emails() {
		global $wpdb;

		if ( empty( $this->args['users'] ) ) {
			return;
		}

		$user_ids = array();

		foreach ( $this->args['users'] as $k => $id ) {
			if ( is_email( $id ) ) {
				$this->add_email( $id );
			} elseif ( is_numeric( $id ) ) {
				$user_ids[] = (int) $id;
			}
		}

		$ids_str = esc_sql( sanitize_comma_delimited( $user_ids ) );

		if ( empty( $ids_str ) ) {
			return;
		}

		$emails = $wpdb->get_col( "SELECT user_email FROM {$wpdb->users} WHERE ID IN ({$ids_str})" ); // phpcs:ignore WordPress.DB

		foreach ( $emails as $email ) {
			$this->add_email( $email );
		}
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment