Skip to content

Fixing the Idea Publisher plugin

Posted in Experiences

Fixing the Idea Publisher plugin is not something I thought I would need to do a day after announcing it and yet here we are. Let’s jump right into it.

One of the biggest limitations while building the idea publisher was that I had to test it from a localhost setup. Virgin of any and all dependencies outside of WordPress Core. I did so mostly to avoid sending tons of emails to my subscribers when testing the plugin. Unfortunately, my big announcement was the first outing from my blog and it fell flat. I refreshed my Minds profile over and over but nothing happened.

Eventually I had to face reality, something was broken. I immediately tested publishing from my local setup and it did work. It has something to do with my real setup. Now the first step is figuring how to disable email sending so that I can debug the plugin in live condition without spamming my dear subscribers.

I found a very helpful entry on the WordPress StackExchange showing how to do that programmatically. From there I created a mini-plugin that allows to put any kind of code you wouldn’t want WordPress updates to override. In that plugin I pasted the below:

add_filter('wp_mail','disabling_emails', 10,1);
function disabling_emails( $args ){
    unset ( $args['to'] );
    return $args;
}

I write a post, publish it and the bit of code didn’t work. Turns out I forgot to activate the mini-plugin. After doing so, I published another random post and this time it worked. No email was sent, I could finally get to work. Well, after my workout and before work. That should give me about an hour and a half to debug/investigate before returning to my office’s comfort zone far away from WordPress and PHP.

Towards the end of the day, I created a new post and published it to make sure emails weren’t sent but somehow emails were back. For some reason the previous two attempts didn’t generate emails and lured me into a false sense of security. Fortunately I do have another WordPress setup deployed in similar conditions to the blog one but without any subscribers. It’s actually related to the project that inspired me creating the Idea Publisher.

At this point, I disconnect that account and try connecting my main Minds profile to that other website. I make publishing attempt then look at my profile, nothing. Then I go on that alternate Minds profile and find that I shared the post there instead. Good, progress. From there, I realise that there must be something wrong with the access token handling.

Since I used WordPress options to manage these, I go and read the documentation. As it turns out, I made a huge mistake. The add_option method does not work as I expected. Actually two.

The first one? My disconnection method for the plugin deletes profile information but not the access nor refresh token. Since the add_option method cannot overwrite existing values, disconnecting then reconnecting an account to Minds.com will fail to update the tokens.

The second mistake comes from the usage of add_option. When refreshing tokens, I use a piece of code that I thought would update the tokens using add_option since there is no updating options. On top of that, I could not detect via unit nor UI testing since running against a virgin environment would not reveal that issue. I would guess that my previous live tests only worked because the token for my main Minds account had not expired yet.

So there are two bugs that I need to fix in order to solve that problem I am facing:

  1. Clear tokens upon disconnection.
  2. Update the options handling to delete options before adding new ones.

Both were fairly straightforward to fix. After implementing these fixes, I extensively tested them on various sites I have. Luckily I have a live setup with a mix of websites with existing and non-existing plugin installs which allowed me to cover more ground than not. Unfortunately, this is the sort of issue you run into with non-testable third party. Sometimes, the key is in the documentation, sometimes it is not.

The final CI run before the hotfix release.

As I write these final lines, I kicked off a continuous integration build running some tests. Once the tests successfully pass, I will merge my changes and create a new release. Release that I will use to publish this blog post on Minds.com.

As you would expect it, the build failed. No seriously.

The release tagging step which is one of the final steps blew up. It tried to increase version 0.1.9 to 0.1.10 but that later version already exists. As it turns out, the code listing versions and sorting them rightfully considers the existing 0.1.10 version as anterior to 0.1.9. That’s a problem for a different day but since the release is ready, we can move to the first major version 1.0.0.

I’ll sort that tag versioning issue another day since I do need my sleep as I will play two football games tomorrow after work. Definitely gonna need the energy to perform. Enough chit-chat, let’s push this first major release out and wrap this post.

Version 1.0.0 is ready to go!

Go try the Idea Publisher now, and know that I am still offering 300 MINDS tokens to whoever brings me a worthy logo for the plugin. If you’re not an artist, you can still contribute by trying out the plugin and letting me know how it treats you. Hopefully, my next time fixing the Idea Publisher will be in a distant future. As distant as possible.

Cover by ArtHouse Studio:

Be First to Comment

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    %d bloggers like this: