Blog

How To Create A Front End Login Page With Easy Digital Downloads

Recently I published a quick tutorial on setting a WooCommerce site to use the WooCommerce login page for all logins instead of wp-login.php. I wanted to replicate this functionality on a new site I’m building with Easy Digital Downloads.

Easy Digital Downloads requires a bit more work, as by default there’s no option to set a login or account page. But as EDD is a quality plugin it was no surprise that I could easily add a new setting for it using the edd_settings_general filter. EDD also has a super handy edd_get_option()¬†function which makes it easy to retrieve the value of our new setting.

On the page that you want to set as your account page make sure you have the [edd_profile_editor] shortcode in the content. The shortcode will display the login form to logged out users, and the profile fields to logged in users.

Once the page and settings are setup, we can pretty much replicate the functionality used for WooCommerce to do the same thing with EDD.

Once you’ve added the code below, your site will automatically redirect any logged out visits to /wp-admin instead to the new EDD account page, as well as updates any other functions that are displaying a link to the login page.

<?php
add_filter( 'edd_settings_general', 'cameronjonesweb_edd_login_page' );
add_filter( 'login_url', 'cameronjonesweb_use_edd_login_page', 10, 3 );
/**
* Adds an additional page to the EDD pages settings
* Make sure the

You need to log in to edit your profile.

Log into Your Account

Lost Password?

or
Log into Your Account

Lost Password?

shortcode is on this page.
*
* @param array $settings The array of settings.
* @return array The updated settings array
*/
function cameronjonesweb_edd_login_page( $settings ) {
array_splice( $settings['main'], 6, 0, [
'account_page' => [
'id' => 'account_page',
'name' => __( 'Account Page', 'easy-digital-downloads' ),
'desc' => __( 'This is the page where customers will login and update their account details.', 'easy-digital-downloads' ),
'type' => 'select',
'options' => edd_get_pages(),
'chosen' => true,
'placeholder' => __( 'Select a page', 'easy-digital-downloads' ),
],
] );
return $settings;
}
/**
* If EDD is active use the account page for logging in
*
* @param string $login_url The URL for login.
* @param string $redirect The URL to redirect back to upon successful login.
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
* @return string
*/
function cameronjonesweb_use_edd_login_page( $login_url, $redirect, $force_reauth ) {
if ( function_exists( 'edd_get_option' ) ) {
$edd_account_page = get_permalink( edd_get_option( 'account_page' ) );
if ( ! empty( $edd_account_page ) ) {
$login_url = $edd_account_page;
}
}
return $login_url;
}

Did you find this post useful?

YesNo