rtMedia Pro - uploader.php adding custom data field


#1

hi !

I’ve added custom field to my medias. Added it to view in the “facebook style” popup. All is working very well.

But now i’m facing a problem : I dont know how to added this field to the upload part.

Here are the code i’ve used in my function.php :

// PRIX
function custom_rtmedia_prix_build($type) {
    if ( $type == 'photo' ) {
        global $rtmedia_media;
        $id = $rtmedia_media->id;
        $prix = get_rtmedia_meta($id,'prix');
        echo '<br /><label for="prix">Prix</label>  ';
        echo '<input class="prix" id="prix" type="text" name="prix" value="'.$prix.'" />';
    }
}
add_action('rtmedia_add_edit_fields', 'custom_rtmedia_prix_build');

function custom_save_rtmedia_prix_build($id, $state) {
    $type = rtmedia_type($id);
    if ( $type == 'photo' ) {
        $prix = get_rtmedia_meta($id,'prix');
        if ( $prix != $_POST['prix'])
        update_rtmedia_meta($id,'prix',$_POST['prix']);
    }
}
add_action('rtmedia_after_update_media', 'custom_save_rtmedia_prix_build', 10,2);

And in media-single.php :

global $rtmedia_media;
$id = $rtmedia_media->id;
$marque = get_rtmedia_meta($id,'marque');

I guess i need to modify uploader.php. But i dont know where to start and if there is any hook to do this.

Does anyone know how to achieve this ?

Ty !


#2

Hi @nicolajean75,

Yes, there is a filter available for that.

You can use this hook -> https://github.com/rtCamp/rtMedia/blob/master/app/main/controllers/upload/RTMediaUploadView.php#L82 for custom field in uploader.


#3

Hi thank you,

I got some something up adding this ton function.php :smile:

function custom_upload_data() {
        global $rtmedia_media;
	echo '<div style="clear:both;width:100%;">';
        echo 'Prix : <input class="prix" id="prix" type="text" name="prix" value="" />  ';
	/*echo 'Marque : <input class="marque" id="marque" type="text" name="marque" value="" />  ';
	echo 'Taille : <input class="taille" id="taille" type="text" name="taille" value="" />  ';
	echo 'Liens : <input class="lien" id="lien" type="text" name="lien" value="" />  '; */
	echo '</div>';
}
add_action('rtmedia_uploader_before_start_upload_button', 'custom_upload_data', 10,2);

field are up, but i cant save them. I’ve done this, but its not working . any idea on how to do this ?

function custom_save_after_upload($id, $state) {
    $type = rtmedia_type($id);
    if ( $type == 'photo' ) {
        $prix = get_rtmedia_meta($id,'prix');
	/*$marque= get_rtmedia_meta($id,'marque');
	$taille = get_rtmedia_meta($id,'taille');
	$lien = get_rtmedia_meta($id,'lien'); */
        if ( $prix != $_POST['prix'])
        update_rtmedia_meta($id,'prix',$_POST['prix']);
	/*if ( $marque != $_POST['marque'])
        update_rtmedia_meta($id,'marque',$_POST['marque']);
	if ( $taille != $_POST['taille'])
        update_rtmedia_meta($id,'taille',$_POST['taille']);
        if ( $lien != $_POST['lien'])
        update_rtmedia_meta($id,'lien',$_POST['lien']); */
    }

}

add_action('rtmedia_uploader_after_start_upload_button', 'custom_save_after_upload', 10,2);

Thanks !! Nicola


#4

Hi @nicolajean75,

To save Custom field you need to handle AJAX hook request and attach value to each media. For Example below is the sample code you need to add :

// Add custom field after file upload
    rtMediaHook.register(
        'rtmedia_js_after_file_upload',
        function ( args ) {
               // your custm ajax call code goes here which you will need to handle in php 
        }
    );

#5

Hi !

Thank you a lot for your reply.

Can you be more specific about the “ajax call”? have you some exemple in the code to guide me.

And, where do i put this lines of code ?

Thank you for your support.


#6

Hi @nicolajean75,

In this Ajax hook request, you need to bind those extra fields with media and to do that you have to send those fields after media upload hook via ajax call.

You can put that code in your theme’s js file.

Thank you.


#8