Restrict Access to wp-content/uploads when User is not Logged In

require_once(‘wp-load.php’); is_user_logged_in() || auth_redirect(); list($basedir) = array_values(array_intersect_key(wp_upload_dir(), array(‘basedir’ => 1)))+array(NULL); $file = rtrim($basedir,’/’).’/’.str_replace(‘..

Source