When you have a problem, you usually have to find a solution pretty quick. It’s kind of a shame, but it’s better to do something and fail than getting nothing done. At least you know what isn’t working. It’s important to get working solution first, but usually you stop there and forget the code. Therefore you should review earlier solutions and think how to improve your codebase.

In here, I’d like to share how I started with one solution and ended up with another. Problem was: how to share membership details between Rails and WordPress. If you compare solutions 1 and 3, they differ a lot, but both solve the problem. Latter a little bit better than former (in my opinion).

Solution 1

First I thought about sharing the session between these apps. Basically, we would create unique one-time hash in Rails when user logs in. Then the hash would be saved in to secure cookie within the same domain. WordPress would use custom-made plugin to get the hash from the cookie and use a command line script to get user details from the rails app. Pretty much customization and maintaining, and sharing session like this is pretty hard to get fully functional. So I dumped this after a month.

Solution 2

Then I started to look SSO (Single Sing-On) solutions and found doorkeeper (https://github.com/doorkeeper-gem/doorkeeper). It uses OAuth and was pretty easy to install and get working. The problem was that there weren’t OAuth client plugins (other than preconfigured with Twitter/Facebook etc) for WordPress at the time. And I had no competence to create that kind of plugin. This solution didn’t allow either of the apps to have their own user registers. And I thought that users should be able to register either of the apps separately.

Solution 3

I found wp-cli at some point middle of thinking solution 2. I started to think what if both apps could have their own users and I didn’t need to customize WordPress at all. I just needed some tool to use wp-cli from Ruby. So I created gem wpcli. How about syncing the membership details? In Rails there was field for username in WordPress and whenever that value will be changed, syncing is done. This requires also some kind of settings page, where roles from each app can be mapped to each other. For example, member in Rails would be premium customer in WordPress.

This was done for spare time project, but I think that’s not relevant.

So I strongly encourage to review already made solutions and to question those constantly. It’s one of the best ways to improve software over the time and more important, it helps you to improve your skills.