WordPress 3.5 attachment_fields_to_edit and media_send_to_editor

So, there are some things which work differently (now). I. What you’ve noticed, when you click the checkbox WordPress sends an Ajax request to ‘wp_ajax_save_attachment_compat()’ with some form data, if your checkbox is checked, this information will be part of the form data. ‘wp_ajax_save_attachment_compat()’ checks for $_REQUEST[‘attachments’] and $_REQUEST[‘attachments’][$id] and will fail if it does … Read more

print_media_templates not applied in media manager plugin

Ok I’ve figured some things out by now: I was not returning the rendered image into anything In the javascript I have a render function media.view.AttachmentsBrowser = media.view.AttachmentsBrowser.extend({ render: function(){ var that = this; if(this.collection){ if(this.collection.models.length > 0){ this.clearImages(); _.each(this.collection.models, function (item){ //old way: that.renderImage(item); //now: this.$el.find(‘#lastli’).before(that.renderImage(item)); }, this); } } } }); Obviously my … Read more

How to display .ico files in the media library

Update: It looks like this will be supported in 5.0+. See ticket #43458 The default This is how the favicon (.ico) files show up in the Media Grid view: This is the corresponding part of the micro template: <# } else if ( ‘image’ === data.type && data.sizes ) { #> <div class=”centered”> <img src=”https://wordpress.stackexchange.com/questions/177981/{{ … Read more

How to add subfolders in media library for better organisation?

I too use have been using the Custom Upload Dir plugin that @sr83 mentioned to organise images and other upload files. It’s a useful solution, although not as flexible as I would like. It does provide a really great range of placeholders to build the folder path dynamically – including %file_ext%, %post_id%, %author%, %postname%, %post_type%, … Read more

How do I select an image from Media Library in my plugin?

You should use wp.media to use the WordPress Media Manager dialog. First, you need to enqueue the scritps: // As you are dealing with plugin settings, // I assume you are in admin side add_action( ‘admin_enqueue_scripts’, ‘load_wp_media_files’ ); function load_wp_media_files( $page ) { // change to the $page where you want to enqueue the script … Read more

Get All Images in Media Gallery?

$query_images_args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => – 1, ); $query_images = new WP_Query( $query_images_args ); $images = array(); foreach ( $query_images->posts as $image ) { $images[] = wp_get_attachment_url( $image->ID ); } All the images url are now in $images;

Change the default-view of Media Library in 3.5?

There were two minor mistakes in my previous answer: I forgot to trigger the change event for the parent. I called the function on every AJAX call, making other selections impossible. Here is the fixed code: <?php /** * Plugin Name: Pre-select post specific attachments */ add_action( ‘admin_footer-post-new.php’, ‘wpse_76048_script’ ); add_action( ‘admin_footer-post.php’, ‘wpse_76048_script’ ); function … Read more