Lesson 3 – The MainWP Development Add-on – Overview Page
Overview Page
class-mainwp-development-overview.php
What’s this Class for?
This class is where all the UI code & any form handlers will go for the Add-on overview 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 the previous class you will want to rename your class declaration by replacing the word “Development” with your add-on name – everything else may stay the same here:
<?php
class MainWP_Development_Overview {
/**
* 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_Admin
*/
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() {
}
?>handle_settings_post()
This method would be used to handle any form submissions on the Add-ons Settings Page.
<?php
public function handle_settings_post() {
}render_tabs()
This method is used to display the main add-ons page tabs. The word “development” & “Development” will need to be replaced in this file.
<?php
public static function render_tabs() {
$curent_tab = 'dashboard';
if ( isset( $_GET['tab'] ) ) {
if ( 'settings' == $_GET['tab'] ) {
$curent_tab = 'settings';
}
}
?>
<div class="ui labeled icon inverted menu mainwp-sub-submenu">
<a href="admin.php?page=Extensions-Mainwp-Developer-Extension&tab=dashboard" class="item <?php echo ( $curent_tab == 'dashboard' ? 'active' : '' ); ?>"><i class="tasks icon"></i> <?php _e( 'Dashboard', 'mainwp-developer-extension' ); ?></a>
<a href="admin.php?page=Extensions-Mainwp-Developer-Extension&tab=settings" class="item <?php echo ( $curent_tab == 'settings' ? 'active' : '' ); ?>"><i class="cog icon"></i> <?php _e( 'Settings', 'mainwp-developer-extension' ); ?></a>
</div>
<?php if ( $curent_tab == 'dashboard' || $curent_tab == '' ) : ?>
<?php echo "Dashboard Placeholder"; ?>
<?php endif; ?>
<?php if ( $curent_tab == 'settings' ) : ?>
<?php echo "Settings Placeholder"; ?>
<?php endif; ?>
}
?>