Last active
December 16, 2015 14:59
-
-
Save engelen/5452624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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