Rich Text Gravity Forms Field with Media Upload and Oembed

Gravity Forms lets you turn on the media library button for the rich text editor fields but you have to do it via php. More stuff on your editor options is here.

If you leave things that way, it’s nice but if you cut/paste a YouTube URL it comes in as a link rather than auto-embedding. Given my main goal with a lot of these Gravity Form workflows is to make it super easy I wanted that option to work. To get that to happen I need to enqueue some of the editor scripts on the frontend where the editor lives.

This little plugin will take care of both things.


//turn on media library
function show_media_button( $editor_settings, $field_object, $form, $entry ) {
    $editor_settings['media_buttons'] = true;
    $editor_settings['wpautop']       = true;
    return $editor_settings;
}
add_filter( 'gform_rich_text_editor_options', 'show_media_button', 10, 4 );

//loads script to do the oembed stuff
function alt_lab_front_end_scripts(){
	wp_enqueue_editor();		
	wp_enqueue_script( 'mce-view', '', array('tiny_mce') );	
}
add_action( 'wp_enqueue_scripts', 'alt_lab_front_end_scripts' );

You can see a quick explanation of where this comes into play in the video below. You’ll also get the chance to see one example of how I give faculty quick tours of sites and hear my mellifluousWhile I struggle to say that word, I do enjoy writing it. voice.

Comments on this post

  1. Cog.Dog said on September 20, 2019 at 4:06 pm

    It probably does not matter since your students are apparently logged in, but I’ve been flailing to figure out out to get the embeds to work in a front end editor when not logged in (it is I believe lack of access to admin_ajax.php)

    Tossed my question to StackExchange

    https://wordpress.stackexchange.com/questions/348566/how-to-set-up-front-end-editor-to-autoembed-media-for-non-logged-in-users

    (PS your video is not embedded)

    (PPS very very mellifluoussy)

    • Tom Woodward said on September 20, 2019 at 5:39 pm

      Bah. You’re right. I’ve got to re-look at it.

Leave a Reply to Cog.Dog Cancel reply

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL