Skip to content

Instantly share code, notes, and snippets.

@cyberwani
Forked from dnaber-de/default_plugin.php
Created December 28, 2012 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberwani/4396247 to your computer and use it in GitHub Desktop.
Save cyberwani/4396247 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: New_Plugin
Description: Empty Plugin to fill with your code
Version: 0.0
Author: David Naber <kontakt@dnaber.de>
Author URI: http://dnaber.de
*/
# @charset utf-8
# @todo Replace New_Plugin with your class name
# @todo Create a directory ./i18n with .mo files, if needed
# @todo Un-comment actimation/deactivation hooks, if needed
# @todo Un-comment mce_external_languages filter, if needed
if ( ! function_exists( 'add_filter' ) )
exit;
if ( ! class_exists( 'New_Plugin' ) ) {
add_action( 'init', array( 'New_Plugin', 'init' ) );
#register_aktivation_hook( plugin_basename( __FILE__ ), array( 'New_Plugin', 'activate' ) );
#register_deactivation_hook( plugin_basename( __FILE__ ), array( 'New_Plugin', 'deactivate' ) );
register_uninstall_hook( plugin_basename( __FILE__ ), array( 'New_Plugin', 'uninstall' ) );
class New_Plugin {
/**
* Textdomain
*
* @access public
* @const string
*/
const TEXTDOMAIN = 'New_Plugin';
/**
* Version
*
* @access public
* @const string
*/
const VERSION = '0.0';
/**
* Option Key
*
* @access public
* @const string
*/
const OPTION_KEY = 'New_Plugin_Options';
/**
* $uri
*
* absolute uri to the plugin with trailing slash
*
* @access public
* @static
* @var string
*/
public static $uri = '';
/**
* $dir
*
* filesystem path to the plugin with trailing slash
*
* @access public
* @static
* @var string
*/
public static $dir = '';
/**
* $default_options
*
* Some settings to use by default
*
* @access protected
* @static
* @var array
*/
protected static $default_options = array(
#'foo' => 'bar',
);
/**
*
* $options
*
* @access protected
* @var array
*/
protected $options = array();
/**
* init
*
* @access public
* @static
* @return void
*/
public function init() {
self :: $uri = plugin_dir_url( __FILE__ );
self :: $dir = plugin_dir_path( __FILE__ );
new self( TRUE );
}
/**
* constructor
*
* @access public
* @param bool $hook_in
* @return void
*/
public function __construct( $hook_in = FALSE ) {
$this->load_options();
$this->load_textdomain();
if ( $hook_in ) {
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
}
}
/**
* admin menu
*
* @access public
* @return void
*/
public function admin_menu() {
add_submenu_page(
'options-general.php',
__( 'New Plugin Settings', self :: TEXTDOMAIN ),
__( 'New Plugin Settings', self :: TEXTDOMAIN ),
'manage_options',
'new_plugin',
array( &$this, 'add_admin_submenu_page' )
);
}
/**
* an admin submenu page
*
* @access public
* @return void
*/
public function add_admin_submenu_page () {
if ( 'POST' === $_SERVER[ 'REQUEST_METHOD' ] ) {
if ( get_magic_quotes_gpc() ) {
$_POST = array_map( 'stripslashes_deep', $_POST );
}
# evaluation goes here
# saving
if ( $this->update_options() ) {
?><div class="updated"><p> <?php _e( 'Settings saved', self :: TEXTDOMAIN );?></p></div><?php
}
}
?>
<div class="wrap">
<h2><?php _e( 'New Plugin settings', self :: TEXTDOMAIN );?></h2>
<div id="poststuff" class="metabox-holder has-right-sidebar">
<div id="side-info-column" class="inner-sidebar">
<div id="side-sortables" class="meta-box-sortables ui-sortable">
<div class="postbox">
<h3 class="handle"><?php _e( 'Aside', self :: TEXTDOMAIN );?></h3>
<div class="inside">
</div>
</div>
</div>
</div>
<div id="post-body">
<div id="post-body-content">
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
<div class="postbox inside">
<h3><?php _e( 'New Plugin options', self :: TEXTDOMAIN );?></h3>
<div class="inside">
<form method="post" action="">
<p>
<input type="submit" class="button-primary" name="submit" value="<?php _e( 'Save settings', self :: TEXTDOMAIN );?>" />
</p>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div><?php
}
/**
* load_textdomain
*
* @access protected
* @return void
*/
protected function load_textdomain() {
# load plugin textdomain
load_plugin_textdomain( self :: TEXTDOMAIN, FALSE, basename( plugin_basename( __FILE__ ) ) . '/i18n' );
# load tinyMCE localisation file
#add_filter( 'mce_external_languages', array( &$this, 'mce_localisation' ) );
}
/**
* mce_localisation
*
* @access public
* @param array $mce_external_languages
* @return array
*/
public function mce_localisation( $mce_external_languages ) {
if ( file_exists( self :: $dir . 'i18n/mce_langs.php' ) )
$mce_external_languages[ 'inpsydeOembedVideoShortcode' ] = self :: $dir . 'i18n/mce-langs.php';
return $mce_external_languages;
}
/**
* load_options
*
* @access protected
* @return void
*/
protected function load_options() {
if ( ! get_option( self :: OPTION_KEY ) ) {
if ( empty( self :: $default_options ) )
return;
$this->options = self :: $default_options;
add_option( self :: OPTION_KEY, $this->options , '', 'yes' );
}
else {
$this->options = get_option( self :: OPTION_KEY );
}
}
/**
* update_options
*
* @access protected
* @return bool True, if option was changed
*/
public function update_options() {
return update_option( self :: OPTION_KEY, $this->options );
}
/**
* activation
*
* @access public
* @static
* @return void
*/
public static function activate() {
}
/**
* deactivation
*
* @access public
* @static
* @return void
*/
public static function deactivate() {
}
/**
* uninstallation
*
* @access public
* @static
* @global $wpdb, $blog_id
* @return void
*/
public static function uninstall() {
global $wpdb, $blog_id;
if ( is_network_admin() ) {
if ( isset ( $wpdb->blogs ) ) {
$blogs = $wpdb->get_results(
$wpdb->prepare(
'SELECT blog_id ' .
'FROM ' . $wpdb->blogs . ' ' .
"WHERE blog_id <> '%s'",
$blog_id
)
);
foreach ( $blogs as $blog ) {
delete_blog_option( $blog->blog_id, self :: OPTION_KEY );
}
}
}
delete_option( self :: OPTION_KEY );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment