Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created August 8, 2018 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/e609fb74dcb6ab2ad3651c74578043a1 to your computer and use it in GitHub Desktop.
Save cameronjonesweb/e609fb74dcb6ab2ad3651c74578043a1 to your computer and use it in GitHub Desktop.
Update Easy Digital Downloads sites to use an account page to login rather than wp-login.php
<?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 [edd_profile_editor] or [edd_login] 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment