wp.media.view.ImageDetails – Save settings as HTML5 data-* attributes for image

A way to do it is to use the (very convenient) editor:image-edit and editor:image-update events triggered by the tinymce wpeditimage plugin to get/set the dom directly (updated to wrap in wp_enqueue_media action): add_action( ‘wp_enqueue_media’, function () { add_action( ‘admin_footer’, function () { ?> <script type=”text/javascript”> jQuery(function ($) { if (wp && wp.media && wp.media.events) { … Read more

Resizing images to the actual size used in the editor?

I created two plugins that together should solve my needs. They are currently in an early alpha stage, and all comments are welcome. The base plugin is an On-Demand Resizer. This plugins monitors requests for non-existing files in the uploads dir, and creates images of the requested size if needed. For example, image-200×100.jpg will create … Read more

How can I make add_image_size() crop from the top?

Intermediate image generation is extremely rigid. image_resize() keeps it close to code and completely lacks hooks. Pretty much only option for this is to hook into wp_generate_attachment_metadata and overwrite WP-generated image with your own (which will need bit of a image_resize() fork). I need this for work so I might be able to share some … Read more

Is it possible set a featured image with external image URL

Yes, it’s possible and pretty easy. This is the workflow I suggest: Put somewhere a UI to insert the URL of the featured image. Probably best choice is to use ‘admin_post_thumbnail_html’ filter hook Use ‘save_post’ action hook to save the URL (after security and validation routine) in a custom post meta Use ‘post_thumbnail_html’ filter hook … Read more

Programmatically adding images to media library

$image_url=”adress img”; $upload_dir = wp_upload_dir(); $image_data = file_get_contents( $image_url ); $filename = basename( $image_url ); if ( wp_mkdir_p( $upload_dir[‘path’] ) ) { $file = $upload_dir[‘path’] . “https://wordpress.stackexchange.com/” . $filename; } else { $file = $upload_dir[‘basedir’] . “https://wordpress.stackexchange.com/” . $filename; } file_put_contents( $file, $image_data ); $wp_filetype = wp_check_filetype( $filename, null ); $attachment = array( ‘post_mime_type’ => … Read more