Does not redirect with previous URL
-
Hi there,
When accessing a wp-admin page while not logged in, it doesn’t keep the old URL and redirect to the new login URL.
The normal behaviour is to add a redirect_to GET parameter in the URL so that it can take you directly to a post edit page for example.
Tried to implement it myself, but no hook available to do it without hacking the plugin if I’m right.
It’s a bit dirty, I think it’s better if you can handle this directly.
public function wp_loaded() { global $pagenow; $request = parse_url( rawurldecode( $_SERVER['REQUEST_URI'] ) ); if ( ! ( isset( $_GET['action'] ) && $_GET['action'] === 'postpass' && isset( $_POST['post_password'] ) ) ) { if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' && $request['path'] !== '/wp-admin/options.php' ) { $redirect_to = home_url(); if ( ! empty( $request['path'] ) ) { $redirect_to .= $request['path']; } if ( ! empty( $request['query'] ) ) { $redirect_to .= '?' . $request['query']; } wp_safe_redirect( $this->new_redirect_url( $redirect_to ) ); // ....
public function new_redirect_url( $scheme = null ) { if ( get_option( 'permalink_structure' ) ) { $url = $this->user_trailingslashit( home_url( '/', $scheme ) . $this->new_redirect_slug() ); if ( ! empty( $scheme ) ) { $url .= '?redirect_to=' . urlencode( $scheme ); } return $url;
`
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Does not redirect with previous URL’ is closed to new replies.