WordPress integration in PHP scripts
- admin
- 0
General description
Today, I had to use a custom PHP script I created a while back in a new WordPress app. Rather than develop a WordPress plugin to handle this existing code, I choose to use WordPress directly within my script.
Using WordPress within 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 usually other libraries within your code, such as Symfony, Zend Framework, Pear, etc., that you don’t want to take apart. You have a working code and you want it to stay together.
In my case, I had created a data collection form for a client. But this was not an ordinary way. It had over 100 form variables. They consisted of text input, radio boxes, check boxes, and text areas. I wanted to use this form directly within my WordPress application. More wanted the integration to be easy.
The solution was actually quite simple.
Existing PHP code
For example, suppose this is my existing PHP code (it’s a simple script to illustrate this point).
But the problem is that that’s just the way to collect the data. What about the appearance of the existing site? How can I make the above code look like the same template layout of my WordPress app?
For example, one solution is to add the raw HTML code. But that is very time consuming and not dynamic. If the WordPress template changes, I have to go in here and change it back manually. It’s not something I want to do.
My PHP Form Page