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?