Skip to content

Instantly share code, notes, and snippets.

@solepixel
Last active December 14, 2015 18:19
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 solepixel/5129026 to your computer and use it in GitHub Desktop.
Save solepixel/5129026 to your computer and use it in GitHub Desktop.
<?php
if(class_exists('Plugin')) return;
class Plugin {
var $debug = false;
var $admin_page = 'plugin';
var $settings = array();
var $errors = array();
/**
* Plugin::__construct()
*
* @return void
*/
function __construct(){
}
/**
* Plugin::initialize()
*
* @return void
*/
function initialize(){
add_action( 'init', array($this, '_init'));
}
/**
* Plugin::_init()
*
* @return void
*/
function _init(){
$this->settings = $this->get_settings();
if(is_admin()){
if(class_exists('WP_GitHub_Updater')){
$config = array(
'slug' => 'plugin/plugin.plugin.php', // this is the slug of your plugin
'proper_folder_name' => 'plugin', // this is the name of the folder your plugin lives in
'api_url' => 'https://api.github.com/solepixel/plugin', // the github API url of your github repo
'raw_url' => 'https://raw.github.com/solepixel/plugin/master/', // the github raw url of your github repo
'github_url' => 'https://github.com/solepixel/plugin', // the github url of your github repo
'zip_url' => 'https://github.com/solepixel/plugin/archive/master.zip', // the zip url of the github repo
'sslverify' => false, // wether WP should check the validity of the SSL cert when getting an update, see https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/2 and https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/4 for details
'requires' => '3.0', // which version of WordPress does your plugin require?
'tested' => '3.5', // which version of WordPress is your plugin tested up to?
'readme' => 'README.md', // which file to use as the readme for the version number
'access_token' => '', // Access private repositories by authorizing under Appearance > Github Updates when this example plugin is installed
);
new WP_GitHub_Updater($config);
}
wp_register_script('prfx-admin', PRFX_DIR.'/js/admin.js', array('jquery'), PRFX_VERSION);
wp_register_style('prfx-admin', PRFX_DIR.'/css/admin.css', array(), PRFX_VERSION);
add_action('admin_menu', array($this, '_admin_menu'));
}
}
/**
* Plugin::_admin_menu()
*
* @return void
*/
function _admin_menu(){
add_submenu_page('tools.php', PRFX_PI_NAME, PRFX_PI_NAME, 8, $this->admin_page, array($this, '_settings_page'));
}
/**
* Plugin::get_settings()
*
* @return
*/
function get_settings(){
return get_option(PRFX_OPT_PREFIX.'settings', array(
// defaults
));
}
/**
* Plugin::_settings_updated()
*
* @return void
*/
function _settings_updated(){
echo '<div class="updated"><p>Your settings have been updated.</p></div>';
}
/**
* Plugin::_settings_page()
*
* @return void
*/
function _settings_page(){
wp_enqueue_script('prfx-admin');
wp_enqueue_style('prfx-admin');
if(isset($_POST) && count($_POST) > 0){
foreach($_POST as $k => $v){
if(substr($k, 0, strlen(PRFX_OPT_PREFIX)) == PRFX_OPT_PREFIX){
$this->settings[$k] = sanitize_text_field($v);
}
}
update_option(PRFX_OPT_PREFIX.'settings', $this->settings);
add_action('admin_notices', array($this, '_settings_updated'));
}
include(PRFX_PATH.'/admin/settings.php');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment