wpcf7_post_related_smt()CF7 1.0

Returns output string of a special mail-tag.

Хуков нет.

Возвращает

Строку. Output of the given special mail-tag.

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

wpcf7_post_related_smt( $output, $name, $html, $mail_tag );
$output(строка) (обязательный)
The string to be output.
$name(строка) (обязательный)
The tag name of the special mail-tag.
$html(true|false) (обязательный)
Whether the mail-tag is used in an HTML content.
$mail_tag(WPCF7_MailTag)
An object representation of the mail-tag.
По умолчанию: null

Код wpcf7_post_related_smt() CF7 5.9.3

function wpcf7_post_related_smt( $output, $name, $html, $mail_tag = null ) {
	if ( ! $mail_tag instanceof WPCF7_MailTag ) {
		wpcf7_doing_it_wrong(
			sprintf( '%s()', __FUNCTION__ ),
			__( 'The fourth parameter ($mail_tag) must be an instance of the WPCF7_MailTag class.', 'contact-form-7' ),
			'5.2.2'
		);
	}

	if ( ! str_starts_with( $name, '_post_' ) ) {
		return $output;
	}

	$submission = WPCF7_Submission::get_instance();

	if ( ! $submission ) {
		return $output;
	}

	$post_id = (int) $submission->get_meta( 'container_post_id' );

	if ( ! $post_id or ! $post = get_post( $post_id ) ) {
		return '';
	}

	if ( '_post_id' === $name ) {
		return (string) $post->ID;
	}

	if ( '_post_name' === $name ) {
		return $post->post_name;
	}

	if ( '_post_title' === $name ) {
		return $html ? esc_html( $post->post_title ) : $post->post_title;
	}

	if ( '_post_url' === $name ) {
		return get_permalink( $post->ID );
	}

	$user = new WP_User( $post->post_author );

	if ( '_post_author' === $name ) {
		return $user->display_name;
	}

	if ( '_post_author_email' === $name ) {
		return $user->user_email;
	}

	return $output;
}