/** * Theme Default Options */ public function default_options() { if (is_file(WOLF_THEME_DIR . '/config/default-options.php')) { include_once WOLF_THEME_DIR . '/config/default-options.php'; } // Default theme options are defined in "includes/default-options.php" if (function_exists('wolf_theme_default_options_init') && !get_option('wolf_theme_options_' . wolf_get_theme_slug())) { wolf_theme_default_options_init(); } // Default customizer options are defined in "includes/default-customizer-options.php" if (function_exists('wolf_theme_customizer_options_init')) { wolf_theme_customizer_options_init(); } }
/** * Save the theme options in array */ public function save() { global $options; /** * Back from WpAdmin construct function redirection */ if (isset($_GET['message']) && 'save' == $_GET['message'] && isset($_GET['page']) && $_GET['page'] == 'wolf-theme-options') { wolf_admin_notice(__('Your settings have been saved.', 'wolf'), 'updated'); } if (isset($_GET['message']) && 'export' == $_GET['message'] && isset($_GET['page']) && $_GET['page'] == 'wolf-theme-options') { wolf_admin_notice(__('Your download should start in a few seconds.', 'wolf'), 'updated'); //wp_safe_redirect( WOLF_THEME_URi . '/includes/admin/options-export.zip' ); } if (isset($_GET['page']) && $_GET['page'] == 'wolf-theme-options') { $errors = array(); if (isset($_POST['action']) && $_POST['action'] == 'save' && (!isset($_FILES['wolf-options-import-file']['name']) || '' == $_FILES['wolf-options-import-file']['name']) && wp_verify_nonce($_POST['wolf_save_theme_options_nonce'], 'wolf_save_theme_options')) { // 5 minutes time out set_time_limit(900); $new_options = array(); $data = $_POST['wolf_theme_options']; foreach ($this->options as $value) { $type = isset($value['type']) ? $value['type'] : null; $value_key = isset($value['id']) ? $value['id'] : null; if ('int' == $type) { $new_options[$value_key] = intval($data[$value_key]); } elseif ('image' == $type) { if (is_numeric($data[$value_key])) { $new_options[$value_key] = absint($data[$value_key]); } else { $new_options[$value_key] = esc_url($data[$value_key]); } } elseif ('url' == $type || 'file' == $type) { if (!empty($data[$value_key])) { $new_options[$value_key] = esc_url($data[$value_key]); } } elseif ('email' == $type) { if (!empty($data[$value_key]) && !is_email($data[$value_key])) { $errors[] = '<strong>' . $data[$value_key] . '</strong> ' . __('is not a valid email', 'wolf') . '.'; } elseif (!empty($data[$value_key])) { $new_options[$value_key] = sanitize_email($data[$value_key]); } } elseif ('editor' == $type) { if (!empty($_POST['wolf_theme_options_editor_' . $value['id']])) { $new_options[$value_key] = $_POST['wolf_theme_options_editor_' . $value_key]; if (function_exists('icl_register_string')) { icl_register_string(wolf_get_theme_slug(), $value_key, $new_options[$value_key]); } } } elseif ('text' == $type || 'textarea' == $type || 'javascript' == $type) { if (!empty($data[$value_key])) { $new_options[$value_key] = $data[$value_key]; if ('text' == $type || 'text_html' == $type || 'textarea' == $type) { if (function_exists('icl_register_string')) { icl_register_string(wolf_get_theme_slug(), $value_key, $new_options[$value_key]); } } } } elseif ('background' == $type) { $bg_settings = array('color', 'img', 'position', 'repeat', 'attachment', 'size', 'parallax', 'font_color'); foreach ($bg_settings as $s) { $o = $value_key . '_' . $s; if (isset($o) && !empty($data[$o])) { $setting = $data[$o]; if ('img' == $s) { if (is_numeric($setting)) { $new_options[$o] = absint($setting); } else { $new_options[$o] = esc_url($setting); } } else { $new_options[$o] = sanitize_text_field($setting); // $new_options[ $o ] = $setting; } } } } elseif ('font' == $type) { $font_settings = array('font_color', 'font_name', 'font_weight', 'font_transform', 'font_style', 'font_letter_spacing'); foreach ($font_settings as $s) { $o = $value_key . '_' . $s; if (isset($o) && !empty($data[$o])) { $new_options[$o] = $data[$o]; } } } elseif ('video' == $type) { $video_settings = array('mp4', 'webm', 'ogv', 'opacity', 'img', 'type', 'youtube_url'); foreach ($video_settings as $s) { $o = $value_key . '_' . $s; if (isset($o) && !empty($data[$o])) { $new_options[$o] = $data[$o]; } } } elseif ('css' == $type) { if (isset($value_key) && !empty($data[$value_key])) { $new_options[$value_key] = $data[$value_key]; } } else { if (isset($value_key) && !empty($data[$value_key])) { $new_options[$value_key] = sanitize_text_field(strip_tags($data[$value_key])); } } } update_option('wolf_theme_options_' . wolf_get_theme_slug(), $new_options); do_action('wolf_after_options_save', $new_options); //wp_redirect( admin_url( 'admin.php?page=wolf-theme-options' ) ); } else { if (isset($_POST['action']) && $_POST['action'] == 'wolf-reset-all-options') { $old_options = get_option('wolf_theme_options'); delete_option('wolf_theme_options_' . wolf_get_theme_slug()); if (function_exists('wolf_theme_default_options_init')) { wolf_theme_default_options_init(); } } } if (isset($_POST['action']) && $_POST['action'] == 'save' && !isset($_POST['wolf-options-import-file-submit'])) { wolf_admin_notice(__('Your settings have been saved.', 'wolf'), 'updated'); } if (isset($_POST['action']) && $_POST['action'] == 'wolf-reset-all-options') { wolf_admin_notice(__('Your settings have been reset.', 'wolf'), 'updated'); } /* Display raw error message */ if ($errors != array()) { $error_message = '<br><div class="error">'; foreach ($errors as $error) { $error_message .= '<p>' . $error . '</p>'; } $error_message .= '</div>'; echo wp_kses($error_message, array('p' => array(), 'br' => array(), 'strong' => array(), 'div' => array('class' => array()))); } } }