restrict uploaded image size and fixed image display size

Add this code to your theme’s functions.php file, and it will limit image dimentions add_filter(‘wp_handle_upload_prefilter’,’tc_handle_upload_prefilter’); function tc_handle_upload_prefilter($file) { $img=getimagesize($file[‘tmp_name’]); $minimum = array(‘width’ => ‘600’, ‘height’ => ‘900’); $width= $img[0]; $height =$img[1]; if ($width < $minimum[‘width’] ) return array(“error”=>”Image dimensions are too small. Minimum width is {$minimum[‘width’]}px. Uploaded image width is $width px”); elseif ($height < … Read more

Media Upload to custom database and Custom Directory

I suppose, you didn’t create table imageupload or can’t create folder if_images at your plugin folder. As a proposal I suggest you to use built-in WordPress functions and wordpress tables or create table on plugin activation. To create new table use function dbDelta. If you want to upload user files, use well-documented wp_handle_upload function. For … Read more

What folder to place Large Video files?

WordPress doesn’t process uploaded files directly from file system, it stores information about them as attachments in database. If you need to turn a directly uploaded file into an attachment the term for it would be a sideload. There are some API functions in WP to help with the task, starting with media_handle_sideload(). Also note … Read more

Import all media referenced in posts

Can I use get_attached_media() to get the images referenced on a page, even if they’re not formally attached? No, if they’re not attached they won’t be attached. I assume you’re talking about images in your posts that are offsite? If so, you need to download them, create an attachment post, attach it to the post, … Read more

Altered Media Library URLs

If you add this in the functions.php file in your themes folder: add_filter(‘upload_dir’, ‘new_upload_dir’); function new_upload_dir( $param ){ $mydir=”/wp-content/uploads”; $param[‘path’] = $param[‘path’] . $mydir; $param[‘url’] = $param[‘url’] . $mydir; error_log(“path={$param[‘path’]}”); error_log(“url={$param[‘url’]}”); error_log(“subdir={$param[‘subdir’]}”); error_log(“basedir={$param[‘basedir’]}”); error_log(“baseurl={$param[‘baseurl’]}”); error_log(“error={$param[‘error’]}”); return $param; } It should change the directory the images are uploaded into.