';
}
}
return $output;
}
// Ajax callback function for the "reset" button (resets settings to default)
function blackoot_settings_reset_ajax_callback() {
global $blackoot_settings_slug;
// Get settings from the database
$blackoot_settings = get_option($blackoot_settings_slug);
// Get the settings template
$options = blackoot_settings_template();
// Revert all settings to default value
foreach($options as $arg){
if ($arg['type'] != 'start_menu' && $arg['type'] != 'end_menu' && isset($arg['default']) ) {
$blackoot_settings[$arg['id']] = $arg['default'];
}
}
// Updates settings in the database
update_option($blackoot_settings_slug,$blackoot_settings);
}
add_action('wp_ajax_blackoot_settings_reset_ajax_post_action', 'blackoot_settings_reset_ajax_callback');
// AJAX callback function for the "Save changes" button (updates user's settings in the database)
function blackoot_settings_ajax_callback() {
global $blackoot_settings_slug;
// Check nonce
check_ajax_referer('blackoot_settings_ajax_post_action','blackoot_settings_nonce');
// Get POST data
$data = $_POST['data'];
parse_str($data,$input);
// Get current settings from the database
$blackoot_settings = get_option($blackoot_settings_slug);
// Get the settings template
$options = blackoot_settings_template();
// Validate input and update all settings according to POST data
foreach($options as $option_array){
if (isset($option_array['id']) && $option_array['type'] != 'start_menu' && $option_array['type'] != 'end_menu') {
$id = $option_array['id'];
if ($option_array['type'] == "radio" ) {
if ( in_array( $input[$option_array['id']], $option_array['values']) ) {
$new_value = $input[$option_array['id']];
} else {
$new_value = $option_array['default'];
}
} elseif ($option_array['type'] == "image") {
$new_value = esc_url_raw($input[$option_array['id']]);
}
$blackoot_settings[$id] = stripslashes($new_value);
}
}
// Updates settings in the database
update_option($blackoot_settings_slug,$blackoot_settings);
}
add_action('wp_ajax_blackoot_settings_ajax_post_action', 'blackoot_settings_ajax_callback');
// NOJS fallback for the "Save changes" button
function blackoot_settings_save_nojs() {
global $blackoot_settings_slug;
// Get POST data
// parse_str($_POST,$output);
// Get current settings from the database
$blackoot_settings = get_option($blackoot_settings_slug);
// Get the settings template
$options = blackoot_settings_template();
// Updates all settings according to POST data
foreach($options as $option_array){
if (isset($option_array['id']) && $option_array['type'] != 'start_menu' && $option_array['type'] != 'end_menu') {
$id = $option_array['id'];
if ($option_array['type'] == "radio" ) {
if ( in_array( $_POST[$option_array['id']], $option_array['values']) ) {
$new_value = $_POST[$option_array['id']];
} else {
$new_value = $option_array['default'];
}
} elseif ($option_array['type'] == "image") {
$new_value = esc_url_raw($_POST[$option_array['id']]);
}
$blackoot_settings[$id] = stripslashes($new_value);
}
}
// Updates settings in the database
update_option($blackoot_settings_slug,$blackoot_settings);
}
// Outputs the settings panel
function blackoot_settings_page(){
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
global $blackoot_settings_slug;
global $blackoot_settings_name;
if (isset( $_POST['reset-no-js'] ) && $_POST['reset-no-js']) {
blackoot_settings_reset_ajax_callback();
echo '
Blackoot Lite Notice: you have not set your primary menu yet, and your site is currently using a fallback menu which is not responsive. Please take a minute to set your menu now!