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:
- a public repo
- a token
- 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!