• Resolved Florian TIAR

    (@mista-flo)


    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)
  • Plugin Author NicolasKulka

    (@nicolaskulka)

    Salut Florian, comment vas tu ?

    Tu peux me proposer la pull request ?

    Thread Starter Florian TIAR

    (@mista-flo)

    Hello Nico, bien et toi ? ??

    Vous avez un repo Github ?

    Je viens de me rendre compte d’un truc en fait.

    Ce cas s’applique uniquement quand les deux options ont la même valeur, c’est à dire l’URL de redirection est la même valeur que la nouvelle URL de login.

    Le code que j’ai montré est un peu buggé et marche que dans certains cas.

    Plugin Author NicolasKulka

    (@nicolaskulka)

    ?a va bien

    Pas du tout, mais prend la dernière version et propose un correctif qui fonctionne dans tous les cas, je ferais un diff.

    Thread Starter Florian TIAR

    (@mista-flo)

    Ok c’est bon j’ai réecrit un patch au propre, où est-ce que je peux t’envoyer le code ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Does not redirect with previous URL’ is closed to new replies.