BP Extended Profile Shortcode


/**
 * Xprofile data shortcode.
 */
add_shortcode( 'ewp-profile-data', function ( $atts = array(), $content = null ) {

	$atts = shortcode_atts(
		array(
			'context' => '', // logged, displayed, author
			'user_id' => 0,
			'field'   => '',
		),
		$atts
	);

	if ( empty( $atts['field'] ) ) {
		return '';
	}

	$user_id = 0;
	switch ( $atts['context'] ) {

		case 'displayed':
			$user_id = bp_displayed_user_id();
			break;
		case 'logged':
			$user_id = get_current_user_id();
			break;
		case 'author':
			$user_id = get_the_author_meta( 'ID' );
			break;
		default:
			if ( $atts['user_id'] ) {
				$user_id = $atts['user_id'];
			} elseif ( in_the_loop() ) {
				$user_id = get_the_author_meta( 'ID' );
			} elseif ( bp_is_user() ) {
				$user_id = bp_displayed_user_id();
			} elseif ( is_user_logged_in() ) {
				$user_id = get_current_user_id();
			}
	}

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

	return xprofile_get_field_data( $atts['field'], $user_id, 'comma' );

} );
Usecase:- [ewp-profile-data field="CustomField"]

Related Articles

Add IPN and Return Url to PayPal

Here’s how to enable Auto Return: Click Settings. Click Website payments under “Product & Services” on the left of the page. Click Update next to “Website preferences.” Click On under “Auto return.” In…