wpcf7_user_related_smt() │ CF7 1.0

Returns output string of a special mail-tag.

Хуков нет.

Возвращает

string. Output of the given special mail-tag.

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

wpcf7_user_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_user_related_smt() CF7 6.2.4.1

function wpcf7_user_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'
		);
	}

	$available_names = array(
		'_user_login',
		'_user_email',
		'_user_url',
		'_user_first_name',
		'_user_last_name',
		'_user_nickname',
		'_user_display_name',
	);

	if ( ! in_array( $name, $available_names, true ) ) {
		return $output;
	}

	$submission = WPCF7_Submission::get_instance();

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

	$user_id = (int) $submission->get_meta( 'current_user_id' );

	if ( ! $user_id ) {
		return '';
	}

	$user = new WP_User( $user_id );

	$prop_key = ltrim( $name, '_' );
	$primary_props = array( 'user_login', 'user_email', 'user_url' );

	if ( ! in_array( $prop_key, $primary_props, true ) ) {
		$prop_key = substr( $prop_key, 5 );
	}

	if ( $user->has_prop( $prop_key ) ) {
		return (string) $user->get( $prop_key );
	}

	return '';
}