id = PluginOptions::AFFILIATE_USERS_OPTION;
$this->title = $title;
}
/**
* Add a page with plugins options to the Settings menu
*/
public function optionsPage()
{
add_submenu_page(
'sb_integrations_list',
$this->title,
$this->title,
'manage_options',
AFFILIATE_USERS_PAGE,
array($this, 'optionsPageOutput')
);
/*add_filter('plugin_action_links_' . plugin_basename(AFFILIATE_USERS_PAGE), function($links) {
$links[] = '' . __('Settings') . '';
$links[] = '' . __('Docs') . '';
return $links;
}
);*/
add_filter('plugin_action_links_' . plugin_basename(AFFILIATE_USERS_PAGE), array($this, 'mlm_plugin_action_links' ) );
}
public function mlm_plugin_action_links($links) {
$links[] = '' . __('Settings') . '';
$links[] = '' . __('Docs') . '';
return $links;
}
/**
* Create a page with plugins options
*/
public function optionsPageOutput()
{
$tab = $this->getCurrentTab();
$this->registerAssets();
?>
adminTabs(); ?>
prepare_items();
$list->display();
break;
default:
?>
tabs[$id] = $title;
return $this;
}
/**
* Add new section to settings
*/
public function addSection($id, $title, $tab = null)
{
$this->sections[$id] = array('title' => $title, 'tab' => $tab);
return $this;
}
/**
* Add new option to settings
*/
public function addOption($id, $title, $type, $section, $parameters = array())
{
$parameters['title'] = $title;
$parameters['section'] = $section;
$parameters['type'] = $type;
$this->options[$id] = $parameters;
return $this;
}
/**
* Register options
* All options will be stored to an array
*/
public function settings()
{
register_setting('option_group', $this->id, array($this, 'sanitizeOptions'));
foreach ($this->sections as $id => $data) {
add_settings_section($id, $data['title'], '', AFFILIATE_USERS_PAGE . $data['tab']);
}
foreach ($this->options as $id => $parameters) {
$parameters['id'] = $id;
add_settings_field(
$id,
$parameters['title'],
array($this, 'optionDisplaySettings'),
AFFILIATE_USERS_PAGE . $data['tab'],
$parameters['section'],
$parameters
);
}
}
/**
* Display options
*/
public function optionDisplaySettings($args)
{
$options = PluginOptions::getPluginOptions();
extract($args);
switch ($type) {
case 'text':
$value = isset($options[$id]) ? $options[$id] : '';
echo '';
if (isset($desc) && $desc) {
echo '
' . $desc . '';
}
break;
case 'textarea':
echo '';
if (isset($desc) && $desc) {
echo '
' . $desc . '';
}
break;
case 'checkbox':
$value = isset($options[$id]) ? $options[$id] : '';
$checked = ($value == 'on') ? ' checked="checked"' : '';
echo '';
break;
case 'radio':
echo '';
if (isset($desc) && $desc) {
echo '
' . $desc . '';
}
break;
case 'select':
echo '';
if (isset($desc) && $desc) {
echo '
' . $desc . '';
}
break;
case 'color':
echo '';
if (isset($desc) && $desc) {
echo '
' . $desc . '';
}
break;
}
}
/**
* Sanitize options
*/
public function sanitizeOptions($input)
{
if (isset($input['reset']) && ((bool) $input['reset'] == true)) {
return array();
}
foreach ($input as $k => &$v) {
$v = trim($v);
// In this part could be added different validation rules
}
foreach ($this->options as $k => $option) {
switch ($option['type']) {
case 'checkbox':
$input[$k] = $input[$k] ? 'on' : 'off';
break;
}
}
if (isset($input['prefix'])) {
global $wp_rewrite;
add_rewrite_rule(
"^({$input['prefix']})/(.+?)$",
'index.php?page=properties&affiliate=$matches[1]&username=$matches[2]',
'top'
);
$wp_rewrite->flush_rules(false);
}
return $input;
}
/*
* Create tabs
*/
protected function adminTabs($current = null)
{
if (!$this->tabs) {
return;
}
if (!$current) {
$current = $this->getCurrentTab();
}
echo '';
foreach ($this->tabs as $id => $title) {
$class = ($id == $current) ? ' nav-tab-active' : '';
$link = esc_url(get_admin_url(null, 'admin.php?page=' . plugin_basename(AFFILIATE_USERS_PAGE) . '&tab=' . $id));
echo '' . $title . '';
}
echo '
';
}
/*
* Get current tab
*/
protected function getCurrentTab()
{
$tab = sanitize_text_field(filter_input(INPUT_GET, 'tab'));
if (!$tab) {
$tabs = array_keys($this->tabs);
$tab = array_shift($tabs);
}
return $tab;
}
/**
* Add script and css styles to a page
*/
protected function registerAssets() {
wp_enqueue_script('client_form_color', AFFILIATE_USERS_URL . 'assets/js/jquery.color.picker.min.js', array('jquery'));
wp_enqueue_script('client_form_options', AFFILIATE_USERS_URL . 'assets/js/options.js', array('jquery'));
}
}