Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: [Resolved] oEmbed in BP Profile

@danbp

Participant

Hi @myg0t,

you do it wrong. WP auto embeds youtube videos automagically (and over 40 other online video providers). In a post or topic or mention, simply copy/paste the video URL, and it’s done.

xprofile use a form with different fields. Because these fields are striped for security reason (classic form security), you can’t embed videos like previously described.

But there is a URL field type ?
Yes, this let you enter a video url, but the field will render the URL, not the embed action. It’s a form field and it’s striped.

So what ?
We will use a normal text field, and will only enter an alpha numeric value.

How can i do this ?

As example, we gona use this video https://www.youtube.com/watch?v=TZPN9g2pmPQ

And to show the video on a profile, we’ll use only the doc ID: TZPN9g2pmPQ

By entering this kind of text in a profile field, it is not striped and will be handled like an ordinary text field and throwed to DB with his filed ID and field value.

To embed the video, we also have to add what WP does on a blog, but not on xprofile page, an iframe to control the video output, so it can be streamed correctly and be read by browsers.

Now we first create a new field and name it Spotlight (or what ever). No matter where, you can use the Base group or any other custom group.
We select the field type and give it a single text area type.
Save.

We go on a profile to modify it and enter TZPN9g2pmPQ in regard of Spotlight.
Save.

And voilĂ  ! The video is correctly embeded and displayed.

As usual for customisation, we’ll use a snippet which we put into bp-custom.php

function set_video_field( $field_value ) {
	$bp_this_field_name = bp_get_the_profile_field_name();
	// field name (case sensitive)
	if( $bp_this_field_name == 'Spotlight' ) {
		$field_value = strip_tags( $field_value );
        // building the HTML and h/w of the iframe
		$field_value = '<iframe width="420" height="315" src="http://www.youtube.com/embed/'.$field_value.'" frameborder="0" allowfullscreen></iframe>';
	}
	return $field_value;
}
add_filter( 'bp_get_the_profile_field_value','set_video_field');

Caution: do not remove the iframe, or video won’t work.

Hope this help.

Skip to toolbar