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

How to add new tab to media upload manager with custom set of images?

This is an old thread but for me still as still as relevant. I have been fiddling and has come up with this code for adding a media tab here, maybe someone want to continue for how the handle content for the tab? šŸ™‚ add_action(‘admin_enqueue_scripts’, function(){ wp_enqueue_script( ‘my-media-tab’, plugin_dir_url( __FILE__ ) . ‘/js/mytab.js’, array( ‘jquery’ … Read more

How to Fix HTTP Error When Uploading Images?

I put the following code into my functions.php file. It works! add_filter( ‘wp_image_editors’, ‘change_graphic_lib’ ); function change_graphic_lib($array) { return array( ‘WP_Image_Editor_GD’, ‘WP_Image_Editor_Imagick’ ); } When this helps it is because it changes the PHP code module used for processing the uploaded image for use with WordPress. This processing includes moving the image into the media … Read more

Pre populate WordPress wp_media modal with image selection

Here is the script: Iā€™m using the function loadImages in following script to load the existing attached images via AJAX and then just pass the function with the IDs of images and it opens up a pre-populated modal. var frame, selection = loadImages(images); $(‘#stag_images_upload’).on(‘click’, function(e) { e.preventDefault(); var options = { title: ‘<?php _e(“Create Featured … Read more

Restricting users to view only media library items they have uploaded?

You could always filter the media list using a pre_get_posts filter that first determines the page, and the capabilities of the user, and sets the author parameter when certain conditions are met.. Example add_action(‘pre_get_posts’,’users_own_attachments’); function users_own_attachments( $wp_query_obj ) { global $current_user, $pagenow; $is_attachment_request = ($wp_query_obj->get(‘post_type’)==’attachment’); if( !$is_attachment_request ) return; if( !is_a( $current_user, ‘WP_User’) ) return; … Read more

How to Protect Uploads, if User is not Logged In?

Only checking if the cookie exists, is not much of a strict protection. To get a stronger protection, you can pass or “proxy” all requests to the uploaded folder (exemplary uploads in the following example) through a php script: RewriteCond %{REQUEST_FILENAME} -s RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L] All requests to uploaded files (which includes images in … Read more