Customizer: Unique identifier that distinguishes which image upload control is uploading an image

Thanks to the tipoff from @birgire in the comment, I was able to locate two things, an example of an implementation that includes context, here (also of note is that the Github gist has code for the very useful ability to access any image uploaded from this context previously! https://gist.github.com/eduardozulian/4739075 /** * Example of inserting … Read more

Front-end Ajax File Upload

I use this code to upload if ( ! function_exists( ‘wp_handle_upload’ ) ) { require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); } if($_FILES[‘file’][‘name’] != ”) { $uploadedfile = $_FILES[‘file’]; $upload_overrides = array( ‘test_form’ => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if ( $movefile && ! isset( $movefile[‘error’] ) ) { $file_url = $movefile[‘url’]; $file_url = … Read more

Why would media_sideload_image() not work locally?

Ah, this is silly, but it turns out there was a very obvious reason why media_sideload_image() wasn’t working. My wp-content folder had the wrong the permissions from when I transferred it to my local environment and I wasn’t able to upload anything. Changed the permissions and it’s working fine.

All Images on wordpress site broken

It’s due to AAM (Advanced Access Manager) plugin. You have different options to fix the issue. 1) Disable AAM Media Manager plugin 2) You can changes AAM Media Manager plugin version 3) If you do not want AAM to handle your website images, Go to the following file /advanced-access-manager/extension/AAM_Media_Manager/extension.php and find private $_skip = false; … Read more

WooCommerce Images are uploading to the server but not attaching

I think that you have made a mistake in the last line. array_push is not doing what you are trying to achieve (check the Manual) same as update_post_meta accepts different arguments. Besides that WooCommerce is storing galleries in simple comma separated list like 1,45,78,34 so you should change the last line update_post_meta($post_id, array_push($post_id, ‘_product_image_gallery’, $id)); … Read more

Filter / Hook to get attachment ID before uploading?

You just complicating yourself here. If you want a sequential ID just store it in an option and increment its value with each new upload. There is a very slight possibility of a race condition which might result with two images having the names of IMG_N.png and IMG_N-2.png but it is not likely to happen … Read more

How to set post_id to 0 when you upload image via Add media button. (async-upload.php)

Finally found an answer for this and checked it worked on my situation. How to upload image without post ID using the new media uploader? // Set post_id to 0 when Add Media button clicked jQuery(‘#insert-media-button’).on(‘click’, function( event ){ event.preventDefault(); wp.media.model.settings.post.id = 0; }); This will set all the images uploaded via Add media button … Read more