';
}
}
update_option($boldr_settings_slug,$boldr_settings);
return $output;
}
// AJAX callback function for the "reset" button (resets settings to default)
function boldr_settings_reset_ajax_callback() {
global $boldr_settings_slug;
// Get settings from the database
$boldr_settings = get_option($boldr_settings_slug);
// Get the settings template
$options = boldr_settings_template();
// Revert all settings to default value
foreach($options as $arg){
if ($arg['type'] != 'start_menu' && $arg['type'] != 'end_menu') {
$boldr_settings[$arg['id']] = $arg['default'];
}
}
// Updates settings in the database
update_option($boldr_settings_slug,$boldr_settings);
}
add_action('wp_ajax_boldr_settings_reset_ajax_post_action', 'boldr_settings_reset_ajax_callback');
// AJAX callback function for the "Save changes" button (updates user's settings in the database)
function boldr_settings_ajax_callback() {
global $boldr_settings_slug;
// Check nonce
check_ajax_referer('boldr_settings_ajax_post_action','boldr_settings_nonce');
// Get POST data
$data = $_POST['data'];
parse_str($data,$output);
// Get current settings from the database
$boldr_settings = get_option($boldr_settings_slug);
// Get the settings template
$options = boldr_settings_template();
// Updates all settings according to POST data
foreach($options as $option_array){
if ($option_array['type'] != 'start_menu' && $option_array['type'] != 'end_menu') {
$id = $option_array['id'];
if ($option_array['type'] == "text") {
$new_value = esc_textarea($output[$option_array['id']]);
} else {
$new_value = $output[$option_array['id']];
}
$boldr_settings[$id] = stripslashes($new_value);
}
}
// Updates settings in the database
update_option($boldr_settings_slug,$boldr_settings);
}
add_action('wp_ajax_boldr_settings_ajax_post_action', 'boldr_settings_ajax_callback');
// NOJS fallback for the "Save changes" button
function boldr_settings_save_nojs() {
global $boldr_settings_slug;
// Get POST data
// parse_str($_POST,$output);
// Get current settings from the database
$boldr_settings = get_option($boldr_settings_slug);
// Get the settings template
$options = boldr_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'] == "text") {
$new_value = esc_textarea($_POST[$option_array['id']]);
} else {
$new_value = $_POST[$option_array['id']];
}
$boldr_settings[$id] = stripslashes($new_value);
}
}
// Updates settings in the database
update_option($boldr_settings_slug,$boldr_settings);
}
// Update settings template in the database upon theme activation
function boldr_settings_theme_activation() {
global $boldr_settings_slug;
// Get current settings from the database
$boldr_settings = get_option($boldr_settings_slug);
// Get the settings template
$options = boldr_settings_template();
// Updates all settings
foreach($options as $option_array){
if ($option_array['type'] != 'start_menu' && $option_array['type'] != 'end_menu') {
$id = $option_array['id'];
if ( !isset( $boldr_settings[$id] ) )
$boldr_settings[$id] = stripslashes($option_array['default']);
}
}
// Updates settings in the database
update_option($boldr_settings_slug,$boldr_settings);
}
add_action('after_switch_theme', 'boldr_settings_theme_activation');
// Outputs the settings panel
function boldr_settings_page(){
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_enqueue_style('thickbox');
global $boldr_settings_slug;
global $boldr_settings_name;
if (isset( $_POST['reset-no-js'] ) && $_POST['reset-no-js']) {
boldr_settings_reset_ajax_callback();
echo '