Front-end login redirect helper functions
authorLaury GvR <laury@gaslightmedia.com>
Wed, 25 May 2016 16:59:28 +0000 (12:59 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Wed, 25 May 2016 16:59:28 +0000 (12:59 -0400)
functions.php

index aa51024..b4bc60a 100644 (file)
@@ -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;
+        }
+    }
+}
+
 ?>