Book Image

WordPress Web Application Development

By : Rakhitha Nimesh Ratnayake
Book Image

WordPress Web Application Development

By: Rakhitha Nimesh Ratnayake

Overview of this book

Developing WordPress-powered websites is one of the standout trends in the modern web development world. The flexibility and power of the built-in features offered by WordPress has made developers turn their attentions to the possibility of using it as a web development framework. This book will act as a comprehensive resource for building web applications with this amazing framework. "WordPress Web Application Development" is a comprehensive guide focused on incorporating the existing features of WordPress into typical web development. This book is structured towards building a complete web application from scratch. With this book, you will build an application with a modularized structure supported by the latest trending technologies. "Wordpress Web Application Development" provides a comprehensive, practical, and example-based approach for pushing the limits of WordPress for web applications beyond your imagination. This book begins by exploring the role of existing WordPress components and discussing the reasons for choosing WordPress for web application development. As we proceed, more focus will be put into adapting WordPress features into web applications with the help of an informal use-case-based model for discussing the most prominent built-in features. While striving for web development with WordPress, you will also learn about the integration of popular client-side technologies such as Backbone, Underscore, and jQuery, and server-side technologies and techniques such as template engines, RSS feeds, Open Auth integration, and more. After reading this book, you will possess the ability to develop powerful web applications rapidly within limited time frames with the crucial advantage of benefitting low-budget and time-critical projects.
Table of Contents (18 chapters)
WordPress Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a custom template loader


First, we have to add a function to the WP_Theme class of the plugin to include the template loader file, as shown in the following code. Also, we have to update the constructor to call the template_init function upon plugin initialization:

public function template_init() {
    include_once 'class-wpwa-template-loader.php';
}

Create a new file named class-wpwa-template-loader.php inside the plugin class to implement the template loader. Let's implement the loader by creating a new class named WPWA_Template_Loader inside the class-wpwa-template-loader.php file:

class WPWA_Template_Loader{
    private $template_dir;
    public function __construct(){
   	 	$this->template_dir = "templates";
    }
    public function render($name,$data =  array() ){
   	   include plugin_dir_path(__FILE__).$this->template_dir."/".$name.".php";
    }
}

The folder named templates will be used to create all the templates required for the theme. Then, we will add a function named...