How to access media via global var or function?


#1

Hi,

I’m currently using my own front end posting plugin where on the back end a new wp post is created and the uploaded file becomes the featured image. I would like to also add it to the user’s rtMedia media gallery.

Do you have a codex or API doc file that shows how to access user media via global variables or functions?

Please observe the following code:

if ($filename) {  
  $attachment = array(  
	 'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),   
	 'post_mime_type' => $wp_filetype['type'],  
	 'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),  
	 'post_content' => '',  
	 'post_status' => 'inherit'  
  );  
  $attach_id = wp_insert_attachment( $attachment, $filename, $new_post_id  );  
  require_once(ABSPATH . 'wp-admin/includes/image.php');  
  $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );  
  wp_update_attachment_metadata( $attach_id, $attach_data );  
  set_post_thumbnail($new_post_id,$attach_id);  
}  

How could I also add this to their media gallery?


#2

@matt-mcfarland, to view media in gallery, there must be an entry of the same in index table of rtMedia in database.

You have to make some tweaks in your code to create an entry in index table.

You can check this file /app/main/controllers/media/RTMediaMedia.php and then check for the function insertmedia() to manually create an entry in rtMedia tables.


#3

#4