BP_Email::validate()

Check that we’d be able to send this email.


Description Description

Unlike most other methods in this class, this one is not chainable.


Top ↑

Return Return

(bool|WP_Error) Returns true if validation succesful, else a descriptive WP_Error.


Source Source

File: bp-core/classes/class-bp-email.php

	public function validate() {
		$retval = true;

		// BCC, CC, and token properties are optional.
		if (
			! $this->get_from() ||
			! $this->get_to() ||
			! $this->get_subject() ||
			! $this->get_content() ||
			! $this->get_template()
		) {
			$retval = new WP_Error( 'missing_parameter', __CLASS__, $this );
		}

		// Has the user opted out of receiving any email from this site?
		$recipient_to       = $this->get_to();
		$recipient_to_first = array_shift( $recipient_to );
		$recipient_address  = $recipient_to_first->get_address();
		if ( bp_user_has_opted_out( $recipient_address ) ) {
			$retval = new WP_Error( 'user_has_opted_out', __( 'The email recipient has opted out from receiving communication from this site.', 'buddypress' ), $recipient_address );
		}

		/**
		 * Filters whether the email passes basic validation checks.
		 *
		 * @since 2.5.0
		 *
		 * @param bool|WP_Error $retval Returns true if validation succesful, else a descriptive WP_Error.
		 * @param BP_Email $this Current instance of the email type class.
		 */
		return apply_filters( 'bp_email_validate', $retval, $this );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.