Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] oEmbed in BP Profile


  • Myg0t
    Participant

    @myg0t

    Hi there guys. I posted about this a few months ago, but the topic was closed, so i’ll have to create a new one.

    I had gotten quite a few helpful responses but wasn’t able to get it working. Decided to take another look at it and i’ve gotten it sort-of working…

    So…

    In my plugins/bp-custom.php i’ve got the line

    add_filter('bp_get_the_profile_field_value','wp_oembed_get');

    this works, but only partially. It allows the video to be embeded into the Spotlight field; but at the same time strips away all the text from the other fields. So it seems that the filter is attempted to embed all the fields.

    As a remedy, i’m working with this code that was suggested to me:

    function bp_youtube_in_profile(){
    add_filter('bp_get_the_profile_field_value','bp_enable_youtube_in_profile',9,3);
    }
    add_action('bp_init','bp_youtube_in_profile',0);
    
    function bp_enable_youtube_in_profile($val,$type,$key){
    $field = new BP_XProfile_Field($key);
    $field_name = $field->name;
    $val = strip_tags($val);
    if(strtolower($field_name) == 'Spotlight'){
    return wp_oembed_get($val,array('width'=>300));
    }
    return $val;
    }

    but this particular bit of code doesn’t want to work. Does the code look right to you guys?

    Can someone explain to me how $val,$type, and $key in function bp_enable_youtube_in_profile($val,$type,$key) comes from?

    Thanks for all of yall’s support!
    M

Viewing 6 replies - 1 through 6 (of 6 total)

  • Henry Wright
    Moderator

    @henrywright

    Hi @myg0t

    In bp-xprofile/bp-xprofile-template.php at around line 500, you’ll see:

    apply_filters( 'bp_get_the_profile_field_value', $field->data->value, $field->type, $field->id );

    The $val, $type and $key args in your function correspond to $field->data->value, $field->type, $field->id


    danbp
    Participant

    @danbp

    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.


    Myg0t
    Participant

    @myg0t

    @henrywright Oh! I see! Thank you for that!


    @danbp
    Holy cow! Thank you so much for this! Your a genius. You really just made my day. I appreciate you taking the time to write so much about it. It makes it much easier to learn from my mistakes!

    Thanks again guys!
    M

    *EDIT* I just thought about this, but is there a way to tell whether the video ID in the field is from youtube or some other video service such as Vimeo?

    I’m noticing after looking at a few Vimeo videos that there IDs seem to be all numbers. Would be a reliable way to distinguish youtube from vimeo?


    danbp
    Participant

    @danbp

    1) yes, you have allready the code to fetch the youtube field. Just echo a text into the if( $bp_this_field_name == ‘Spotlight’ )

    2) How would you be sure that a user enter the right code into the field ?
    You have to create a separate field for each provider.
    Vimeo is using <iframe src="//player.vimeo.com/video/and a doc ID like 17054419


    Myg0t
    Participant

    @myg0t

    Ah! Very nice!

    Many many thanks!
    M


    danbp
    Participant

    @danbp

    You’re welcome !

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] oEmbed in BP Profile’ is closed to new replies.
Skip to toolbar