how to get URL of media uploaded to WordPress via media_handle_sideload()

To get the URL of the uploaded image/attachment, you can use wp_get_attachment_url() (which always returns the full-sized image URL) or wp_get_attachment_image_url() for image attachment: // This is how you should call uploadImageToMediaLibrary(); assign the value to $att_id. $att_id = uploadImageToMediaLibrary($post->ID, $external_url, “custom_alt”); $url = wp_get_attachment_image_url( $att_id, ‘full’ ); // full-sized URL But to set the … 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

how to retrieve uploaded url of zip files

To allow uploading files which are not in the ‘regular’ list of MIME’s you have to tell WordPress to add them to that list. As an example you find below code which adds those extensions to the already existing MIMES list. Please make a backup first /** * Source: @link https://developer.wordpress.org/reference/hooks/upload_mimes/ * */ add_filter( ‘upload_mimes’, … Read more