Make WordPress Core

Opened 4 months ago

Closed 2 months ago

Last modified 2 months ago

#61746 closed defect (bug) (worksforme)

WordPress login redirect issue

Reported by: dipakparmar2007's profile dipakparmar2007 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Login and Registration Keywords: has-testing-info
Focuses: Cc:

Description (last modified by hellofromTonya)

The 'login_redirect' hook is not work in WordPress version 6.1.1.

I set default themes.

// Hook into the login_redirect filter
add_filter('login_redirect', 'custom_login_redirect', 10, 3);

function custom_login_redirect($redirect_to, $request, $user) {
   
        return home_url('/dashboard/');

}

if ( isset( $_POST['action'] ) && $_POST['action'] == 'log-in' ) {

    $user_login = $_POST['user_login'];
    $password = $_POST['password'];
    $user_data = array(
	 'user_login' => $user_login,
	 'user_password' => $password,
	 'remember' => true
	);

	$user = wp_signon( $user_data );

	if ( ! is_wp_error( $user ) ) {
	 	$user_id = $user->ID;
	    if ( $user_id ) {
	        $url = site_url().'/dashboard/';
		    wp_redirect( $url );
		    exit;     
	    }  
	} else {
	 	$error_message = $user->get_error_message();
	}

}



<form action="" method="post" class="sign-in">
	<div class="form_group">
		<label for="user_login"><?php _e('Username'); ?></label>
				        
		<input type="text" name="user_login" class="input_control" id="user_login" value="" />
	</div>
	<div class="form_group">
		<label for="password"><?php _e('Password'); ?></label>
		<input type="password" class="input_control" name="password" id="password" />
	</div>
	<div class="forgot"><a href="<?php echo site_url(); ?>/forgot-password/">Forgot Password?</a></div>
	<div class="form_footer">
		<button type="submit"><?php _e('Log in'); ?></button>
		<input type="hidden" name="action" value="log-in" />
	</div>
</form>

Attachments (1)

login-issue.jpg (130.9 KB) - added by dipakparmar2007 4 months ago.

Download all attachments as: .zip

Change History (7)

#1 @dipakparmar2007
4 months ago



// Hook into the login_redirect filter
add_filter('login_redirect', 'custom_login_redirect', 10, 3);

function custom_login_redirect($redirect_to, $request, $user) {
   
        return home_url('/dashboard/');

}

This hook is ilso not work in WordPress version 6.1.1 and I set default themes.

Last edited 4 months ago by dipakparmar2007 (previous) (diff)

#2 @hellofromTonya
2 months ago

  • Description modified (diff)

#3 @hellofromTonya
2 months ago

  • Component changed from General to Login and Registration
  • Keywords has-testing-info added
  • Severity changed from critical to normal

Testing Instructions

These steps define how to reproduce the issue and indicate the expected behavior.

Steps to Reproduce or Test

Test Page: Dashboard.

  1. Create the "Dashboard" page.
    • Log into WordPress.
    • Go to Pages > Add New Page.
    • Add "Dashboard" as the title.
    • Publish the page.
  2. Log out of the site.
  3. Add the test code as a must-use plugin:
  • Add the wp-content/mu-plugins/ directory.
  • Add a test.php file in that directory.
  • Copy and paste the following code into that file:
add_filter( 'login_redirect', 'custom_login_redirect', 10, 3 );
function custom_login_redirect( $redirect_to, $request, $user ) {
        return home_url('/dashboard/');
}
  • Save the file.
  1. Go to the login page, e.g. http://example.com/wp-admin/ or http://example.com/wp-login.php.
  2. Enter your login credentials.
  3. Select/trigger/enter the Log In button.
  4. 🐞 Bug occurs.

Expected Results

When testing a patch to validate it works as expected:

  • ✅ Should redirect to the expected page after login.

When reproducing a bug:

  • ❌ Does not redirect to the expected page after login.

Supplemental Artifacts

Test Report Icons:
🐞 <= Indicates where issue ("bug") occurs.
✅ <= Behavior is expected.
❌ <= Behavior is NOT expected.

#4 @hellofromTonya
2 months ago

Reproduction Report

This report validates that the issue can be reproduced.

Environment

  • OS: macOS
  • Web Server: Nginx
  • PHP: 8.3.8
  • WordPress: 6.6.2
  • Browser: Firefox 131.0
  • Theme: Twenty Twenty-Four
  • Active Plugins: None

Actual Results

  • ❌ Could not reproduce the reported issue.

After login, the site redirected to the Dashboard page which in my test site is http://wpdev.test/dashboard.

Additional Notes

Works for me in my local testing.

#5 @hellofromTonya
2 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Hello @dipakparmar2007,

Welcome to WordPress Core's Trac. I'm sorry to hear you are having difficulty with your site after updating to 6.6.1.

I tested (see test report comment:4) using the sample callback you shared. I'm unable to reproduce the issue. In my testing:

  • The site redirects to Dashboard page.
  • 'login_redirect' filter is working.

I'm not sure about the extra code shared in the description, but am assuming that's the custom code being used.

As not able to reproduce and with the information shared, the reported issue does not appear to be a Core bug. Closed this ticket as worksforme.

Where you can find help?
You can find people who are able to assist with your site in the WordPress support forums.

Please note, this Trac is used for the development of the WordPress Core software itself, not for support or assistance with individual sites, themes, frameworks, or plugins.

#6 @hellofromTonya
2 months ago

  • Version 6.6.1 deleted

For contextual history, here are non-docs changes made to this area of the code during 6.6.x cycles:

Note: See TracTickets for help on using tickets.