function leyka_save_settings($tab_name) { $options_names = array(); foreach (leyka_opt_alloc()->get_tab_options($tab_name) as $entry) { if (is_array($entry)) { foreach ($entry as $key => $option) { if ($key == 'section') { $options_names = array_merge($options_names, $option['options']); } else { $options_names[] = $option; } } } else { $options_names[] = $entry; } } foreach ($options_names as $name) { $option_type = leyka_options()->get_type_of($name); if ($option_type == 'checkbox') { leyka_options()->opt($name, isset($_POST["leyka_{$name}"]) ? 1 : 0); } elseif ($option_type == 'multi_checkbox') { if (isset($_POST["leyka_{$name}"]) && leyka_options()->opt($name) != $_POST["leyka_{$name}"]) { leyka_options()->opt($name, (array) $_POST["leyka_{$name}"]); } } elseif ($option_type == 'html' || $option_type == 'rich_html') { if (isset($_POST["leyka_{$name}"]) && leyka_options()->opt($name) != $_POST["leyka_{$name}"]) { leyka_options()->opt($name, esc_attr(stripslashes($_POST["leyka_{$name}"]))); } } else { if (isset($_POST["leyka_{$name}"]) && leyka_options()->opt($name) != $_POST["leyka_{$name}"]) { leyka_options()->opt($name, esc_attr(stripslashes($_POST["leyka_{$name}"]))); } } } }
function leyka_settings_complete($settings_tab) { $settings_complete = true; $tab_options = leyka_opt_alloc()->get_tab_options($settings_tab); // Special 4 strict standards $option_section = reset($tab_options); foreach ($option_section['section']['options'] as $option_name) { if (!leyka_options()->opt_safe($option_name) && leyka_options()->is_required($option_name)) { $settings_complete = false; break; } } return $settings_complete; }
/** Displaying settings **/ public function settings_screen() { /* Capability test */ if (!current_user_can('leyka_manage_options')) { wp_die(__('You do not have permissions to access this page.', 'leyka')); } $current_stage = $this->get_current_settings_tab(); require LEYKA_PLUGIN_DIR . 'inc/settings-pages/leyka-settings-common.php'; /* Page actions */ do_action('leyka_pre_settings_actions', $current_stage); /** Process settings change */ if (!empty($_POST["leyka_settings_{$current_stage}_submit"])) { do_action("leyka_settings_{$current_stage}_submit", $current_stage); } ?> <div class="wrap"> <h2 class="nav-tab-wrapper"><?php echo $this->settings_tabs_menu(); ?> </h2> <div id="tab-container"> <form method="post" action="<?php echo admin_url(add_query_arg('stage', $current_stage, 'admin.php?page=leyka_settings')); ?> " id="leyka-settings-form"> <?php wp_nonce_field("leyka_settings_{$current_stage}", '_leyka_nonce'); if (file_exists(LEYKA_PLUGIN_DIR . "inc/settings-pages/leyka-settings-{$current_stage}.php")) { require LEYKA_PLUGIN_DIR . "inc/settings-pages/leyka-settings-{$current_stage}.php"; } else { do_action("leyka_settings_pre_{$current_stage}_fields"); foreach (leyka_opt_alloc()->get_tab_options($current_stage) as $option) { // Render each option/section if (is_array($option) && !empty($option['section'])) { do_action('leyka_render_section', $option['section']); } else { // is this case possible? $option_info = leyka_options()->get_info_of($option); do_action("leyka_render_{$option_info['type']}", $option, $option_info); } } do_action("leyka_settings_post_{$current_stage}_fields"); ?> <p class="submit"> <input type="submit" name="<?php echo "leyka_settings_{$current_stage}"; ?> _submit" value="<?php _e('Save settings', 'leyka'); ?> " class="button-primary" /> </p> <?php } ?> </form> <!-- --><?php //do_action("leyka_settings_post_{$current_stage}_form"); ?> </div> </div><!-- close .wrap --> <?php }