set_options(); // Set the currently saved options
$this->set_defaults(); // Set the default options
$this->set_select_options(); // Set the options available for each select
}
/**
* Output the necessary JS in the head of the front end (when the user is logged in)
*/
public function on_wp_head(){
if(is_user_logged_in()) :
?>
'text'
)
);
add_settings_field(
'text_direction',
__('Text Direction', 'djg-admin-bar-button'),
array($this, '_option_text_direction'),
'djg_admin_bar_button',
'abb_button_section',
array(
'label_for' => 'text_direction'
)
);
add_settings_field(
'button_position',
__('Position on the Screen', 'djg-admin-bar-button'),
array($this, '_option_button_position'),
'djg_admin_bar_button',
'abb_button_section',
array(
'label_for' => 'button_position'
)
);
add_settings_field(
'button_direction',
__('Direction', 'djg-admin-bar-button'),
array($this, '_option_button_direction'),
'djg_admin_bar_button',
'abb_button_section',
array(
'label_for' => 'button_direction'
)
);
add_settings_field(
'button_duration',
__('Duration', 'djg-admin-bar-button'),
array($this, '_option_button_duration'),
'djg_admin_bar_button',
'abb_button_section',
array(
'label_for' => 'button_duration'
)
);
/*-----------------------------------------------
Admin Bar settings
-----------------------------------------------*/
add_settings_section(
'abb_bar_section', // ID
__('What about the Amdin Bar itself?', 'djg-admin-bar-button'), // Title
array($this, 'do_info_bar_section'), // Callback
'djg_admin_bar_button' // Page
);
add_settings_field(
'bar_direction', // ID
__('Direction', 'djg-admin-bar-button'), // Title
array($this, '_option_bar_direction'), // Callback
'djg_admin_bar_button', // Page
'abb_bar_section', // Section
array( // Args
'label_for' => 'bar_direction'
)
);
add_settings_field(
'bar_duration',
__('Duration', 'djg-admin-bar-button'),
array($this, '_option_bar_duration'),
'djg_admin_bar_button',
'abb_bar_section',
array(
'label_for' => 'bar_duration'
)
);
/*-----------------------------------------------
General settings
-----------------------------------------------*/
add_settings_section(
'abb_general_section', // ID
__('And finnally just one general settings...', 'djg-admin-bar-button'), // Title
array($this, 'do_info_general_section'), // Callback
'djg_admin_bar_button' // Page
);
add_settings_field(
'show_time', // ID
__('Show Time', 'djg-admin-bar-button'), // Title
array($this, '_option_show_time'), // Callback
'djg_admin_bar_button', // Page
'abb_general_section', // Section
array( // Args
'label_for' => 'show_time'
)
);
}
/**
* Render the page
*/
public function on_show_page(){
?>
set_defaults(); // Set the default options
$this->set_select_options(); // Set the options available for each select
$new_input = array(); // Create a new array to hold the sanitized options
/** Button text */
if(isset($input['text'])) :
$text = sanitize_text_field($input['text']);
$new_input['text'] = ($text !== '') ? $text : $this->defaults['text'];
endif;
/** Text direction */
if(isset($input['text_direction'])) :
$new_input['text_direction'] = (array_key_exists($input['text_direction'], $this->select_options['text_direction'])) ? $input['text_direction'] : $this->defaults['text_direction'];
endif;
/** Button position */
if(isset($input['button_position'])) :
$new_input['button_position'] = (array_key_exists($input['button_position'], $this->select_options['button_position'])) ? $input['button_position'] : $this->defaults['button_position'];
endif;
/** Button direction */
if(isset($input['button_direction'])) :
$new_input['button_direction'] = (array_key_exists($input['button_direction'], $this->select_options['button_direction'])) ? $input['button_direction'] : $this->defaults['button_direction'];
endif;
/** Button duration */
if(isset($input['button_duration'])) :
$time = absint($input['button_duration']);
$new_input['button_duration'] = ($time > 0) ? $time : $this->defaults['button_duration'];
endif;
/** Bar direction */
if(isset($input['bar_direction'])) :
$new_input['bar_direction'] = (array_key_exists($input['bar_direction'], $this->select_options['bar_direction'])) ? $input['bar_direction'] : $this->defaults['bar_direction'];
endif;
/** Bar duration */
if(isset($input['bar_duration'])) :
$time = absint($input['bar_duration']);
$new_input['bar_duration'] = ($time > 0) ? $time : $this->defaults['bar_duration'];
endif;
/** Show time */
if(isset($input['show_time'])) :
$time = absint($input['show_time']);
$new_input['show_time'] = ($time > 0) ? $time : $this->defaults['show_time'];
endif;
return $new_input;
}
/**
* Set the $options, grabbed from the 'wp_options' DB table
*/
private function set_options(){
$this->options = get_option('admin_bar_button');
}
/**
* Set the default values, used if a value is not set when the 'on_show_page' or 'on_save_settings' methods are called
*/
private function set_defaults(){
$this->dafaults = array(
'text' => __('Admin bar', 'djg-admin-bar-button'),
'text_direction' => 'ltr',
'button_position' => 'left',
'button_direction' => 'left',
'button_duration' => 500,
'bar_direction' => 'right',
'bar_duration' => 500,
'show_time' => 5000
);
}
/**
* Set the options that are available for each of the