WPCF7_Mail::compose()privateCF7 1.0

Composes an email message and attempts to send it.

Метод класса: WPCF7_Mail{}

Хуки из метода

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->compose( $send );
$send(true|false)
Whether to attempt to send email.
По умолчанию: true

Код WPCF7_Mail::compose() CF7 5.9.3

private function compose( $send = true ) {
	$components = array(
		'subject' => $this->get( 'subject', true ),
		'sender' => $this->get( 'sender', true ),
		'body' => $this->get( 'body', true ),
		'recipient' => $this->get( 'recipient', true ),
		'additional_headers' => $this->get( 'additional_headers', true ),
		'attachments' => $this->attachments(),
	);

	$components = apply_filters( 'wpcf7_mail_components',
		$components, wpcf7_get_current_contact_form(), $this
	);

	if ( ! $send ) {
		return $components;
	}

	$subject = wpcf7_strip_newline( $components['subject'] );
	$sender = wpcf7_strip_newline( $components['sender'] );
	$recipient = wpcf7_strip_newline( $components['recipient'] );
	$body = $components['body'];
	$additional_headers = trim( $components['additional_headers'] );

	$headers = "From: $sender\n";

	if ( $this->use_html ) {
		$headers .= "Content-Type: text/html\n";
		$headers .= "X-WPCF7-Content-Type: text/html\n";
	} else {
		$headers .= "X-WPCF7-Content-Type: text/plain\n";
	}

	if ( $additional_headers ) {
		$headers .= $additional_headers . "\n";
	}

	$attachments = array_filter(
		(array) $components['attachments'],
		function ( $attachment ) {
			$path = path_join( WP_CONTENT_DIR, $attachment );

			if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) {
				if ( WP_DEBUG ) {
					trigger_error(
						sprintf(
							/* translators: %s: Attachment file path. */
							__( 'Failed to attach a file. %s is not in the allowed directory.', 'contact-form-7' ),
							$path
						),
						E_USER_NOTICE
					);
				}

				return false;
			}

			if ( ! is_readable( $path ) or ! is_file( $path ) ) {
				if ( WP_DEBUG ) {
					trigger_error(
						sprintf(
							/* translators: %s: Attachment file path. */
							__( 'Failed to attach a file. %s is not a readable file.', 'contact-form-7' ),
							$path
						),
						E_USER_NOTICE
					);
				}

				return false;
			}

			static $total_size = array();

			if ( ! isset( $total_size[$this->name] ) ) {
				$total_size[$this->name] = 0;
			}

			$file_size = (int) @filesize( $path );

			if ( 25 * MB_IN_BYTES < $total_size[$this->name] + $file_size ) {
				if ( WP_DEBUG ) {
					trigger_error(
						__( 'Failed to attach a file. The total file size exceeds the limit of 25 megabytes.', 'contact-form-7' ),
						E_USER_NOTICE
					);
				}

				return false;
			}

			$total_size[$this->name] += $file_size;

			return true;
		}
	);

	return wp_mail( $recipient, $subject, $body, $headers, $attachments );
}