Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scarstens/454c2633f0e5083353b8 to your computer and use it in GitHub Desktop.
Save scarstens/454c2633f0e5083353b8 to your computer and use it in GitHub Desktop.
Seths Plugin Boiler Plate Idea - this is the "no singletons" version
<?php
/**
* Plugin Name: Fansided VIP
* Plugin URI: http://fansided.com/
* Description: All the amazing business logic Fansided provides to WordPress installs.
* Author: sethcarstens
* Version: 1.0.0
* Author URI: http://www.linkedin.com/in/sethcarstens/
* License: Privately Copyright - do not redistribute.
* Text Domain: fs_vip
*
* @package fs_vip
* @category plugin
* @author Seth Carstens <seth.carstens@fansided.com>
*/
//avoid direct calls to this file, because now WP core and framework has been used
if ( ! function_exists( 'add_filter' ) ) {
header('Status: 403 Forbidden'); header('HTTP/1.1 403 Forbidden'); exit();
}
if(!class_exists('fansided_vip'))
{
class fansided_vip
{
public $installed_dir;
public $installed_url;
public $admin;
public $modules;
/**
* Construct the plugin object
*
* @since 1.0
*/
public function __construct()
{
$this->modules->count = 0;
$this->installed_dir = dirname(__FILE__);
$this->installed_url = plugins_url('/', __FILE__);
#confirm PHP_TAB exists for use in printing
if(!defined('PHP_TAB')) define('PHP_TAB',"\t");
#extend current blog global variable with all blog details
$GLOBALS['current_blog'] = get_blog_details($GLOBALS['current_blog']->blog_id);
$GLOBALS['current_blog']->description = get_bloginfo('description');
#initialize
add_action('init', array($this,'init'));
#loaded during init because loading during admin_init is too late for many admin functions
if(is_admin()) add_action('init', array($this,'admin_init'));
} // END public function __construct
/**
* Initialize the plugin - for public (front end)
*
* @since 1.0
* @return void
*/
public function init() {
//always load includes folder php files
$this->load_classes();
#add meta data to HTML HEAD tag
if(class_exists('fansided_social_meta')) $this->modules->fansided_social_meta = new fansided_social_meta($this);
if(class_exists('kses_custom_tag_allowances')) $this->modules->kses_custom_tag_allowances = new kses_custom_tag_allowances($this);
}
/**
* Initialize the plugin - for admin (back end)
*
* @since 1.0
* @return void
*/
public function admin_init() {
//if user can edit posts, load VIP admin
if(current_user_can('edit_others_posts')) {
require_once($this->installed_dir.'/admin/fansided-vip-admin.php');
$this->admin = new fansided_vip_admin($this);
}
}
/**
* Activate the plugin
*
* @since 1.0
* @return void
*/
public static function activate()
{
} // END public static function activate
/**
* Deactivate the plugin
*
* @since 1.0
* @return void
*/
public static function deactivate()
{
} // END public static function deactivate
/**
* Loads PHP files in the includes folder
*
* @since 1.0
* @return void
*/
protected function load_classes() {
// load all files with the pattern *.php from the directory inc
foreach( glob( dirname( __FILE__ ) . '/includes/*.php' ) as $class ) {
require_once $class;
$this->modules->count++;
}
}
} // END class fansided_vip
} // END if(!class_exists('fansided_vip'))
/**
* Build and initialize the plugin
*/
if(class_exists('fansided_vip'))
{
// Installation and uninstallation hooks
register_activation_hook(__FILE__, array('fansided_vip', 'activate'));
register_deactivation_hook(__FILE__, array('fansided_vip', 'deactivate'));
// instantiate the plugin class
$fansided_vip = new fansided_vip();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment