A module is a modular, plug and play, custom post type (CPT) solution developed within the site application scope. For example, if your site or project needs a CPT solution (such calendar events or testimonies), rather than using a plugin like “types” to create a post type in the database where it can not be included within your version control process (such as git), a Div Module will provide you with a simple programmatic solution that even a competent front-end developer could implement.
Not only will your CPT be registered, but you will have a single and page template for your custom post type easily prepared within your module scope so that you can potentially reuse you module on another project either as-is or at the very least as a boilerplate for yourself.
The purpose of a module is to give a developer a unrestricted platform to create custom solutions for their projects within the functionality scope that WordPress has already established (whether that be within a plugin or the Div Blend site application approach. The Div Module abstract class source code can be seen and reviewed here
Implementation
All Site Application modules are hosted in the modules directory (/mu-plugins/{site-application}/modules/). You can start with the example module included in the Div Starter boilerplate found here
- Extend the DIV_Module abstract class
class testimony extends DIV_Module{ public function __construct(){ $this->labels = array(); $this->args = array( 'supports' => array('title','thumbnail'), 'menu_icon' => 'dashicons-megaphone', 'menu_position' => 3, 'public' => true, 'publicly_queryable' => false, ); parent::__construct(); #do not remove this } } #yes that's it!
- Include Templates and Fields
The default file names can be changed be passing a new parameter value. Typical module may look like this: