Front End Login WordPress Plugin – Model View Controller (MVC) – Tutorial – Part One

Pages: 1 2 3

A lot has been written about the Model-View-Controller (MVC) paradigm over the years. Let me address the subject specifically in the context of WordPress plugin development.  This is Part One of the mini-series.  It covers the “scaffolding” for MVC and the login / logout functionality.  Part Two covers user registration, lost password etc.

Setting the scene

When I talk about MVC I mean a strict separation of responsibilities.  The flow in any Web-Application is simple:  The web browser addresses the web server with a request (Get or Post), the server handles this, and presents some result to the user.

  • A request comes in and it gets routed somewhere (Controller)
  • Based on the request, actions are performed (Model)
  • If needed, the result is presented to the user’s browser (View)

To illustrate these ideas, we will implement a simple Front-End Registration / Login plugin.  This plugin will not have an admin “settings” interface.

The material is presented as a tutorial, and has two parts.  In this Part One, we set the scene, implement the “scaffolding” and create the Login / Logout functionality. In Part Two we will implement front end registration, password changes, and the “Oops I forgot my password” functionality.

The View

Plugins present data to the user in two different scenarios, in the “front-end”, or as part of the administrative “settings” interface.  Front-end “views” are typically implemented by the use of shortcodes.

The Model

The “Model” contains the “Business Logic”.  This may-or-may-not include database access.  More important is the separation of responsibilities.  The Model gets requests from the Controller, acts upon them, and causes things to happen.

The Controller

This is the “traffic cop”.  The Controller handles the requests coming from the web-browser, and directs them to be handled. Typically, the Controller will hand off to the Model.

Plugin Requirements

  • For any user, other than the administrator, limit access to the wp-admin area.  All activities listed below have to happen on the front end.
  • Allow a user to register by selecting a username and by providing a valid email address.
  • Upon registration, send an email with an initial password.
  • Provide a sign-in form on a page, with a link to a “lost password”.
  • Provide a form to reset the password (front-end).  This form has to accommodate both logged-in users and referrals from “lost password” links.

We will flesh out more detailed  requirements as we build the plugin.

Plugin Structure

We will have a plugin directory, with the main plugin program file.  We will then have a “classes” directory where all the needed classes reside.  Furthermore, to keep things clean, we will use namespacing.  Model, View and Controller will be implemented as classes.

Plugin Directories and Files

Plugin Directories and Files


In addition to the classes sub-folder, we created a css sub-folder.

Pages: 1 2 3