[wp-trac] [WordPress Trac] #61746: WordPress login redirect issue
WordPress Trac
noreply at wordpress.org
Fri Oct 4 15:44:03 UTC 2024
#61746: WordPress login redirect issue
-----------------------------+------------------------------
Reporter: dipakparmar2007 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 6.6.1
Severity: critical | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Description changed by hellofromTonya:
Old description:
> 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>
New description:
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>
}}}
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61746#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list