Currently, there are lots of sites based on WordPress running steadily in our company, except the project which I'm working on threw out so many issues. since all of us were tired and bored with endless hotfixes, it's time for us to refactor this project, or there would be more and more features immigrated and more time would be taken. That project seems more like a tool than a normal website, but I think the principles for refactoring are the same. Hoping this post will help you, let's go ahead.
Document Your Code and Project
We all know document code is necessary and useful, but most of our teammates are ignore this rule before. It's so painful for us to review the codes which were written at several months ago, and we also spent a lot of time on making the function flow clear. After we added this entry to our coding rules, we got at least two benefits that the codes are more abstract and the code repeat using between teammates is more commonly seen. For beginners, I recommend this guide, see A beginner’s guide to writing documentation.
Designing Meaningful URL
Naming things always hard, but RESTful style gives us a simple new way for naming URL resource. RESTful style URL is brief and flexible, for example, we use http://example.com/post and HTTP request methods instead of "http://example/post-create", "http://example/post-update", etc. And, it's quite easy to use RESTful API in modern PHP framework, like Laravel, all that you need to do is typing a command and press enter.
Test Everything You Have Written
In this refactor, we tried TDD with a failed ending. I mean the TDD didn't go well in our develop processing, not the unit test. We added an entry in deployment steps to trigger the unit test so that we must keep adding new tests and improving the existed tests. If there are some issues in the test case, the release will fail and a warning email will be pushed to us. For me, the most important advantage of the unit test is to keep the code running as expected. We have the confidence of changing codes which were written about months ago without worries. Also, the unit test will make your code better.