Hi,
For youtube this works:
add_filter( 'bxcft_show_field_value', 'my_show_field', 15, 4);
function my_show_field($value_to_return, $type, $id, $value) {
if ($type == 'web') {
$value = str_replace("<p>", "", $value);
$value = str_replace("</p>", "", $value);
$field = new BP_XProfile_Field($id);
if ($field->name == 'Link test youtube') {
$link_src = strip_tags(trim($value));
$link_src = str_replace('youtu.be/', 'youtube.com/embed/', $link_src);
return '<iframe width="560" height="315" src="'.$link_src.'" frameborder="0" allowfullscreen></iframe>';
}
}
return $value_to_return;
}
First, I check if the type of the field is the type I used. In my case I use website field.
if ($type == 'web') {
The next 3 lines are from my plugin:
$value = str_replace("<p>", "", $value);
$value = str_replace("</p>", "", $value);
$field = new BP_XProfile_Field($id);
Buddypress returns the value of your field surrounded by a paragraph <p> so I remove it to take the value of field only. The third line I create $field so I can now access the name of the field.
I check now if it’s the field with the name I want. In my case I call my field “Link test youtube”.
if ($field->name == 'Link prueba') {
When I edit my profile I use the share link of youtube: https://youtu.be/axQhG6-qNhA, so I need to transform this into: <iframe width=”560″ height=”315″ src=”https://www.youtube.com/embed/axQhG6-qNhA” frameborder=”0″ allowfullscreen></iframe>
First, I remove the tags my field has:
$link_src = strip_tags(trim($value));
The strip_tags remove the tag . This tag is added automatically by a filter in buddypress. The trim function remove any extra whitespace at the beginning or end of value. After applying this two functions in $link_src I have only the link https://youtu.be/axQhG6-qNhA. Now I need to transform this into the embed link.
$link_src = str_replace('youtu.be/', 'youtube.com/embed/', $link_src);
I replace youtu.be with youtube.com/embed/.
return '<iframe width="560" height="315" src="'.$link_src.'" frameborder="0" allowfullscreen></iframe>';
This line return the iframe.
The last line is necessary to display the other fields you don’t want to modify. With soundcloud you need to do something similar.