'.$arg['name'].''."\n"; } } return $output; } // Generate the settings panel's content function boldr_settings_machine($options) { global $boldr_settings_slug; $boldr_settings = get_option($boldr_settings_slug); $output = ""; foreach ($options as $arg) { if ( is_array($arg) && is_array($boldr_settings) ) { if ( array_key_exists('id', $arg) ) { if ( array_key_exists($arg['id'], $boldr_settings) ) $val = stripslashes($boldr_settings[$arg['id']]); else $val = ""; } else { $val = ""; } } else { $val = ""; } if ( $arg['type'] == "start_menu" ) { $output .= '
'; } elseif ( $arg['type'] == "radio" ) { $output .= '

'. $arg['name'] .'

'."\n"; if ( $val == "" && $arg['default'] != "") $boldr_settings[$arg['id']] = $val = $arg['default']; $values = $arg['values']; $output .= '
'; foreach ($values as $value) { $output .= ''.$value.'
'; } $output .= '
'; $output .= '
'."\n"; } elseif ( $arg['type'] == "image" ) { $output .= '

'. $arg['name'] .'

'."\n"; if ( $val == "" && $arg['default'] != "") $boldr_settings[$arg['id']] = $val = $arg['default']; $output .= ''."\n"; $output .= '
'. $arg['desc'] .'

'."\n"; $output .= ''."\n"; $output .= '
'."\n"; $output .= '
'."\n"; } elseif ( $arg['type'] == "gopro" ) { $output .= '

'. $arg['name'] .'

'."\n"; $output .= '

Unleash the full potential of BoldR by upgrading to BoldR Pro!

'; $output .= '

The Pro version comes with a great set of awesome features:

'; $output .= ''; $output .= 'Learn More and Upgrade Now!'; } elseif ( $arg['type'] == "end_menu" ) { $output .= '
'; } } 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 '

Settings were reset to default.

'; } if (isset( $_POST['save-no-js'] ) && $_POST['save-no-js']) { boldr_settings_save_nojs(); echo '

Settings updated.

'; } ?>