Add Caption Field to rtMedia Edit Page

I would like to be able to edit the media's caption from the rtmedia edit page, like you can edit the description field.

Similar to this: but with just the caption field that already exists, not a custom field.

Thank you!

@fromtheheartstamps - You would need to following two actions to achieve what you want

WordPress stores the caption of an image in the post_excerpt field. You could use wp_update_post to update the excerpt field using the rtmedia_after_update_media action

Thank you for your quick response...I will do some reading to see if I can figure out how to use these actions. I'm learning as I go and not a developer. If anyone knows how to put this together into something I can copy and paste into my theme's function, that would be great! Otherwise, I will keep reading and try to figure it out.

Thank you!

I tried customizing the actions in the examples you linked to, inserting both actions into my theme's functions.php. And I got a server error. So then I thought I would try the actions as is (to add the camera build field), and I put both actions in my theme's function.php, and I got a server error again.

@fromtheheartstamps - That was since the functions given in both the examples had the same name. The docs have been updated. Please check once again.

That works! Thanks @joshuaabenazer! I was able to create the field that I needed on the edit page. :) However, I think using the rtmedia_after_update_media action to update the caption field and store it as the media caption is beyond my current understanding. Can you help? Thank you!

@fromtheheartstamps - Are you making use of the WordPress caption field in your theme or some other plugin? If not you should be better off storing it in the rtMedia meta using the above given examples by just changing "camera" to "caption".

Yes, the galleries and the posts use the caption field and I am able to have a link in the caption to the photo owner's blog.

I would like the caption field to work just like the description field. When I edit or add a description in the rtMedia edit page in BuddyPress, it is then updated when I open the media to edit in WordPress Media Library (shows the same description). It works in the reverse, too. If I update the media description from the WP Media Library, it updates the media as seen in the BuddyPress groups and albums. I would like the caption field to do the same. So I just want to have access to that caption field from where I upload in BuddyPress (rtMedia edit page) instead of having to open and edit the media in the default WP Media Library. Hope that makes sense. It seems like it has to be possible because that's how the description field works.

Thanks for your time and consideration!

Try the following code

function custom_rtmedia_caption($type) {  
    if ( $type == 'photo' ) {  
        global $rtmedia_media;  
        $media_id = $rtmedia_media->media_id;  
        $caption = get_post_field( 'post_excerpt', $media_id );  
        echo '

Caption '; echo ''.esc_textarea($caption).'

'; } } add_action('rtmedia_add_edit_fields', 'custom_rtmedia_caption'); function custom_save_rtmedia_caption($id, $state) { $type = rtmedia_type($id); $media_id = rtmedia_media_id($id); if ( $type == 'photo' ) { $caption = get_post_field( 'post_excerpt', $media_id ); if ( $caption != $_POST['rtmedia_caption']) wp_update_post(array('ID'=>$media_id,'post_excerpt'=>$_POST['rtmedia_caption'])); } } add_action('rtmedia_after_update_media', 'custom_save_rtmedia_caption', 10,2);

Thanks @joshuaabenazer! The caption is now visible in the rtMedia edit page in BuddyPress, but it is read only and shows up as text. I am not able to edit it.

It is showing the caption for the image that was added in the WP Media Library>Edit Media. But when I update something like the title of the image in the rtMedia edit page in BuddyPress, the caption is removed. I am guessing because there is not a field for input, so it thinks it is blank and then overwrites the caption that was there. ??

Is there a way to change it so that it can be edited? Thank you, again, for your time!

Edited to update: It works perfectly!!! I had copied the code that was in the email sent from this thread, and it did not quite work, but the code that is here now (above) works perfectly! Including linking, saving, displaying properly. Everything! Thank you so much!! This is a great feature to have the caption field!

@fromtheheartstamps - Glad to know it works for you :)