Skip to content

Instantly share code, notes, and snippets.

@engelen
Last active December 16, 2015 14:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save engelen/5452624 to your computer and use it in GitHub Desktop.
Save engelen/5452624 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: My Plugin
Author: Jesper van Engelen
Author URI: http://jepps.nl
*/
/**
* Main plugin class for My Plugin
*/
class JWMP_MyPlugin
{
/**
* The one (and only) instance of this class
*
* @var JWMP_MyPlugin
*/
private static $_instance = null;
private function __construct() {}
private function __clone() {}
/**
* Get the instance of this class, insantiating it if it doesn't exist yet
*
* @return JWMP_MyPlugin Class instance
*/
public function get_instance()
{
if (!is_object(self::$_instance)) {
self::$_instance = new JWMP_MyPlugin();
self::$_instance->init();
}
return self::$_instance;
}
/*****************
* Actual plugin functionality
****************/
/**
* Set up plugin functionality
* This is what would be in __construct if we were following a similar approach without using the singleton-pattern
*/
public function init()
{
// Actions
add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
add_action('init', array(&$this, 'handle_posttypes'));
}
/**
* Register and enqueue scripts and styles for the admin area
*/
public function admin_enqueue_scripts()
{
// Scripts
wp_register_script('mp-admin', plugins_url('public/js/admin.js', __FILE__));
wp_enqueue_script('mp-admin');
}
/**
* Register custom post types and taxonomies
*/
public function handle_posttypes()
{
// Register custom post type call
}
}
JWMP_MyPlugin::get_instance();
?>
<?php
/*
Plugin Name: My Other Plugin
Author: Jesper van Engelen
Author URI: http://jepps.nl
*/
/**
* Prevent the My Plugin plugin from registering and enqueueing admin scripts
*/
function jwmop_prevent_mp_admin_scripts()
{
if (class_exists('JWMP_MyPlugin')) {
remove_action('admin_enqueue_scripts', array(&JWMP_MyPlugin::get_instance(), 'admin_enqueue_scripts'));
}
}
// Actions
add_action('plugins_loaded', 'jwmop_prevent_mp_admin_scripts');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment