WordPress Embedded Application

I earn my living developing web applications. I usually stress the word ‘application’ because as soon as people hear the word ‘web’ they think of web sites. What I mean is I use sw frameworks like Codeigniter, Symfony or Django to create custom made-to-measure logic. Also the applications are not accessible to the public most of the time. They use the web technologies (http, html, …) that’s why the ‘web’ before the ‘applications’.

Much less often I create/maintain ‘standard’ websites, i.e. websites created in a system like WordPress. Recently I was working on an application that was supposed to be embedded into a WordPress site. The site was the tool to promote and sell a service, the application was to be the service. The site was running when I got to the project, my task was to embed the application (inherited styles, header, footer) into it without breaking/rebuilding anything. I’ve collected some bits of information from the web and combined them with my knowledge. Here is the result:

(1) I’ve created a custom page template in WordPress. Then I created a new page in the WordPress admin module using the custom template.

(2) I’ve added a new rewrite rule in my functions.php file. The rule rewrites all the URIs (e.g. http://{domain}/application/whatever1/whatever2/…) matching the pattern (http://{domain}/application/ in this example) to http://{domain}/index.php?pagename=application. That means all the application pages will be using the custom template from (1) as their landing page.

(3) I’ve included the landing page (it’s usually index.php) of the chosen framework into the custom page template from (1) and configured it as necessary. From that moment all the requests asking for http://{domain}/application/… were processed by the framework in the usual way i.e. if the URI looked like http://{domain}/application/do/something, the main application controller at http://{domain}/application called the ‘something’ method of the ‘do’ controller. At the same time all the WordPress functions were accessible within the framework. That allowed me e.g. to use its own authentication functions within the application and share the credentials between the web site and the application.