Replacing Images in Media Library

Well, I think the easiest way would be the following: Download your wp-content/uploads/ folder so you have all images on your hard disk Remove the images WordPress has automatically generated (the ones with -*x*.jpg, maybe read this if you have SSH access as a filename) Optimize your base images with Photoshop Reupload the images into … Read more

Find unused images?

Is there a reliable up-to-date way to find media that resides on the server but is not used in the WP site? In short: no, not as far as I’m aware. I have found a number of plugins, but all are very old, with lots of negative comments to the effect that they do not … Read more

List and show uploaded pdf files dynamically

Possibilities to fetch attachments WordPress saves files not only to a physical disk, but as well as attachment post type into your MySQL/MariaDB database. This means you have two possibilities to query for uploaded files and you have to chose what you need in which scenario/context. Filesystem only To loop through all files or a … Read more

WordPress HTTP Error on File upload

I faced the same problem with my WordPress site. It’s some bug in WordPress. Which version you are using? I resolved this error by adding a function to my functions.php file in my theme. function ms_image_editor_default_to_gd( $editors ) { $gd_editor=”WP_Image_Editor_GD”; $editors = array_diff( $editors, array( $gd_editor ) ); array_unshift( $editors, $gd_editor ); return $editors; } … Read more

Move a file from a directory to another

Can’t seem to track down the right filter to process this in just yet (where the edit form is being saved), especially since attachment_fields_to_edit can be used in multiple places. But maybe you already know? This will give you a good start anyway… add_filter(‘??attachment_fields_save_filter??’,’move_attachment_directory’,10,2); function move_attachment_directory($form_fields,$post) { $attach_id = $post->ID; if (!isset($_POST[‘attachments’][$attach_id][‘my_select’])) {return;} if ($_POST[‘attachments’][$attach_id][‘my_select’] … Read more

Get User’s Facebook Photos as WordPress Upload

You can use media_sideload_image() which will take a link to a file and upload it to the media library. You do need to pass it some kind of $post_id @Sumit points out in the comments you could pass NULL into the $post_id field. media_sideload_image( $file_url, $post_id, $image_desc, $return ); If you need the uploaded image … Read more

Upload Image in a WordPress page using PHP

Implementing your own upload form like this can be a major security vulnerability, you might want to instead use a library/script where such potential issues are already dealt with properly. Here is one I remember using successfully on a project for a similar purpose (user uploaded video)… though it may be more than what you … Read more

How to safely allow user upload on CPTs?

If I understood correctly the situation described in the question and its comments, the user has capabilities to upload files and to edit your post type, so you shouldn’t be fitering capabilities, the user already has the correct capabilities. The problem is that wp_editor() use the global $post by default, and in your context the … Read more

limit file type and file size using media_handle_upload

Use PHP // Check that the nonce is valid, and the user can edit this post. if (isset( $_POST[‘my_image_upload_nonce’] ) && wp_verify_nonce( $_POST[‘my_image_upload_nonce’], ‘my_image_upload’ ) ){ // Input type file name $image_input_name=”my_image_upload”; // Allowed image types $allowed_image_types = array(‘image/jpeg’,’image/png’); // Maximum size in bytes $max_image_size = 1000 * 1000; // 1 MB (approx) // Check … Read more