/* --------------------------------------------------------------------------- * Create menu for theme options panel * --------------------------------------------------------------------------- */ function veda_create_admin_menu() { /** * Creates main options page. */ add_theme_page( THEME_NAME . esc_html__(' Theme Options', 'veda'), THEME_NAME . esc_html__(' Options', 'veda'), 'manage_options', 'veda-opts', 'veda_options_page' ); } add_action('admin_menu', 'veda_create_admin_menu'); require_once(VEDA_THEME_DIR . '/framework/theme-options/settings.php'); /* --------------------------------------------------------------------------- * Create function to init veda options * --------------------------------------------------------------------------- */ add_action('admin_init', 'veda_admin_options_init', 1); function veda_admin_options_init() { register_setting(VEDA_SETTINGS, VEDA_SETTINGS); add_option(VEDA_SETTINGS, veda_default_option()); if (isset($_POST['dttheme-option-save'])) : veda_ajax_option_save(); endif; if (isset($_POST['dttheme']['reset'])) : delete_option(VEDA_SETTINGS); update_option(VEDA_SETTINGS, veda_default_option()); # To set Default options wp_redirect(admin_url('admin.php?page=parent&reset=true')); exit; endif; } function veda_ajax_option_save() { $ajax_ref_check = check_ajax_referer('dttheme_wpnonce', 'dttheme_admin_wpnonce'); if($ajax_ref_check === false) { return false; } else { $data = $_POST; unset($data['_wp_http_referer'], $data['_wpnonce'], $data['action']); unset($data['dttheme_admin_wpnonce'], $data['dttheme-option-save'], $data['option_page']); $msg = array( 'success' => false, 'message' => esc_html__('Error: Options not saved, please try again.', 'veda') ); $data = array_filter($data['dttheme']); if (update_option(VEDA_SETTINGS, $data)) { $msg = array( 'success' => 'options_saved', 'message' => esc_html__('Options Saved.', 'veda') ); } else { $msg = array( 'success' => true, 'message' => esc_html__('Options Saved.', 'veda') ); } $echo = json_encode($msg); @header('Content-Type: application/json; charset='.get_option('blog_charset')); echo "{$echo}"; exit; } } /* --------------------------------------------------------------------------- * Backup And Restore theme options * --------------------------------------------------------------------------- */ add_action('wp_ajax_veda_backup_and_restore_action', 'veda_backup_and_restore_action'); function veda_backup_and_restore_action() { $save_type = $_REQUEST['type']; if ($save_type == 'backup_options') : $data = array( 'general' => veda_option('general'), 'layout' => veda_option('layout'), 'social' => veda_option('social'), 'pageoptions' => veda_option('pageoptions'), 'widgetarea' => veda_option('widgetarea'), 'woo' => veda_option('woo'), 'colors' => veda_option('colors'), 'fonts' => veda_option('fonts'), 'backup' => date('r') ); update_option("dt_theme_backup", $data); die('1'); elseif ($save_type == 'restore_options') : $data = get_option("dt_theme_backup"); update_option(VEDA_SETTINGS, $data); die('1'); elseif ($save_type == "import_options") : $data = $_REQUEST['data']; $data = unserialize(stripcslashes($data)); update_option(VEDA_SETTINGS, $data); die('1'); elseif( $save_type == "reset_options") : delete_option(VEDA_SETTINGS); update_option(VEDA_SETTINGS, veda_default_option()); #To set Default options die('1'); endif; } /* --------------------------------------------------------------------------- * Create function to get theme options * --------------------------------------------------------------------------- */ function veda_option($key1, $key2 = '') { $options = get_option ( VEDA_SETTINGS ); $output = NULL; if (is_array ( $options )) { if (array_key_exists ( $key1, $options )) { $output = $options [$key1]; if (is_array ( $output ) && ! empty ( $key2 )) { $output = (array_key_exists ( $key2, $output ) && (! empty ( $output [$key2] ))) ? $output [$key2] : NULL; } } else { $output = $output; } } return $output; } /* --------------------------------------------------------------------------- * Create admin panel image preview * --------------------------------------------------------------------------- */ function veda_adminpanel_image_preview($src, $backend = true, $default = "no-image.jpg") { $default = ($backend) ? VEDA_THEME_URI . "/framework/theme-options/images/" . $default : VEDA_THEME_URI . "/images/" . $default; $src = ! empty ( $src ) ? $src : $default; $output = "
\n"; echo "{$output}"; } /* --------------------------------------------------------------------------- * List all images from specific directory * --------------------------------------------------------------------------- */ function veda_listImage($dir) { $sociables = array (); $icon_types = array ( 'jpg', 'jpeg', 'gif', 'png' ); if (is_dir ( $dir )) { $handle = opendir ( $dir ); while ( false !== ($dirname = readdir ( $handle )) ) { if ($dirname != "." && $dirname != "..") { $parts = explode ( '.', $dirname ); $ext = strtolower ( $parts [count ( $parts ) - 1] ); if (in_array ( $ext, $icon_types )) { $option = $parts [count ( $parts ) - 2]; $sociables [$dirname] = str_replace ( ' ', '', $option ); } } } closedir ( $handle ); } return $sociables; } /* --------------------------------------------------------------------------- * Types of Background option available * --------------------------------------------------------------------------- */ function veda_bgtypes($name, $parent, $child) { $args = array ( "bg-patterns" => esc_html__ ( "Pattern", 'veda' ), "bg-custom" => esc_html__ ( "Custom Background", 'veda' ), "bg-none" => esc_html__ ( "None", 'veda' ) ); $out = '