Working on WordPress

Posted on July 15, 2020 · 7 mins read

I’ve spent time over the past couple months working on WordPress plugins for the MIT Club of Northern California (MITCNC). I haven’t done any significant WordPress development since early 2017, when I made updates to the theme and plugin I built for my photography site. I am also on the bandwagon of PHP haters (although this is mostly due to not-so-great experience of dealing with Drupal at edX). This most recent experience with WordPress has been both exciting and frustrating!

SSO

My work began with a need to improve the single sign-on (SSO) experience for our members. SSO allows any alum around the world to sign into the MITCNC website and register for events. Since the pandemic has moved all events online, we also pull alumni data from an API owned by the MIT Alumni Association (MITAA) to determine club membership and offer reciprocal benefits. This means a member of the MIT Club of Hong Kong can attend a virtual MITCNC at the member price—usually free.

MITAA operates an OAuth 2.0 provider to facilitate authorization, so our WordPress site needed an OAuth 2.0 plugin. I searched for existing plugins, but none fully met our needs, and all would need further customization to make additional API calls to get alumni data (e.g., club memberships and class year), so I decided to build my own. I had no desire to create an OAuth client from scratch—kinda been there already, and don’t want to go back—so I used an existing client as my starting point. The bulk of my time was spent re-learning how to create an admin settings page to capture OAuth credentials, and create/update users on successful sign-on. I also used this as an opportunity to learn about using PHP_CodeSniffer to maintain code quality and perform linting.

The completed plugin is available at https://gitlab.com/mitcnc/mitaa-wordpress-sso. I am used to maintaining packages in a requirements.txt, Gemfile, or package.json, so I opted to make this plugin installable via the PHP equivalent, Composer. The use of Composer, rather than an admin UI, to install WordPress seems to slowly be becoming the norm. This plugin isn’t useful outside the MIT alumni community, so I doubt I’ll ever publish it in the official WordPress directory.

One area I need to explore more is testing. GitLab CI currently runs for each merge request, but it only validates the composer.json file and runs PHP_CS. All of my testing has been manual, which is fine given the relatively small scope of this plugin, but not sustainable over time.

Stripe

Club memberships are currently processed by a different service—Encompass—using CyberSource for payments. Many MIT groups, including edX, use CyberSource for payment processing. I’ve tried to change this since before I joined Stripe, but it’s a tough battle! I do have more control over MITCNC, and we are making a move to Stripe to handle our memberships primarily because CyberSource’s card account updater is not functioning properly. We see a high proportion of memberships lapse due to outdated card data, which is unacceptable for a club that relies on recurring revenue to fund operations. It’s a bonus that I used to work on the team that handles subscriptions, and now work on the team that handles payments.

WooCommerce was my first destination when looking at existing plugins for WordPress. It’s by far the most popular way to integrate Stripe with WordPress. Unfortunately, it’s missing two recent Stripe features that I really want to take advantage of—Checkout and customer portal. Checkout allows us to rely on Stripe for our checkout page, and take advantage of additional payment methods that might be of interest to our international alumni. We can also, finally, make use of Apple Pay and Google Pay to make checkout even faster. The customer portal gives members the ability to view past invoices and adjust their memberships without having to message our club administrator.

I ended up building my own Stripe plugin at https://gitlab.com/mitcnc/wordpress-stripe-plugin. The plugin allows for a selection of activated pricing plans on the admin side. Shortcodes can be used to display a pricing table and checkout button, or a link to the customer portal. I also wrote a background task to create Stripe customers for every WordPress user, which will help when we migrate data from CyberSource to Stripe.

This plugin is not as full-featured as WooCommerce (nor is it meant to be), but it’s a great starting point for us since it gives our alumni more information about, and control over, their memberships. That said, I hope that WooCommerce supports Checkout and the customer portal someday so that we can join that ecosystem and, eventually, use WooCommerce+Stripe to handle event registrations and other purchases.

Closing thoughts

My two months of WordPress development have been pretty good. I still need to work on testing, and I’m also interested in how folks better divide their code into files/classes. Both of these plugins consist of a single class with about 800 lines of code. Code navigation during development is a bit wild right now, so it would be great to split the class in some logical manner, or switch to a more functional approach.

Both plugins are open source under the MIT license. Feel free to use the code/plugins if they are helpful, or submit a merge request if you see something that needs fixing.

MITCNC will most likely continue using WordPress for the foreseeable future. If you’re an alum, or just someone passionate about open source or volunteering, we’d love to have your assistance. Once we migrate membership data, we’ll turn our focus to event registration and email marketing. Contact me if you want to help!