Filter media library items by size

So far, the only workable solution I’ve come up with is to run a new query within the ajax_query_attachments_args filter. It’s definitely not ideal but works as expected in the absence of a more efficient alternative: function restrict_media_library_by_width($query) { $include = array(); $exclude = array(); $temp_query = new WP_Query($query); if($temp_query->have_posts()) { while($temp_query->have_posts()) { $temp_query->the_post(); $meta … Read more

How to restrict images in v3.5 Media Library modal to only those from a specific post id?

I am not sure is this what you are looking for. This code will “lock” uploads to show only “Uploaded to this post” in media panel add_action( ‘admin_footer-post-new.php’, ‘firmasite_mediapanel_lock_uploaded’ ); add_action( ‘admin_footer-post.php’, ‘firmasite_mediapanel_lock_uploaded’ ); function firmasite_mediapanel_lock_uploaded() { ?> <script type=”text/javascript”> jQuery(document).on(“DOMNodeInserted”, function(){ // Lock uploads to “Uploaded to this post” jQuery(‘select.attachment-filters [value=”uploaded”]’).attr( ‘selected’, true ).parent().trigger(‘change’); … Read more

Customizing the 3.5 “Add Media” popup (Backbone.js)

I had do adapt Backbone for a project of mine, so I might help to get you started. If you want to adapt the rendering of your Backbone Templates, you need to rewrite them, because there are no built in filters for existing Templates. add_action(‘print_media_templates’, ‘print_my_media_templates’); function print_my_media_templates() { ?> <script type=”text/html” id=”my-custom-template”> //TODO: Copy … Read more

Bind event on Media gallery elements WordPress

(function ($) { “use strict”; $(function () { var button = $(‘.upload-image’); button.click(function (e) { e.preventDefault(); // If the media frame already exists, reopen it. if (file_frame) { file_frame.open(); return; } var btn = $(this), media = wp.media; // Create the media frame. var file_frame = media.frames.file_frame = media({ title: jQuery(this).data(‘uploader_title’), button: { text: jQuery(this).data(‘uploader_button_text’) … Read more

Best approach when modifying the Media Manager

This is my go to snippet for things like this. <?php add_action(‘print_media_templates’, function(){ // define your backbone template; // the “tmpl-” prefix is required, // and your input field should have a data-setting attribute // matching the shortcode name ?> <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> <label class=”setting”> <span><?php _e(‘My setting’); ?></span> <select data-setting=”my_custom_attr”> <option value=”foo”> Foo </option> … Read more

Rendering the uploaded file in a wp.media object

I presume you’ve fixed this already but (in a blatant attempt to snaffle the bounty and) as mentioned in the comments there’s a simple fix, in your myplugin_meta_box_callback() function change the line $mime_types = array( ‘application/pdf’ ); to $mime_types=”application/pdf”; The library.type option to wp.media expects a string (which can be comma-separated with additional types) not … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)