Home / Admin / Profile Data Shortcode
Duplicate Snippet

Embed Snippet on Your Site

Profile Data Shortcode

Renders the value of a single Profile Form field. Accepts one value, key. But it has to be the page that shows the vendor's store/downloads

Code Preview
php
<?php
	function fes_profile_data( $atts ) {
		$output = '';
		if ( empty( $atts['key'] ) ) {
			return $output;
		}
		$vendor     = false;
		$vendor_var = get_query_var( 'vendor' );
		if ( ! empty( $vendor_var ) ) {
			if ( is_numeric( $vendor_var ) ) {
				$vendor = get_vendor( absint( $vendor_var ) );
			} else {
				$vendor = get_user_by( 'slug', esc_attr( $vendor_var ) );
			}
		}
		if ( ! $vendor ) {
			return $output;
		}
		$user_data = get_userdata( $vendor->ID );
		if ( ! $user_data ) {
			return $output;
		}
		$output .= '<div id="' . esc_attr( $atts['key'] ) . '" class="vendor-profile-field">' . "\n";
		if ( 'description' === $atts['key'] ) {
			$output .= wpautop( get_user_meta( absint( $vendor->ID ), esc_attr( $atts['key'] ), true ) );
		} elseif ( 'user_avatar' === $atts['key'] ) {
			$output .= '<img src="' . esc_url( get_user_meta( absint( $vendor->ID ), esc_attr( $atts['key'] ), true ) ) . '" alt="Image of ' . esc_attr( $vendor->name ) . '">' . "\n";
		} elseif ( 'display_name' === $atts['key'] ) {
			$output .= $user_data->display_name;
		} else {
			$output .= get_user_meta( absint( $vendor->ID ), esc_attr( $atts['key'] ), true );
		}
		$output .= '</div>' . "\n";
		return $output;
	}
	add_shortcode( 'fes_profile_data', 'fes_profile_data' );
}

Comments

Add a Comment