Lesson 3 – The MainWP Development Add-on – Individual Site Subpage

Individual Site Subpage

class-mainwp-development-individual.php

What’s this Class for?

This class is where all the UI code & any form handlers will go for the Individual Sites Page

Namespaces

Each PHP file with a MainWP add-on will need a unique namespace added to the top of each file just under the opening.

<?php
namespace MainWP\Extensions\Development;

Class Declaration

Just like with previous class you will want to rename your class declaration by replacing the word “Development” with your add-ons name – everything else may stay the same here:

<?php
class MainWP_Development_Individual {
  /**
  * Static variable to hold the single instance of the class.
  *
  * @static
  *
  * @var mixed Default null
  */
  static $instance = null;
  public static $instance = null;
  /**
  * Get Instance
  *
  * Creates a public static instance of this class file.
  *
  * @static
  *
  * @return MainWP_Development_Individual
  */
  public static function get_instance() {
    if ( null == self::$instance ) {
      self::$instance = new self();
    }
    return self::$instance;
	}
}

Class Methods

__construct()

PHP allows developers to declare constructor methods for classes. Classes that have a constructor method call this method on each newly created object, so it is suitable for any initialization that the object may need before it is used.

This is where we will load all of our actions, and filters & Initiate the rest of our add-ons class files.

<?php
public function __construct() {
  add_action( 'admin_init', array( &$this, 'admin_init' ) );
}
?>

admin_init()

This method may be used to load any actions or filter & fire off and form handler methods if needed during admin initiation.

<?php
public function admin_init() {

}

render_individual_page()

This method would be used to handle any form submissions on the Add-ons Settings Page.

<?php
public function render_individual_page() {
  do_action( 'mainwp_pageheader_sites', 'DevelopmentIndividual' );
  echo "Individual Page Placeholder";
  do_action( 'mainwp_pagefooter_sites', 'DevelopmentIndividual' );
}
?>