echo prevents PHP memory exhaustion. fpassthru( $file ); } /** * Renders the current attached file to the browser. */ public function render_attached_file() { $attachment = get_post( get_queried_object_id() ); $filepath = get_attached_file( $attachment->ID ); $mime_type = $attachment->post_mime_type; if ( $this->is_image( $mime_type ) ) { $this->render_file( $filepath, $mime_type ); } else { $this->set_404(); } } /** * Serve a 410 for attachment pages. */ public function serve() { if ( is_attachment() ) { status_header( 410 ); $this->render_attached_file(); } } /** * Determines if a mime type is for an image. * * @param string $mime_type The mime type to check. * * @return bool Whether or not the given mime type is for an image. */ private function is_image( $mime_type ) { return in_array( $mime_type, $this->valid_image_types, true ); } /** * Sets the 404 status in WordPress to true. */ protected function set_404() { global $wp_query; $wp_query->is_404 = true; } }