Today, I had to make use of a customized PHP script that I created some time in the past in a brand new WordPress utility. Instead of growing a WordPress plugin to care for this current code, I make a choice as an alternative to make use of WordPress at once within my script.
Using WordPress within your script is a brilliant possibility you probably have a large number of customized PHP code.
When you’ve got a big PHP code base out of your earlier construction efforts. There are in most cases different libraries within your code, equivalent to Symfony, Zend Framework, Pear, and many others, that you do not want to take aside. You have running code and you wish to have it to stick in combination.
In my case, I had created a kind for information assortment for a shopper. But this used to be no unusual shape. It had over 100 shape variables. They have been made up of textual content enter, radio packing containers, checkboxes, and textarea’s. I sought after to make use of this way at once within my WordPress utility. Plus I sought after the mixing to simple.
The answer used to be in reality fairly easy.
Existing PHP Code
For instance, suppose that is my current PHP code (this can be a easy script as an example this level).
But the issue is, this is best the shape to assemble the knowledge. What about the feel and appear of the prevailing website online. How can I am getting the above code to appear to be the similar template format of my WordPress utility.
For instance, one answer is so as to add the uncooked HTML. But this is each time eating, and it’s not dynamic. If the WordPress template adjustments, I’ve to head in right here and manually exchange it once more. Not one thing I wish to do.
My PHP Form Page
But that would not precisely paintings. I must fit the navigation, come with the manner sheets, and ensure the HTML matched precisely the feel and appear of my primary web page.
The Better Solution
Instantiate WordPress, and use the inbuilt purposes within your code.
Do you notice how simple that used to be? WordPress is instantiated proper in my web page. Then I instruct the web page to name the header and footer purposes of WordPress.
Let PHP do the paintings. There is not any want to reproduction the WordPress code in natural HTML when you’ll be able to have it generated robotically via WordPress itself.
The added receive advantages is if the principle WordPress website online format ever adjustments, the template wrapping your customized PHP code will replicate the ones adjustments in an instant.