'yes', 'show_ideal_weight' => 'yes', 'show_health_tips' => 'yes', 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'), 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'), 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'), 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'), 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'), 'text_too_thin' => __('You are underweight.', 'aa-health-calculator'), 'text_healthy' => __('You have a healthy weight.', 'aa-health-calculator'), 'text_overweight' => __('You are overweight.', 'aa-health-calculator'), 'alert_invalid_input' => __('Please fill in everything correctly.', 'aa-health-calculator'), ]; $this->options = get_option('aa_health_calculator_options', []); $this->options = wp_parse_args($this->options, $defaults); wp_localize_script('aa-health-script', 'aaHealthOptions', $this->options); } public function render_shortcode() { ob_start(); ?>
[$this, 'sanitize_options'], ]); add_settings_section( 'aa_health_calculator_main_section', __('Premium Options', 'aa-health-calculator'), '__return_false', 'aa-health-calculator' ); add_settings_field( 'show_categories', __('Show BMI Categories', 'aa-health-calculator'), [$this, 'field_checkbox_callback'], 'aa-health-calculator', 'aa_health_calculator_main_section', ['label_for' => 'show_categories'] ); add_settings_field( 'show_ideal_weight', __('Show Ideal Weight Range', 'aa-health-calculator'), [$this, 'field_checkbox_callback'], 'aa-health-calculator', 'aa_health_calculator_main_section', ['label_for' => 'show_ideal_weight'] ); add_settings_field( 'show_health_tips', __('Show Health Tips', 'aa-health-calculator'), [$this, 'field_checkbox_callback'], 'aa-health-calculator', 'aa_health_calculator_main_section', ['label_for' => 'show_health_tips'] ); } public function sanitize_options($input) { $output = []; $output['show_categories'] = (isset($input['show_categories']) && $input['show_categories'] === 'yes') ? 'yes' : 'no'; $output['show_ideal_weight'] = (isset($input['show_ideal_weight']) && $input['show_ideal_weight'] === 'yes') ? 'yes' : 'no'; $output['show_health_tips'] = (isset($input['show_health_tips']) && $input['show_health_tips'] === 'yes') ? 'yes' : 'no'; // Preserve tips and texts, or set defaults if not present $defaults = [ 'tip_drink_water' => __('Drink plenty of water every day.', 'aa-health-calculator'), 'tip_exercise' => __('Exercise regularly to stay healthy.', 'aa-health-calculator'), 'tip_vegetables' => __('Include vegetables in your diet.', 'aa-health-calculator'), 'tip_limit_sugar' => __('Limit sugar intake.', 'aa-health-calculator'), 'tip_sleep' => __('Get enough sleep.', 'aa-health-calculator'), 'text_too_thin' => __('You are underweight.', 'aa-health-calculator'), 'text_healthy' => __('You have a healthy weight.', 'aa-health-calculator'), 'text_overweight' => __('You are overweight.', 'aa-health-calculator'), 'alert_invalid_input' => __('Please fill in everything correctly.', 'aa-health-calculator'), ]; foreach ($defaults as $key => $default) { $output[$key] = isset($input[$key]) ? sanitize_text_field($input[$key]) : $default; } return $output; } public function field_checkbox_callback($args) { $options = get_option('aa_health_calculator_options'); $key = $args['label_for']; ?> />