Architecture of WordPress Plugin
-
Good afternoon. I’m developing a small plugin for WordPress and I’m facing a problem. I had to put a redirect on the administrative page of the plugin. When I used the wp-redirect function, I realized that it could not be done in the obvious way. The administrative page of the plugin is executed after sending the server headers, because it is embedded in the administrative panel template. The first thing that I wanted to do was to get a way to solve my problem. This is what is most important to me right now and is slowing down development.
But I have also seen an even more global architecture problem. When using administrative pages as the main functional blocks, the model code and the template code are not separated. I have indicated only one possible problem of this approach. I have created several classes and can use them at the top of the admin plugin pages. In fact, I just call some logic inside the template. This is inflexible and uncomfortable. I have read official WordPress materials such as Plugin Handbook. I have also used scaffolds and scaffolds to use literate architecture. But I never found an effective way to separate the code.
Eventually, I saw a plugin-platform for developing https://github.com/tombenner/wp-mvc plugins. It seemed to me interesting enough. It has an ORM for tables and auxiliary functions for creating forms. At the moment I’m not ready to use such solutions, because I don’t have enough experience in development of wordpress plug-ins and I don’t realize the risks of all the risks. I would like to get a solution for my problem based on the classic WordPress architecture, but with code separation.
I imagine it this way. I plug in the code of logic where I can define what files I should use in this script and redirect it if I need it. It could be a template_redirect hook or some other place. The administrative page can be a template to which data will be transmitted. As I said, I don’t know how to implement a good pattern due to lack of experience. For example, I don’t know how to pass an array with prepared data in hook to the admin plugin page file. I ask you to give me an example of a tested and proven architecture that matches the WordPress patterns but is more thoughtful.
- The topic ‘Architecture of WordPress Plugin’ is closed to new replies.