[Resolved] Trying to use bp_profile_field_data() and oEmbed
-
I have a buddypress x_profile field named Video and I’d like to embed the URL (using the WP oEmbed functionality) into a post within the loop. I’m using bp_profile_field_data() and the user_id is the author of the post.
I’m successfully getting the video URL to show but it’s not embedded. Here’s what I have so far:
$current_author = get_the_author_meta('ID'); if ( $video_url = bp_profile_field_data(array('user_id'=>$current_author,'field'=>'Video' )) ); echo wp_oembed_get( $video_url );
I’m currently using the latest installs of WordPress (3.5.1) and Buddypress (1.7).
Any help/suggestions is greatly appreciated. I’ve been successful in using the same code when it comes to embedding custom fields but I’m not sure why this is only showing the URL.
-
hi @operapreneur,
try this, to put into /plugins/bp-custom.php
function bpfr_enable_video_on_profile( $val, $type, $key ) { $field = new BP_XProfile_Field( $key ); $field_name = $field->name; if( strtolower( $field_name ) == 'video' ) { // video is the field name on the profile (case sensitive) $val = strip_tags( $val ); return wp_oembed_get( $val, array('width'=>400) ); // video size; this fit correctly if you use bp-default } return $val;
He is saying to put it in a bp-custom.php file.
Don’t include the pre and code beginning and ending tags as they shouldn’t be there…
Thanks for the clarification @aces. I’m new to buddypress and an amateur when it comes to php.
I hadn’t heard of the bp-custom.php file before. I followed the steps mentioned on the page and I’m assuming there is something in the bp-core that checks for this file and contents.
@Chouf1 Unfortunately this function didn’t fix the problem – I’m still just getting only the URL and not the embedded video. Do I need to call this function or was my initial code going to work?I double checked video was all lowercase and I even tried it all by removing the wp_oembed_get from my code.
Any other suggestions?
Again, thanks.
Still looking for some guidance.
I’m not sure why an x_profile field is not treated exactly like meta data. It seems to me, this maybe specific to my project, that this would be very valuable. The Xprofile Custom Fields Type Plugin is very useful and is helping extend the functionality.
Alas, videos are still not embedding via bp_profile_field_data()
Any suggestions are welcome.
Sorry, I’m going to need a little more guidance. I have more than two fields that need to use the oEmbed. I assumed that the filter you created were for specific field IDs but that doesn’t seem to be the case at all. At this point only one of the fields is embedded the rest are just links.
Also, is this suppose to work with the bp_profile_field_data()? My main purpose on this support thread is to get the profile field to embed outside of the profile page. It’s awesome that it’s embedded in it now but it seems I’m missing something.
Thanks for your help! Looking forward to getting this figured out.
To use it elsewhere you would need to get the value of the field and pass it to wp_oembed_get. This is not tested:
$val = bp_member_profile_data('field=youtube'); // in members loop $val = xprofile_get_field_data( 'youtube' , $user_id ); // outside members loop $embed = wp_oembed_get( $val, array( 'width' => 400 ) ); echo $embed
In my previous example I have a provider array. These are the names of your profile fields not the actual service.
@modemlooper I let this issue sit for a while but now I’m back at it and having trouble.
The oembed works perfectly on the member’s profile page but when I try to use it else where it does not work.
I’ve tried what you had suggested above inside and outside the member loop. I’m cool with just trying to get it to work inside the member loop… I’m not sure why this should be so difficult.
The video link displays but does not embed. I’m using the same link that is successfully embedded in the profile. Here’s what I have:
<?php $video_url = bp_profile_field_data( 'field=22' ); $embed = wp_oembed_get( $video_url, array( ‘width’ => 400 ) ); echo $embed ?>
I’m using bp_profile_field_data instead of bp_member_profile_data because it is at least displaying the link.
Any other suggestions would be extremely appreciated, I feel like I’ve exhausted my options.
Sorry here’s the code again.
<?php $video_url = bp_profile_field_data( 'field=22' ); $embed = wp_oembed_get( $video_url, array( ‘width’ => 400 ) ); echo $embed ?>
I’ve finally had success getting videos to embed outside the member loop.
Modemlooper’s suggested code worked. I’m not sure what I was doing wrong before but this works:
$val = xprofile_get_field_data( ‘youtube’ , $user_id ); // outside members loop
$embed = wp_oembed_get( $val, array( ‘width’ => 400 ) );
echo $embed
Thank you!
I would like to have an advice about all of this…
I’m trying basically the same thing, with the same code. And something strange’s going on.
In the member-header.php file, I try to embed a video from a field “video”. Here is the code I’m using:
$embed = wp_oembed_get( bp_member_profile_data( ‘field=video’ ), array( ‘width’ => 400 ) );
echo $embedIt only shows the link ( the value of “video” field ), in plain text.
But when I put in the link, instead of the field value, it works. Like this:
$embed = wp_oembed_get( ‘http://www.youtube.com/watch?v=pZul0OH5qoE’, array( ‘width’ => 400 ) );
echo $embedThat embeds the video correctly.
–> Obviously, I can’t use that static code. It’s just for testing.
I really don’t understand why wp_oembed_get refuses to work when I’m passing a web link as a value, and works correctly when i’m passing a web link from a direct string.
Can someone help me on this ?
bp_get_member_profile_data
great…
- The topic ‘[Resolved] Trying to use bp_profile_field_data() and oEmbed’ is closed to new replies.