Inventory_Presser_Contact_Form_7::add_mail_tags( string $output, string $name, mixed $html, mixed $mail_tag = null )

Replaces mail tags with the data we promised.

On This Page


Parameters Parameters

$output

(string) (Required)

$name

(string) (Required)

$html

(mixed) (Required)

$mail_tag

(mixed) (Optional)

Default value: null


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/integrations/class-contact-form-7.php

		public function add_mail_tags( $output, $name, $html, $mail_tag = null ) {
			$name       = preg_replace( '/^wpcf7\./', '_', $name ); // for back-compat.
			$submission = WPCF7_Submission::get_instance();
			if ( ! $submission ) {
				return $output;
			}

			// [invp_adf_timestamp] handler
			if ( 'invp_adf_timestamp' === $name
				&& $timestamp = $submission->get_meta( 'timestamp' )
			) {
				return wp_date( 'c', $timestamp );
			}

			// [invp_adf_vehicle] handler
			if ( 'invp_adf_vehicle' === $name ) {
				if ( ! has_filter( 'wp_mail_content_type', array( $this, 'html_mail_content_type' ) ) ) {
					add_filter( 'wp_mail_content_type', array( $this, 'html_mail_content_type' ) );
				}

				// What name in posted_data is the vehicle field?
				$post_id = $this->get_submission_vehicle_post_id();
				if ( false === $post_id ) {
					return '';
				}

				return sprintf(
					'<vehicle>'
					. '<id>%s</id>'
					. '<year>%s</year>'
					. '<make>%s</make>'
					. '<model>%s</model>'
					. '<vin>%s</vin>'
					. '<stock>%s</stock>'
					. '</vehicle>',
					INVP::get_meta( 'car_id', $post_id ),
					invp_get_the_year( $post_id ),
					invp_get_the_make( $post_id ),
					invp_get_the_model( $post_id ),
					invp_get_the_vin( $post_id ),
					invp_get_the_stock_number( $post_id )
				);
			}

			// [invp_adf_vendor] handler
			if ( 'invp_adf_vendor' === $name ) {
				if ( ! has_filter( 'wp_mail_content_type', array( $this, 'html_mail_content_type' ) ) ) {
					add_filter( 'wp_mail_content_type', array( $this, 'html_mail_content_type' ) );
				}
				// Contact Form 7 default mail tag equivalents.
				$_site_title = wp_specialchars_decode( get_bloginfo( 'name', true ), ENT_QUOTES );
				$_site_url   = get_bloginfo( 'url', true );

				// Get the vehicle.
				$post_id     = $this->get_submission_vehicle_post_id();
				$vendor_name = $_site_title;

				// Does the vehicle have a term in the locations taxonomy?
				$location_terms = get_the_terms( $post_id, 'location' );
				if ( ! empty( $location_terms ) ) {
					$vendor_name             = $location_terms[0]->name;
					$term_id                 = $location_terms[0]->term_id;
					$address_street          = get_term_meta( $term_id, 'address_street', true );
					$address_street_line_two = get_term_meta( $term_id, 'address_street_line_two', true );
					$address_city            = get_term_meta( $term_id, 'address_city', true );
					$address_state           = get_term_meta( $term_id, 'address_state', true );
					$address_zip             = get_term_meta( $term_id, 'address_zip', true );
					$phone                   = get_term_meta( $term_id, 'phone_1_number', true );

					return sprintf(
						'<vendor>'
							. '<vendorname>%1$s</vendorname>'
							. '<contact>'
								. '<name part="full" type="business">%1$s</name>'
								. '<phone type="voice">%2$s</phone>'
								. '<address>'
									. '<street line="1">%3$s</street>'
									. '<street line="2">%4$s</street>'
									. '<city>%5$s</city>'
									. '<regioncode>%6$s</regioncode>'
									. '<postalcode>%7$s</postalcode>'
									. '<url>%8$s</url>'
								. '</address>'
							. '</contact>'
							. '</vendor>',
						$vendor_name,
						$phone,
						$address_street,
						$address_street_line_two,
						$address_city,
						$address_state,
						$address_zip,
						$_site_url
					);
				} else {
					// This vehicle does not have a term in the location taxonomy.
					return sprintf(
						'<vendor>'
						. '<vendorname>%1$s</vendorname>'
						. '<contact>'
							. '<name part="full" type="business">%1$s</name>'
							. '<url>%2$s</url>'
						. '</contact>'
						. '</vendor>',
						$_site_title,
						$_site_url
					);
				}
			}
			return $output;
		}