/**********************************************************************************
JW Simple Options
Author: Jerry Wood Jr.
Email: jay@plugish.com
WWW: http://plugish.com
This sofware is provided free of charge. I use this in my own projects and
it's ideal for small options pages when you don't feel like writing the
HTML to accompany it. This work is Licensed under the Creative Commons
Attribution Share-Alike 3.0 License. All I ask, is you don't sell the
software as is. You're more than welcome to include it in a package
as long as you give the appropriate credit.
**********************************************************************************/
class JW_SIMPLE_OPTIONS{
/**
* @access private
* @var string Class version number.
*/
private $ver = '1.1';
/**
* @access private
* @var array() A map of the options data.
*/
private $options;
/**
* Location of the plugin/theme menu.
*
* Accepts: page, link, comment, management, option, theme, plugin, user, dashboard, post, or media.
* @access private
* @var string Default: 'new'
*/
private $menu_type = 'new';
/**
* Used in options saving/gathering and menu data.
*
* @access private
* @var string Default: 'jw_'
*/
private $prefix = 'jw_';
/**
* Reader friendly menu name.
*
* @access private
* @var string Default: 'JW Options'
*/
private $menu_title = 'JW Options';
/**
* Capability needed by users to see this menu.
*
* @access private
* @var string Default: manage_options
* @see add_menu_page()
*/
private $cap = 'manage_options';
/**
* URL friendly name of the menu, ie. 'options_page'
*
* Will be prefixed by prefix variable.
* @access private
* @var string Default: 'options_page'
*/
private $slug = 'options_page';
/**
* Icon of the top-level menu. Absolute URL.
*
* @access private
* @var string Default: NULL
*/
private $icon = NULL;
/**
* Menu position of the top-level menu. Used only if menu_type is 'new'.
*
* @access private
* @var integer Default: NULL
*/
private $pos = NULL;
/**
* Used in menu pages and throughout the plugin
*
* @access private
* @var string Defaults to "JW Options Panel"
*/
private $plugin_title = 'JW Options Panel';
/**
* Used in menu generation and hooks.
*
* @access private
* @var string
*/
private $hook;
function JW_SIMPLE_OPTIONS($ops){
$this->__construct($ops);
}
function __construct(array $ops){
// Setup variables
$this->plugin_title = empty($ops['plugin_title']) ? $this->plugin_title : $ops['plugin_title'];
$this->menu_title = empty($ops['menu_title']) ? $this->menu_title : $ops['menu_title'];
$this->cap = empty($ops['capability']) ? $this->cap : $ops['capability'];
$this->slug = empty($ops['slug']) ? $this->prefix.$this->slug : $ops['slug'];
$this->options = empty($ops['opData']) ? $this->options : $ops['opData'];
$this->icon = empty($ops['icon_url']) ? $this->icon : $ops['icon_url'];
$this->pos = empty($ops['menu_pos']) ? $this->pos : $ops['menu_pos'];
$this->prefix = empty($ops['prefix']) ? $this->prefix : $ops['prefix'];
add_action('admin_init', array(&$this, 'register_admin_deps') );
add_action('admin_menu', array(&$this, 'load_admin_menu') );
add_action('admin_enqueue_scripts', array(&$this, 'load_admin_deps') );
}
/**
* Builds an array of check boxes.
*
* @param string $key Option identifier minus prefix.
* @param array $data Associative array of data to display.
*/
public function buildCheckFields($key, $data, $def = false){
$opData = get_option($this->prefix.$key, $def);
?>
return $output;
}
/**
* Builds an array of data, comparable to a matrix.
*
* Also provides neat javascript functionality such as adding/removing rows.
* @param string $key Option identifier minus prefix.
* @param array $fields A regular array of data identifiers, ie. array('field1', 'field2').
*/
public function buildDataArrayFields($key, $fields, $showhead = false){
$opData = get_option($this->prefix.$key);
?>
[+] Add Row