I have a custom login, in which I have 2 apis: The first to post a user phone, and the second to post the user pin to verify the phone.

The main issues is that these 2 apis, which has the following url (domain.com/api/user/verify_phone) are not working because they are redirected to the /login page.

When I call the same url after the user is authenticated it works... but I need it before the login of course. How can I do that? Please help!

I may found that the bug in the functions.php on the theme, there I have created a function to handle all the redirections of the login, this is the code:

function login_redirect(){
global $pagenow;
     if( 'wp-admin' != preg_split('/\//',$_SERVER['REQUEST_URI'])[1] ){
        if(preg_split('/\//',$_SERVER['REQUEST_URI'])[1] == '/api/'){
        }else if( $_SERVER['REQUEST_URI'] != '/login/') {
            if (!checkUserStatus()){

So with these I try to redirect all call to make sure users log in and I tried to make the apis call go through but there are still giving a 302 redirection error. PLEASE HELP!

  • 2
    How are those APIs implemented? There's no code in your question – Tom J Nowell Jan 6 '19 at 2:33

I think this is just a slight mistake on your "if" condition

$result = preg_split('/\//','domain.com/api/user/verify_phone');

Results in:

array(4) {
  string(10) "domain.com"
  string(3) "api"
  string(4) "user"
  string(12) "verify_phone"

So the result at [1] is "api", but you are checking for "/api/" on the fourth line of your code sample.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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