My Library WordPress Plugin

I am so proud of this. It took me a few months to get it right. And wow… it was hard to mix PHP and JavaScript while not being able to explain this to chatGTP. It took less time to just google it. But it still helped with the manual work for the form, like, the many modifications I had to do on names of fields. I still need to update my data with books from 2019 and before, but that will take a while since I am missing a lot of details.

See how my library looks here!

So why? Why did I make this plugin? The idea was to just have it as a local file on my computer for easy access. But then I got ambitious. I got to write the plugin where I could display the HTML file (after spending endless hours trying to make it pure PHP 😅 and giving up…). But I just wanted an easy way to update the books I’ve read on my JSON file in GitHub, without doing it manually.

Firstly, we need to create some things in Github:

  1. a public repo
  2. a token
  3. an empty JSON file in the path you wish (books/library.json)

Then we code the plugin:

You can find the whole code here.

Basically, I select a book which is in my list already. Then I add the information. Warning, my star reviews are backwards because I could not figure out how to make them normal (left to right). So right now they are 54321 instead of 12345. It works for me! 😁 And I am not fighting hours for this little hobby. If I released this as an official plugin, I would have to. So think of this as alpha!

I select the book, I update the information, and I SAVE before committing. You can save multiple modifications before committing, which is pretty neat. Yet, I am still paranoid, so I commit every 3 books or so… The download button was the initial build, where I was planning on committing manually the file to the repo. But I thought if GitHub has APIs, why not make it easier? There you have it. If I were to release it, I would add a set-up page to edit the token and repo information. But if you know what you are doing, you can just manually modify everything or use this as a template for anything else you might want or data you might want to show and edit from WordPress.

Talking about showing, this is the front end code. I just open an HTML block in a WordPress page and that is it!


Leave a Reply

Your email address will not be published. Required fields are marked *