Overview
Today, I had to use a custom PHP script that I created a while ago in a new WordPress application. Instead of developing a WordPress plugin to handle this existing code, I choose instead to use WordPress directly inside my script.
Using WordPress inside your script is a great option if you have a lot of custom PHP code.
When you have a large PHP code base from your previous development efforts. There are typically other libraries inside your code, such as Symfony, Zend Framework, Pear, etc, that you don’t want to take apart. You have working code and you want it to stay together.
In my case, I had created a form for data collection for a client. But this was no ordinary form. It had over 100 form variables. They were made up of text input, radio boxes, checkboxes, and textarea’s. I wanted to use this form directly inside my WordPress application. Plus I wanted the integration to easy.
The solution was actually quite simple.
Existing PHP Code
For example, assume this is my existing PHP code (it is a simple script to illustrate this point).
But the problem is, that is only the form to collect the data. What about the look and feel of the existing site. How can I get the above code to look like the same template layout of my WordPress application.
For example, one solution is to add the raw HTML. But that is both time consuming, and it is not dynamic. If the WordPress template changes, I have to go in here and manually change it again. Not something I want to do.
My PHP Form Page