You can also add in a filter that can add the ID as a html5 data attribute to the returned HTML fragment from send_to_editor.
public function image_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt){
$dom = new DOMDocument();
@$dom->loadHTML($html);
$x = new DOMXPath($dom);
foreach($x->query("//img") as $node){
$node->setAttribute("data-id", $id);
}
if($dom->getElementsByTagName("a")->length == 0){
$newHtml = $dom->saveXML($dom->getElementsByTagName('img')->item(0));
}else{
$newHtml = $dom->saveXML($dom->getElementsByTagName('a')->item(0));
}
return $newHtml;
}
add_filter('image_send_to_editor', array(&$this,'image_to_editor'), 1, 8);
Then in your javascript handler for window.send_to_editor;
$('img',html).data('id'));
You can do the same thing for media uploads as well.
Related Posts:
- Reject upload of wrong-sized images using the Media Uploader
- Which filters or actions to use after a media upload and delete?
- Settings in ‘Media > Settings’ is ignored when inserting images
- There’s a way to scale media (images) at 50%?
- Force wordpress to see uploads folder media
- Site icons with alpha channel for self-hosted WordPress blog network
- Control resizing of uploaded images
- Set default “Link CSS Class” in add media admin editor
- Extend Media Library
- How to make “Upload files”selected by default in Insert Media?
- How to show all available images in WP’s media library when using the Polylang plugin?
- Saving Media – Which Hook is Fired?
- Set limit to media upload?
- WordPress 3.5: Switch back to Old Media Uploader?
- Insert images to post not working
- Using Images in WordPress – Best Practices
- wp_generate_attachment_metadata returns empty array
- Set a maximum upload count for users on a specific user role
- Password protect some uploaded files, so only logged-in users can view them
- using media uploader to select image of specific size, enforce cropper
- Trigger JS when featured image upload window is opened in admin
- Append button to WordPress Image Details modal
- add_image_size creating lots of images (of various sizes)
- Media uploader not work properly [closed]
- Add suffix to filename of uploaded images
- Retrieving JSON data in ajax request from media uploader
- How to disable WordPress Media resize different size version?
- Saving WordPress generated thumbnails in a subdirectory
- How to side load an image from a service
- How to host different file formats/types for a media attachment without creating multiple attachments?
- How to stop unlink images when remove a site or user
- How To install AWS SDK for PHP in wordpress?
- Add fields to the WordPress media uploader
- Change default from “Attachment post URL” to “File URL” in Add Media
- Insert Image automatically when upload finishes wordpress media uploader
- How do I modify the url of uploaded media content?
- Why would media_sideload_image() not work locally?
- Rotating image does not work for custom image sizes
- Handling image uploads without thickbox
- WordPress bug with capabilities?
- Display attachments by the ID of the post being edited in the wp.media frame (frontend)
- Media upload on WordPress changes title of image
- media_handle_upload() progress bar
- Enabling users to upload files
- move_uploaded_file() not working on wordpress front end
- ‘An error occurred in the upload. Please try again later.’ for users with different roles
- wrong media url in wordpress
- Ho to add “Create Slider” option to default “Add Media” popup?
- How to upload WordPress Images to remote web server and display those images in WordPress gallery [closed]
- Prevent small image sizes from being uploaded
- Protecting uploads not working
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- How to get the return value of wp.media({ frame: ‘post’ }) in all cases?
- Error uploading images (but the images are at the server!)
- Images uploaded to the media library has strange colors. However, in the edit screen the color is ok
- Blank upload.php page
- What is the way to add additional fields to attachments in 3.5+?
- Original image not saving?
- WordPress automatically adds links to uploaded images
- Create featured image from a remote url when creating a post
- tb_show not showing a media upload window . custom plugin
- Image resizing – TimThumb vs convert on upload?
- File names are being overridden when uploading new media
- In the media Rest API, what is “missing_image_sizes”?
- Error: The uploaded file exceeds the upload_max_filesize directive in php.ini [duplicate]
- Stop image resizing in particular case – is that possible?
- Issue with images which have no sizes available
- Migrating media files (documents only) to a fresh install and maintaining the same directory structure
- WordPress media upload issue could not insert attachment into the database
- Thumbnail images missing in WP media library
- Resize uploaded original images to a minimum automatically
- Get featured image with custom size outside WordPress
- WordPress creating images if uploaded image is greater than 960px on one side?
- wp_enqueue_media() and upload_mimes problem
- Reattach media after moving to another server
- Better solution for managing media attachments with `wp_editor()`?
- Convert all uploaded PNG files to PNG-8 format
- What if I have a large file on the server that I want the wp library to have?
- Bug: Deleting file, then uploading same file again places file in an old month folder
- Profile image does not upload
- Do custom post type (CPT) attachments/media store the parent post ID?
- Create multiple folders in upload media folder
- unable to write to the database while uploading images
- Upload error on localhost (at minimum, not yet tested online)
- How to change Route respond To A specific Path?
- WordPress media has all disappeared on wp-admin but still on the server
- unsharp thumbnails after uploading image
- Media Library: Remove replace images of selected author
- How to upload multiple images using WP rest API to media?
- Moving wp-content folder to public_html
- How use custom upload directories in filesystem and url based on media type or category
- get users nickname uploaded media
- Force relative path in media library for LAN deployment
- Set featured link not showing
- wordpress 3.6 media manager cropping timestamp
- Broken Media Library
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- Can’t upload files 1MB+ [closed]
- Is it possible to restrict the number of media uploads (photos) per user?
- How To Convert External Image URLs To Own Website’s Uploaded Images Automatically?