I've built a custom user account system using a custom post type. I was wondering whether it is safe to use the built-in function wp_set_auth_cookie($user_id, $remember, $secure) Wordpress uses for the built-in user system. For $user_id I figured I could use the post id. But wouldn't this clash with the existing system? Is there a nifty trick to keep the default user cookies from clashing with the custom user cookies or shouldn't I use this function at all?

1 Answer 1


Why are you building a seperate user system in the first place? The wordpress builtin system is pretty flexible.

In theory all the login functions like wp_set_auth_cookie(), wp_generate_auth_cookie(), wp_parse_auth_cookie() etc. are all pluggable functions. Which means you can replace them with your own custom functions.

But to be realistic, it will be a lot of work to get this working as you won't be able to use the default wp_set_auth_cookie() as long as you replace all login functions, or sync your virtual userbase with the real wp_users table.

The default function will not set a valid login cookie unless it finds that $user_id is a real wordpress user.

I think your best options are:

  • Rewrite your login system to use real users instead of your CPT and store your custom stuff in user_meta.
  • Sync your CPT users with real users (create a real user for each post of your CPT).
  • Build your own login system, leave it totally seperate from wordpress users and create the auth_cookies your self.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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