rtmedia_after_add_media hook. How to get EXIF data?

Hi, I just found the rtmedia_after_add_media hook. But I can’t get any exif data out of the related $file_object.

How do I have to access this object to get the raw fileobject? $file_object[‘file’] or $file_object[0][‘file’] or totally different?

Thanks in advance.

Sebastian

Hi @Sebastian,

You will get filepath from $file_object by using this -> $file_object[0][‘file’].

For example,you can add following code in your theme’s functions.php file to get filepath from fileobject.

function get_file_path ( $media_ids, $file_object, $uploaded, $autoformat = true ) { 
                error_log ( var_export ( $file_object[ 0 ][ 'file' ], true ) ); 
} 
add_action (  'rtmedia_after_add_media', 'get_file_path' );

Hi, I’ve put your snippet in my functions.php. Unfortunatly the file object is null…

What went wrong?

Hi @Sebastian,

Sorry, try following code.

function get_file_path ( $media_ids, $file_object, $uploaded, $autoformat = true ) { 
                error_log ( var_export ( $file_object[ 0 ][ 'file' ], true ) ); 
} 
add_action (  'rtmedia_after_add_media', 'get_file_path', 10, 4 );

Thanks. Everything works fine now :slight_smile:

Hi @Sebastian,

I am glad to hear that your issue is fixed.