I’ve broken, then fixed the favorites code

TL;DR: I fixed the favorites so everyone can use them on all the subsites, I may have wiped yours, if you’re missing all your favorite posts, let me know below.

There’s a rather nice wordpress plugin that allows users to add posts to their favorites, but it’s broken in several ways, the big ones are:

  1. No wordpress network support, we didnt’ see that too much here since there’s only about 5 sites on the MCS network, but I have about 80 sites on my TWG network, but that’s still on php 5.5
  2. No php 7.1 support, primarily brackets no longer get automatically translated into arrays when you try to append a value to it.

The guy that original wrote the script made some interesting choices like putting all the favorited posts for each user into their own serialized string in the database, which coupled with the get_user_meta’s choice to return strings and not arrays if there’s no results of the query…well that caused some headaches.  There was a point where I upgraded the site from php 5.5 to 7.1 and we got all sorts of nice performance increases, but it incidentally broke the ability of anyone new to the site to add favorite posts, which I discovered when I was trying to fix the images for the  Top 10 page over on the NSFW side of the house.  Some of the images are still broken, but the thing that really attracted my attention was the fact that the “most favorited” sections weren’t populating at all.  That was a damn week ago, but now I have that fixed I can move onto fixing the images.

The images are going to be a bigger issue to fix, because the images are broken due to a decision I made nearly 5 years ago to make a separate subdomain for the NSFW content.  The decision itself was sound and I think it’s turned out for the best.  My method of doing it though was to export all the posts that had a category of NSFW and import them into a new wordpress install.   Everything’s gone great except for some weird image and url issues with the posts, which I just recently discovered was due to a column in the wordpress database that still had the original www url on it.  While I could just find and replace those values, there’s about 20,000 posts with them and I’d rather not blow everything up.  I first ran into the problem when I redid the archives, it worked great for the main site, but good god it’s a mess to load the images from the NSFW posts. I have like three nested if statements and http_referrer checks to see if you’re asking for the post from the nsfw subdomain.

There’s a small possibility that I nuked your favorites.  I made a back up of that column before I started messing with it, so if you’re missing yours let me know below and I’ll restore them.

| Send to Facebook | Send To Twitter
  • Leave A Comment

    Notify of
    Inline Feedbacks
    View all comments