Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

hey i got a slightly weird problem..

i got a form enabling login in certain single's according to the cateory and user level.. it works great but the server which is windows (where the website is hosted on returns the wrong "current page" value

Meaning.. this:

'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 

returns this: www.somewebsite.com/sub/sub/?p=100

instead of: www.somewebsite.com/sub/?p=100

This is the actuall form:

          <div class="logincategory">
            <?php wp_login_form( $args );
             $args = array(
            'echo' => true,
            'redirect' => site_url($_SERVER['REQUEST_URI']),
            'form_id' => 'loginform',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_remember' => __( 'Remember Me' ),
            'label_log_in' => __( 'Log In' ),
            'id_username' => 'user_login',
            'id_password' => 'user_pass',
            'id_remember' => 'rememberme',
            'id_submit' => 'wp-submit',
            'remember' => true,
            'value_username' => NULL,
            'value_remember' => false ); ?> 
            </div>

So.. this is a bug of the server which i can't solve directly

so i used

$myCurrentUrl = site_url( $_SERVER['REQUEST_URI'] ); $myCurrentUrltwo = str_replace("www.somewebsite.com/sub/sub/","www.somewebsite.com/sub/", "$myCurrentUrl");

That (when eching) returns the right URL but how do i insert the variable into this command

    'redirect' => site_url( $_SERVER['REQUEST_URI'] ), 
share|improve this question
    
having the exact same issue. –  helgatheviking Nov 10 '11 at 1:53
    
i made a hacky solution.. i have created a folder on my root hosting with the same name as the the folder that is being shown up twice then put an index.php file inside of it with the code in my answer down here (the header(status...) answer i wrote here - so i hope it would help you –  Sagive SEO Nov 10 '11 at 7:34

4 Answers 4

up vote 1 down vote accepted

based on the changes seen in the diff on this trac ticket: http://core.trac.wordpress.org/ticket/17243

i've adjusted my redirect to the following

'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']

and this seems to work for WP when it is in a subfolder. this will be the new default value starting in WP 3.3 and wp_login_form() works for me in 3.3-beta3 without passing any arguments.

so for now i am going to serve up arguments conditionally based on version (maybe overkill)

if ( !version_compare( $wp_version, '3.3-beta3', '>=' ) ) {
    $args = array ( 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
    );
} else {
    $args = array ();
} 

wp_login_form($args);
share|improve this answer
    
10x for your help.. that ticket gave the right direction :) –  Sagive SEO Nov 11 '11 at 18:45

i tried that.. i guess the server reWrited on the way to the browser. thanks for all you help.. guys.. i solved it using this:

<?php
header("Status: 301 Moved Permanently");
header("Location: /sub/index.php?". $_SERVER['QUERY_STRING']);
exit;
?>

That works so i am going to stay with that since the client needed a fast solution.

share|improve this answer

Insert it like this:

<?php wp_login_form( $args );
             $args = array(
            'echo' => true,
            'redirect' => $myCurrentUrltwo,
            'form_id' => 'loginform',
            'label_username' => __( 'Username' ),
            'label_password' => __( 'Password' ),
            'label_remember' => __( 'Remember Me' ),
            'label_log_in' => __( 'Log In' ),
            'id_username' => 'user_login',
            'id_password' => 'user_pass',
            'id_remember' => 'rememberme',
            'id_submit' => 'wp-submit',
            'remember' => true,
            'value_username' => NULL,
            'value_remember' => false ); ?> 
share|improve this answer

change your redirect to:

'redirect' => '/' . $_SERVER['REQUEST_URI'],

That will then take you to the right location.

share|improve this answer
    
Noep that still takes me to the wrong place... This : $_SERVER['REQUEST_URI'] return the wrong address.. i need to change this with my varible.. –  Sagive SEO Sep 13 '11 at 14:47
    
What does $_SERVER['REQUEST_URI'] return? –  Alex Older Sep 13 '11 at 14:52
    
www.somewebsite.com/sub/sub/?p=100 (for example).. instead of: www.somewebsite.com/sub/?p=100 Its a server error and not a problem with wordpress.. is there any way to feed 'redirect' a value from a variable ?? –  Sagive SEO Sep 13 '11 at 14:55
    
what does it return outside of the site_url() function? –  Alex Older Sep 13 '11 at 15:00
    
What do you mean? "outside of the site_url() function?" I treid writing everything in my inital explenation.. –  Sagive SEO Sep 13 '11 at 15:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.