Modify the array of selected images in media modal

I’m able to do the following in media modal: var selection = wp.media.frame.state().get(‘selection’); // get selected collection attachment = wp.media.attachment(id); // get attachment with id attachment.fetch(); selection.add(attachment); // add attachment to selection collection There should be .remove() method or something similar.

Ignore a filter on the media library

You can use is_admin() in conjunction with the admin global variable $pagenow to make sure you’re not on either the upload or media page: function remove_images( $where ) { global $wpdb, $pagenow; if( is_admin() && in_array( $pagenow, array( ‘upload.php’, ‘media-upload.php’ ) ) { return $where } $where .= ” AND {$wpdb->posts}.post_mime_type NOT LIKE ‘image/%'”; return … Read more

Video embeds work in backend, but are not parsed in frontend

I’ve just looked at the source of the WP_Embed class, and it appears they are not actually registering a shortcode, but hooking into the the_content filter. Change your code to $content_desktop = apply_filters(“the_content”, get_the_content()); or manually trigger their filter with something like $content_desktop = WP_Embed::run_shortcode(get_the_content()); or, if you prefer to have an object: $myembeds = … Read more

How to add a category or tag to media at upload time with the browser uploader?

I’ve been using Media Tags plugin with much success – it was very useful for retrieving images belonging to certain page with specific tags with following code: $results = get_attachments_by_media_tags(array(“media_tags”=>”gallery”, “post_parent” => $global_id, “order” => “ASC”)); Of course you can easily tag anything that sits in your media library (I wasn’t even aware that you … Read more

Disable slow media queries?

Solution for WordPress versions >= 4.7.4 (4.8) Ticket #31071 introduces patches with new filters to override three possible slow media queries, in the wp_enqueue_media() function: media_library_show_audio_playlist (@param bool|null) From the inline doc: Whether to show the button, or null to decide based on whether any audio files exist in the media library. media_library_show_video_playlist (@param bool|null) … Read more

Switch to the library tab in the media uploader

After struggling around for days through the poorly documented media modal source code and using code from the gist (thanks, Fabien), I came up with a solution: JS: wp.media.controller.Custom = wp.media.controller.State.extend({ initialize: function(){ this.props = new Backbone.Model({ custom_data: ” }); this.props.on( ‘change:custom_data’, this.refresh, this ); }, refresh: function() { this.frame.toolbar.get().refresh(); }, // called when the … Read more

How to reduce original image quality on upload?

In general I wouldn’t recommend modifying the original uploaded image files, just in case we might need to re-generate intermediate sizes. But let’s see if it’s possible 🙂 We can in general let WordPress choose the image editor, that depends on modules like GD or Imagick, through: $editor = wp_get_image_editor( $file ); but this can … Read more

Append button to WordPress Image Details modal

Here’s an alternative technique to manipulating the template. I adapted the solution below from this post. In the approach below, the print_media_templates hook, which is triggered at the bottom of wp-includes/media-template.php, is used to output some JavaScript that removes the default image details underscores template (<script type=”text/html” id=”tmpl-image-details”>) and replaces it with a duplicated version … Read more