Introduction & Setup
WordPress Dev plugin is something I wanted to do in a while. So I jump into it, fumble by way around – and found my way. Here are my notes, may they be useful to those of you who are just getting started on doing wordpress dev. My PHP skill is very minimal, so pardon me if I made rookie mistakes here.
Editor & MAMP
- Get your favorite editor, I recommend ATOM.
- Download MAMP.
For those who are more used to XAMPP or LAMP – MAMP is those, but for mac
- Start MAMP normally and start servers. You should see MAMP start screen.
Configuring htdocs folder (Optional)
- I don’t like having my htdocs under the original location.
So, I made a new directory under my data partition, which I have symlinked to ~/DATA. I prefer my HTDOCS to be located inside this partition, so I made a directory in ~/DATA/_HTDOCS.
note: I prefer putting it under my data partition because I took regular backup of it.
- Then, I removed /Applications/MAMP/htdocs, and made a symlink
1ln -s $HOME/DATA/_HTDOCS htdocs
- Reboot MAMP. It will now use the new HTDOCS location.
WordPress Action Hooks Architecture
This is the picture I wish someone had shown me earlier
Basically – WordPress breaks down its rendering activity into a series of action. Example, when front-end page loads, or when admin page loads – these are all actions. WordPress register event IDs in different parts of different actions, such as – before a page loads, or before the admin notification is rendered (if any). You can attach your function into these event IDs – called hooks – so that when these event triggers, your function is then called. From there, WordPress action is chained – leading into the entire WordPress system’s behavior.
In this way, you can inject all kind of functionality into WordPress – but you need to know what kind of hooks existed on what kind of situation. Say, if you want to register your own menu in the admin panel, you’ll want to call it AFTER the admin page initiates, but BEFORE the admin content is loaded, preferrably, BEFORE the admin menu is loaded. Well, there is such a hook, it’s called admin_menu.
So by knowing which hook existed, you can latch a function (or multiple functions) into the ones you want. Then when the action fires, your function will be hooked in the execution chain.
Where can we find a list of all Action hooks?
Recovering from INNODB Crash due to hard shutdown
Happens when you do a hard shutdown – a forceful shutdown by long pressing power button, or in my case, when the MBA runs out of battery. If you don’t take regular backup / mysql dump – then you will need this recovery steps.
On restart, DB may not start because the DB doesn’t have a chance to do clean up work, it’s basically forced to drop act with its pants down. So, a recovery action is needed.
- in MAMP when starting server – MySQL server won’t start (no tick box)
- When tailing the log file [/Applications/MAMP/logs/mysql_error_log.err] mysqld indicates that there are error in INNODB due to inconsistent structure, and actually advise to put innodb_force_recovery>0 in config file.
- Go to /Applications/MAMP – this is where the my.cnf file need to be located. It is not there by default, so one need to be created.
- Create a my.cnf file if there is none. If you already made your own, then modify it. Add innodb_force_recovery=1 into [mysqld] group
- Monitor log file [/Applications/MAMP/logs/mysql_error_log.err]
- Start the MySQL Server again via MAMP – it should succeed. Check log file to indicate that recovery procedure is done.
- If successful, stop the MySQL DB via MAMP. (“Stop Servers”)
- edit the file again, and flip back innodb_force_recovery back to 0. Save the file. This is because, not all SQL operations / wordpress DB calls can be done with innodb_force_recovery on 1. So you only want to flip it to 1 when you are doing recovery, when you are done, flip it back to 0 and restart, so things are as they are.
- Start the MySQL server again via MAMP. Check back – everything should be back to normal.