wordpress plugin admin pages – infinite loop on login page

While writing a wordpress plugin with several admin pages (at least pages for identified users) I ran into the following issue:

Upon every successful login, my page content was not displayed and user was redirected to login screen in what seemed to be a never ending loop.

After lengthy debugging, reason for this was that after login, I redirected my user to a custom short url which did not start with ‘wp-admin/xxxx’. Then in my page being loaded, when I included the file /wp-admin/admin.php to load wp framework, this redirected me to login page.

When a user logs in using wordpress native login functionality, the cookie is set with a path set to ‘/wp-admin’. If the url you are using for your page does not start with ‘/wp-admin’ then the logged-in cookie is not loaded and user is redirected to the login page in a never ending loop.

Note: the technique of creating dedicated admin pages and loading wp framework by including wp-admin/admin.php page is inspired from wp admin pages such as wp-admin/plugins.php

Solution

Quick and easy solution is to have all the urls for your pages requiring identification to start with ‘wp-admin/’.

Post a Comment

Your email is never published nor shared. You're allow to say what you want...