Hello guys I am trying to setup the forum on my site. I have some issues. I have woocomerce, wp foro and wp-login.php. These three have login methods. I have already worked out the way to redirect people to wp-login.php for woocomerce. but in wp foro there is only an option to add the cutom login and register page url. The issue with approach is users are not being redirected back to the page they were on.
I want users to be redirected back to the page they were one earlier:
function redirect_to_login_if_not_logged_in() { // Only apply redirect logic if the user is not logged in if ( ! is_user_logged_in() ) { // Capture the requested URL $redirect_to = esc_url($_SERVER['REQUEST_URI']); // Check for WPForo login/signup pages and redirect to WordPress login if ( is_page(array('sign-in', 'sign-up')) ) { wp_redirect( wp_login_url($redirect_to) ); exit; } } } add_action('template_redirect', 'redirect_to_login_if_not_logged_in');
This is how I am trying to do but it don't seem to be working. This way the code is not redirecting properly.
Basic option given in plugin does not redirect users to their original page where they were.
Hi,
Please try this code:
dd_filter( 'wpforo_login_url', function( $login_url ){ if( wpforo_setting( 'authorization', 'login_url' ) ){ $login_url .= wpforo_get_redirect_to_url_path(); } return $login_url; } ); add_filter( 'wpforo_register_url', function( $register_url ){ if( wpforo_setting( 'authorization', 'register_url' ) ){ $register_url .= wpforo_get_redirect_to_url_path(); } return $register_url; } );
I am very interested in this code as I am using a custom URL for my login page due to a membership plugin.
Can you confirm where I should add this code to allow the redirect to work on this page?
Thanks!