The $file
array doesn’t have anything that you’d be able to use, but $GLOBALS
has some helpful information. You can uncomment the debugging line that contains $GLOBALS
to see what it contains.
I have added a guard clause to the top of the tc_handle_upload_prefilter
function. This ensures that the file size checking code is only run when the job_logo
file is being uploaded.
add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter');
function tc_handle_upload_prefilter($file) {
// Debugging...
//return array("error"=> print_r( $_POST, true ) );
//return array("error"=> print_r( $file, true ) );
//return array("error"=> print_r( $GLOBALS, true ) ); // This is helpful...
//return array( "error"=> print_r( $GLOBALS['job_manager_uploading_file'], true ) ); // Now we're cooking!
if ( ! isset( $GLOBALS['job_manager_uploading_file'] ) || ( 'job_logo' !== $GLOBALS['job_manager_uploading_file'] ) ) {
return $file;
}
$img = getimagesize( $file['tmp_name'] );
$minimum = array( 'width' => '640', 'height' => '480' );
$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 < $minimum['height'] )
return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
else
return $file;
}