Download an image from a webpage to the default uploads folder

I recently had to do this via a nightly cron script for a social media stream. $parent_id is the ID of the post you want to attach the image to. function uploadRemoteImageAndAttach($image_url, $parent_id){ $image = $image_url; $get = wp_remote_get( $image ); $type = wp_remote_retrieve_header( $get, ‘content-type’ ); if (!$type) return false; $mirror = wp_upload_bits( basename( … Read more

Allowing WebP uploads?

It’s necessary to use the wp_check_filetype_and_ext filter to set the mime type and extension for webp files in addition to using the upload_mimes filter to add the mime type to the list of uploadable mimes. /** * Sets the extension and mime type for .webp files. * * @param array $wp_check_filetype_and_ext File data array containing … Read more

Import WordPress xml file larger than 8mb

OPTION 1: If a WordPress WXR file, an XML file exported from WordPress, is too large to import, there are several things you might try to overcome that limit. Increase the amount of memory a PHP script may consume. Note: If using a shared hosting service, you may need to ask your host to increase … Read more

how to upload and allow downloads of .mobi and .epub formats

Assuming that you are using the WordPress native Media uploader then you can use the upload_mimes filter hook to add or remove allowed file types, for example: function custom_myme_types($mime_types){ //Adding avi extension $mime_types[‘avi’] = ‘video/avi’; //Removing the pdf extension unset($mime_types[‘pdf’]); return $mime_types; } add_filter(‘upload_mimes’, ‘custom_myme_types’, 1, 1); You can see that to add a file … Read more

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