format required for processing by the sapi handlers. They create an array called $_POST['weaverx_main_settings']. Each setting in that array corresponds to a Weaver Xtreme option value, and will be passed to the validation function. We will wrap the main form (Main Options) with our functions weaverx_sapi_form_top() and weaverx_sapi_form_bottom() that generates required calls to sapi. All other forms will use submit buttons that include their own nonce definition. Other forms generally do not change individual settings, but take actions such as save/restore or setting a subtheme. */ // # RUNTIME SAPI HELPER FUNCTIONS ============================================ function weaverx_sapi_options_init() { /* this will initialize the SAPI stuff, must be called from the admin_init cb function . In reality, we really only need to register one setting - 'weaverx_main_settings_group', and the settings will be saved in the WP DB as 'weaverx_main_settings'. The SAPI uses the name param of any fields to figure out where to store the input value. The validation will have to scan the ENTIRE list of options and lookup the kind of validation each parameter needs. NOTE: This code is here to support Legacy Weaver Xtreme Theme options settings. Version 2.0 does not use or call these validation functions directly, but the are needed to support the legacy options interface. */ register_setting('weaverx_settings_group', /* the group name of our settings */ apply_filters('weaverx_options',WEAVER_SETTINGS_NAME), /* the get_option name */ 'weaverx_validate_cb'); /* a validation call back */ } function weaverx_validate_cb($in) { return weaverx_validate_all_options($in); } /* ================= nonce helpers ===================== */ function weaverx_submitted($submit_name) { // do a nonce check for each form submit button // pairs 1:1 with weaverx_nonce_field $nonce_act = $submit_name.'_act'; $nonce_name = $submit_name.'_nonce'; if (isset($_POST[$submit_name])) { if (isset($_POST[$nonce_name]) && wp_verify_nonce($_POST[$nonce_name],$nonce_act)) { return true; } else { die(__('WARNING: invalid form submit detected. Probably caused by session time-out, or, rarely, a failed security check. Please contact WeaverTheme.com if you continue to receive this message.', 'weaver-xtreme' /*adm*/) . '(' . $submit_name . ')'); } } else { return false; } } function weaverx_nonce_field($submit_name,$echo = true) { // pairs 1:1 with submitted // will be one for each form submit button return wp_nonce_field($submit_name.'_act',$submit_name.'_nonce',$echo); } /* ================= Main SAPI helper functions ================= */ function weaverx_sapi_form_top($group, $form_name='') { /* beginning of a form */ $name = ''; if ($form_name != '') $name = 'name="' . $form_name . '"'; echo("
\n"); /* */ settings_fields($group); // use our one set of settings } function weaverx_sapi_form_bottom($form_name='end of form') { // customizer only, keep values, preserve values, save values, not legacy (search terms for these kinds of settings) $non_sapi = apply_filters('weaverx_non_sapi_options',array( // non-sapi elements in the db 'weaverx_version_id', 'style_version', 'theme_filename', 'addon_name', '_hide_theme_thumbs', 'm_primary_hamburger', 'm_secondary_hamburger', 'font_set_vietnamese', 'font_set_cryllic', 'font_set_greek', 'font_set_hebrew', 'font_word_spacing_global_dec', 'font_letter_spacing_global_dec', '_options_level', '_PHP_warning_displayed', 'last_option')); /* The following code allows the SAPI to save the non-sapi values. If you don't do this here, then the values will be set to false, and be lost! SAPI is not tolerant of submitting a form that doesn't include EVERY setting for the form group. */ weaverx_setopt('last_option','Weaver Xtreme'); // Safety check for limited PHP $_POST variables foreach ($non_sapi as $name) { ?> \n"); } function weaverx_sapi_submit( $before='', $after='', $show_more_opts = false ) { // generate a submit button for the form $submit_label = __('Save Settings', 'weaver-xtreme' /*adm*/); echo $before; ?> \n" . $after ; } function weaverx_form_submit($value) { weaverx_sapi_submit('',''); } function weaverx_sapi_main_name($id, $echo=true) { /* generate the SAPI name for WEAVER_SETTINGS_NAME */ $name = apply_filters('weaverx_options',WEAVER_SETTINGS_NAME); if ($echo) echo $name. '[' . $id . ']'; return $name . '[' . $id . ']'; } /* ============== Validation ===================== */ function weaverx_validate_all_options($in) { /* validation for all options */ $err_msg = ''; // no error message yet if (empty($in)) { wp_die( __( 'You attempted to save options, but something has gone wrong. Please be sure you are logged in and your host is correctly configured. See the "Weaver Doesn\'t Save Settings" FAQ on weavertheme.com.' ,'weaver-xtreme') ); } if (!current_user_can('edit_theme_options')) { wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ,'weaver-xtreme') ); } $wvr_last = ''; $cur_item = ''; foreach ($in as $key => $value) { //$cur_key = $key; switch ($key) { /* -------- integer -------- */ case 'excerpt_length': if (!empty($value) && (!is_numeric($value) || !is_int((int)$value))) { $opt_id = str_replace('', '', $key); $opt_id = str_replace('_', ' ', $opt_id); $err_msg .= __('Option must be an integer value: ', 'weaver-xtreme' /*adm*/) . '"'. $opt_id . '" = "' . $value . '".' . __(' Value has been cleared to blank value', 'weaver-xtreme' /*adm*/) . '
'; $in[$key] = ''; } break; /* ---------- text ----------- */ case 'excerpt_more_msg': case 'header_maxwidth': if (!empty($value)) $in[$key] = weaverx_filter_textarea($value); break; case 'themename': // can't be empty! if (empty($value)) $in[$key] = 'please-give-this-a-name'; else $in[$key] = weaverx_filter_textarea($value); break; /* code */ case 'copyright': // Alternate copyright case '_css_rows': if (!empty($value)) { $in[$key] = weaverx_filter_code($value); } break; case '_perpagewidgets': // Add widget areas for per page - names must be lower case if (!empty($value)) { $in[$key] = strtolower(str_ireplace(' ','',weaverx_filter_code($value))); } break; case '_althead_opts': case 'head_opts': if ( !empty( $value ) ) { $in[$key] = weaverx_filter_head( $value ); } break; case 'wvrx_css_saved': if ( !empty( $value ) ) { $in[$key] = weaverx_filter_code( $value ); //$in[$key] = wp_filter_post_kses( trim(stripslashes($value)) ); } break; /* must not have