From 84e539c8218c9c64e5b3e2f36725644d820b6ab9 Mon Sep 17 00:00:00 2001 From: Laury GvR Date: Wed, 25 May 2016 12:59:28 -0400 Subject: [PATCH] Front-end login redirect helper functions --- functions.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/functions.php b/functions.php index aa51024..b4bc60a 100644 --- a/functions.php +++ b/functions.php @@ -193,4 +193,63 @@ add_action('thematic_searchloop', 'mytheme_search_loop'); // return $post_id; // } // } + +/* + * This function returns true when the current page is the page given by ID + * or a descendent thereof. + */ +if (!function_exists('is_in_tree')) { + function is_in_tree( $pid ) { + global $post; + + if ( is_page($pid) ) + return true; + + $anc = get_post_ancestors( $post->ID ); + foreach ( $anc as $ancestor ) { + if( is_page() && $ancestor == $pid ) { + return true; + } + } + return false; + } +} + +/** + * Function Name: front_end_login_fail. + * Added for: GLM Member DB front-end login failure custom redirection. + * Description: This redirects the failed login to the custom login page + * instead of default login page with a modified url +**/ +add_action( 'wp_login_failed', 'front_end_login_fail' ); +function front_end_login_fail( $username ) { + // Getting URL of the login page + $referrer = $_SERVER['HTTP_REFERER']; + // if there's a valid referrer, and it's not the default log-in screen + if( !empty( $referrer ) && !strstr( $referrer,'wp-login' ) && !strstr( $referrer,'wp-admin' ) ) { + wp_redirect( get_permalink( get_option('glm_members_database_option_members_only_id') ) . "?login=failed" ); + exit; + } +} + +/** + * Function Name: front_end_blank_credentials. + * Added for: GLM Member DB front-end login failure custom redirection. + * Description: This redirects to the custom login page if user name or + * password is empty with a modified url +**/ +add_action( 'authenticate', 'front_end_blank_credentials', 1, 3); +function front_end_blank_credentials( $login, $username, $password ) { + + // Getting URL of the login page + $referrer = $_SERVER['HTTP_REFERER']; + // if there's a valid referrer, and it's not the default log-in screen + if( !empty( $referrer ) && !strstr( $referrer,'wp-login' ) && !strstr( $referrer,'wp-admin' ) ) { + if( $username == "" || $password == "" ){ + wp_redirect( get_permalink( get_option('glm_members_database_option_members_only_id') ) . "?login=empty" ); + exit; + } + } +} + ?> -- 2.17.1