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.

I have http://example.com/admin.php

There I check whether the user is admin or not. If not, I send the user to the wp-login page like this:

blog.mysite.com/wp-login.php?redirect_to=http%3A%2F%2Fmysite.com/admin.php

I expect redirect back for admin.php but WordPress always sends me to wp-admin control panel.

After researching, I found that when the destination host is not in filter allowed_redirect_hosts, WP just redirects the user to wp-admin.

How can I add more hosts to the filter?

If I put this example from the WP Codex in functions.php, it stops working.

add_filter( 'allowed_redirect_hosts' , 'my_allowed_redirect_hosts' , 10 );
function my_allowed_redirect_hosts($content){
    $content[] = 'blog.example.com';
    $content[] = 'codex.example.com';
    // wrong: $content[] = 'http://codex.example.com';
    return $content;
}
share|improve this question
    
It looks like that should work. When you say "it stops working", what do you mean? Users get redirected to wp-admin, or you get error messages, or the site goes blank, or...? Also, if you can post the code you used -- not the stuff from the Codex, but the actual code that you tried in functions.php -- that might help. –  Pat J Jul 16 '13 at 0:40
    
I tested the filter and successfully added www.google.com to the 'safe' list. That filter works. The problem is elsewhere. Something else in code not posted is going on that is causing the problem. –  s_ha_dum Jul 16 '13 at 4:44
    
Thank you two.I added the code just replacing the strings for "google.com", to the functions.php. Just it stop working and the page goes blank, like a php error. Maybe i must add the code in the theme's function.php? –  chipi92 Jul 16 '13 at 9:57

1 Answer 1

up vote -1 down vote accepted

Finally it works! What I was doing wrong is putting the code in the WP functions.php file, and not in my custom theme functions.php file.

Thanks all!

share|improve this answer
    
Glad you got it working. For future reference: All code that you are adding belongs in either your theme files (usually wp-content/[themename]/functions.php) or a plugin (usually in wp-content/plugins/[...]). The general rule of thumb is don't hack core. –  Pat J Jul 16 '13 at 16:27

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.