WPCF7_Submission::add_extra_attachments()publicCF7 1.0

Adds extra email attachment files that are independent from form fields.

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

Хуков нет.

Возвращает

true|false. True if it succeeds to attach a file at least, or false otherwise.

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

$WPCF7_Submission = new WPCF7_Submission();
$WPCF7_Submission->add_extra_attachments( $file_path, $template );
$file_path(строка|массив) (обязательный)
A file path or an array of file paths.
$template(строка)
The name of the template to which the files are attached.
По умолчанию: 'mail'

Код WPCF7_Submission::add_extra_attachments() CF7 5.9.8

public function add_extra_attachments( $file_path, $template = 'mail' ) {
	if ( ! did_action( 'wpcf7_before_send_mail' ) ) {
		return false;
	}

	$extra_attachments = array();

	foreach ( (array) $file_path as $path ) {
		$path = path_join( WP_CONTENT_DIR, $path );

		if ( file_exists( $path ) ) {
			$extra_attachments[] = $path;
		}
	}

	if ( empty( $extra_attachments ) ) {
		return false;
	}

	if ( ! isset( $this->extra_attachments[$template] ) ) {
		$this->extra_attachments[$template] = array();
	}

	$this->extra_attachments[$template] = array_merge(
		$this->extra_attachments[$template],
		$extra_attachments
	);

	return true;
}