Force users to be logged-in to download purchased files

Themify Landing featured

I know many of you are as big a fan of Easy Digital Downloads as I am, so you will love this snippet. This snippet for EDD will force users to be logged-in to download purchased files. It is also probably best that you use this as a plugin how Pippin Williamson intended.

If you are looking to add a little more functionality to the login process check out this snippet to Capture users last login date and time.

class EDD_Force_Login {

	function __construct() {
		add_action( 'plugins_loaded', array( $this, 'load' ) );

	public function load() {
		add_action( 'edd_process_verified_download', array( $this, 'force_login' ), 10, 2 );

	public function force_login( $download, $email ) {
		if(  ! is_user_logged_in() ) {
			$login_url = wp_login_url( trailingslashit( home_url() ) . '?' . $_SERVER['QUERY_STRING'] );
			$message = sprintf( 'You must be logged in to download files. <a href="%s">Login here</a>.', $login_url );
			wp_die( $message, 'Error' );


$GLOBALS['edd_force_login'] = new EDD_Force_Login();

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!