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.

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

Uploading images on front end doesn’t generate thumbnail sizes

wp_generate_attachment_metadata generates metadata for an image attachment. It also creates a thumbnail and other intermediate sizes of the image attachment based on the sizes defined on the Settings_Media_Screen. wp_generate_attachment_metadata() is located in wp-admin/includes/image.php. /* just require image.php before wp_generate_attachment_metadata */ require_once(ABSPATH . ‘wp-admin/includes/image.php’); $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); hope that helps!

Copying uploaded images not working in wordpress

Since i was also looking for some sort of keeping submitted images, i found this simple plugin, which gave me a bit insight: https://wordpress.org/plugins/store-file-uploads-for-contact-form-7/ Also if you read a bit on the mentioned “file-uploading-and-attachment” topic in cf7, you should get the point: For security reasons, specifying files outside of the wp-content directory for email attachments … Read more

How to use MediaUpload outside of editor

The answer is actually several steps that took me lots of experimentation, but it comes down to the following code that you need to compile using something like webpack and extract out the libraries, etc: // MediaUploadFilter.js import { MediaUpload } from ‘@wordpress/media-utils’ const { addFilter } = window.wp.hooks const replaceMediaUpload = () => MediaUpload … Read more

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