Hello Indiehackers,
I am not new to coding, but I don't seem to grasp things as quickly as I would like to. I sponged up the information to become a paramedic quickly after someone showed me the fundamental errors I was making.
I think the same thing will have to be done for me with coding.
I have set out to make a very complicated wordpress plugin with the help of tutorials, chatGPT, Bard, etc. I have used a boilerplate for the primary file layout, and using the wordpress dev handbook, I have been trying to make all the essential parts before I move on to the more complicated features.
I still cannot grasp writing the code, but I am more understanding when reading it. However, I still cannot seem to get things right.
The WP dev handbook for the activation hook and the functions around that seem limited; they do have an expanded guide on it, but that seems to cause a lot of errors in VSCode. I don't know if this is just VSCode saying it or whether it will break the system.
I have VSCode wordpress playground, which is impressive, and I cannot recommend it enough for ease of use.
Can anyone help me with a few little issues I have run into, guide me and maybe show me the error in my ways with what I have done, as I cannot understand some of the issues I have run into?
EDIT: I have finally made a repository here: https://github.com/EVCV/twentyi-api-integration
It was working on wordpress playground but no longer works at all in the local environment, so I will be going over the code from the top to work out what the causes are.
It’s a bit hard to help like this. Why don’t you share your code and let us know where you’re stuck so we can take a look :)
https://github.com/EVCV/twentyi-api-integration
Hi, thank you for this reply.
I tried to make a repository but i couldn't get it to work and then I got angry as wasn't in the mood haha.
I will try sort out a repository later and share the link.
This comment was deleted 3 years ago
So, setting aside the question of how you're currently set up (fwiw, I like VSCode pointing directly at the plugin directory of a locally-installed wp and I like the Local app from Flywheel for running locally), how clear are you on the basic architecture of of WordPress? A couple of things I think programmers sometimes get hung up on:
The whole WordPress cycle (ok, almost the whole) happens every time a page is requested. If you have a call that registers something or other, it will register it for each and every page request. And it's a fresh universe each and every time.
Your plugin code runs when WordPress hits the moment where it runs all the plugin code. If you want actual control over when something in your plugin runs, you've got to hook the action that occurs in the timeframe you want. The obvious example is the "init" action, but there are all sorts of hooks for things like "when the post is processed but hasn't been displayed yet".
Actions and filters are the same thing -- they are hooks for callbacks to your functions, but they are conceptually different. Actions are just normal hooks. Filters send you data that you can change on the fly and return. So you could use a filter hook to change the word "the" to appear red everywhere it comes up in a post, to take a very contrived example.
There are kind of two styles of writing plugins. One is just "normal" PHP, except that the header takes a particular format in the comments that identifies it as a plugin. The other approach is to use PHP's support for classes. These look rather different and mysterious if you're not familiar with them, even though they do the same things.
Relatedly, fancier plugins add in lots of things that make them much harder to parse. They use tools like composer to manage PHP libraries they are including; the create classes for different kinds of tasks and isolate those classes in separate folders/files; they support internationalization and so have lots of whacky looking code to translate things before displaying them and have a folder full of translation files.
The main thing, though, is to get familiar with the more frequently used core wordpress calls and the use of action and filter hooks.
Thank you for taking the time to write this reply. I guess overall I am not hugely familiar with the architecture.
So far my plugin is a boilerplate folder with the activation hook creating a db table and entry, then a menu and sub menu page system.
This has given me a lot of insight already into hooks, actions, filters etc.
I have found the easiest way to get to this point was create simple PHP with a header for wordpress plugin and then get AI to help me convert it to the file structure of the boilerplate I have.
An interesting approach. Not sure it doesn't make life harder than it would be if you read a book or took an online course, but you'll pick it up over time either way.
I have tried courses, I have tried books (books as a whole seem a no go with me for some reason) and none have helped. I might be okay if I had a mentor that could actually talk to me about issues.
First of all, you should setup an actual webserver and install WordPress instead of using VSCode WordPress playground, this will allow you to view your changes and track any errors, just like a real website on http://localhost. I suggest WAMP, it's easy to setup.
Second, you can't build a complex plugin with AI with no coding skills or PHP & WordPress experience. I've tried simple stuff with GPT, sometimes it works, sometimes it just come up with non-existing WP hooks and functions, or completely non-working solutions. So, if you aren't able to look at the code and know what's wrong with it, you'll have a hard time getting anything working. We're still talking about simple stuff, I can't imagine it building a whole complex plugin.
Third, get yourself fimilar with PHP and WordPress Codex first.
Thank you for the reply.
Wordpress playground sets up a webserver on localhost but I do also have a live web server set up. I have WAMP also but as playground does the same thing its a bit daft to have both open.
I like the playground as critical errors you can just change the code, save it and then go back and the server is fixed, rather than on my live servers having to delete the plugin and then try again (unless i can edit the file which i have not been able to do up to now).
I was using this as a project to learn PHP and Codex with but their dev guide contradicts itself a lot which has caused me to get confused with it all.
If you're using WAMP, you can just add the project folder to VS Code, make changes, save and refresh the page, you don't need to delete anything.
For the Codex, do you mind pointing where the contraction is? Maybe we can help.
I have started this tonight, going from wordpress playground to a local install has completely broken the code. I guess the playground was not as good?
There is no way the local install can break your code as both of them are completely 2 different things. You're just going to host your code on the local environment, if it's already broken, that's something you need to solve by modifying the code. Also, you might have DEBUG mode enabled on local env, which will show you any errors with your code by default.
If you couldn't ensure that you VSCode are set-up properly for WordPress debugging, instead of meddling that for hours or even days, just make it plain simple and develop & live test the code in a fresh install of WordPress. Write codes, run the WP pages and see what happen.
Hi, Thank you for the reply and the information, can i ask what extensions or settings do you recommend for debugging wordpress on VSCode? I have a live staging web server and also a local host server which I can test this on already.