Support » Plugins » Hacks » extending wbdp class to use another user authentication system

  • Hello friends,

    I am running a multisite wordpress install alongside two other opensource applications (Elgg and a made-from-sratch project management system built on CodeIgniter), but each has its own user system, authentication, etc. I am merging these three to use the same user login system so that my users can login once for all aspects of the site, and I don’t have to have all userdata in three different places. I’ve mapped out the databases, and already remade the CodeIgniter system to use the Elgg user authentication.

    WordPress is next. My thought was to extend the wpdb class so that anytime a query is run on the $wpdb->user or usermeta tables, it runs my custom methods that extract the user info from the Elgg system and returns it in wordpress terms. Then all I need to do is have the master login script set the appropriate wordpress cookies and my user logs in once for all three systems.

    Is there a way to do this with by coding a plugin? I’d rather not hack the wpdb class. I’ve seen a few mentions of db.php being used to extend the class, but I can’t find documentation about how this actually works.

    Or, if anyone knows a better way to go about this, I’m all ears.

    Thank you

Viewing 9 replies - 1 through 9 (of 9 total)
  • wp_authenticate is a pluggable function, meaning that you can add a function to a plugin to override its functionality. (I think — I haven’t dug around much in pluggable functions myself.)



    very awesome

    This line of the wp_authenticae() function tells you what yo uneed to do:

    $user = apply_filters('authenticate', null, $username, $password);

    That’s telling you that you can add yoru own filter for ‘authenticate’ that can contain your own login/authentication code. That will let you check a different system for the authentication.

    So, if I rewrite the wp_authenticate by using the filter to check against my other system that takes care of the login feature. It would return WP_User with the information from my other system. Would that take care of wordpress and plugin queries about the user? Like if $user->user_email is called? What about usermeta or other functions like is_admin() or get_userdata( $userid );

    Thanks for the help. I think I’m seeing what I need to do.



    very awesome

    No, you do not re-write wp_authenticate. You use the ‘authenticate’ filter to call your own authentication function.

    As for waht it returns, I didn’t look at that part, but if you return the same thing as the other function that it’s being called from wp_authenicate( 0then you’ll find out what is expected.

    Thank you. That is great

    For one example that I use at work — if you need examples, of course — check out the Simple LDAP Authentication plugin.

    Thank you, that example is helpful. As I’ve done some more digging, I’ve found that it isn’t just authentication that is the issue. For me, I don’t want to have a WordPress account for one part of the site and a separate account for the others, even if the plugins play nicely together. I want to keep all data in one place. So, I’ve begun working on a database drop-in that runs every $wpdb method request (get_results(), query(), etc) through a filter that checks if the $wpdb->users or usermeta table is being used. If it is, it runs a custom function that pulls the info from my other database and returns it the way wordpress expects. I’ve started development and it seems to be working, but I’ve just started.

    Thanks all!

    PS: I would be willing to release this as a plugin. Would it help anyone else?

    Wow, that sounds daunting. Good luck!



    chrismichaels84 I wouldn’t Mind some help with my plug in for just my site . Have multiple sites that share the same database not the same tables but each Of the website’s can Access the other website’s tables. I want the user to be able to register on one Particular site added their profile From that one site. Be able to login On any of the other Websites . and only have the data stored in a one site .

    Patrick Johanneson. I could use help how to have my own code for authentication.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘extending wbdp class to use another user authentication system’ is closed to new replies.