function bizz_maybe_set_defaults($run = false) { global $themeid; $themeid = $themeid; $saved_defaults = get_option('bizz_defaults_' . $themeid); $saved_reset = get_option('bizz_reset_' . $themeid); $saved_themesidebars = get_option($themeid . '_sidebars_widgets'); $args = array('post_type' => 'bizz_widget', 'numberposts' => -1); $layout_posts = get_posts($args); /* delete_option('bizz_defaults_' . $themeid); delete_option('bizz_reset_' . $themeid); delete_option($themeid . '_sidebars_widgets'); bizzthemes_default_layouts('reset'); # set delete_option('bizz_reset_' . $themeid); */ if (empty($saved_defaults) && empty($saved_themesidebars) && empty($saved_reset) && !$layout_posts) { #security checks if (is_preview()) { bizzthemes_default_layouts('set_defaults'); # set $homeurl = trailingslashit(site_url()); $page = "{$homeurl}?preview=1&template={$themeid}&stylesheet={$themeid}&preview_iframe=1&TB_iframe=true&stoprefresh=1"; if (!isset($_GET['stoprefresh'])) { header("Refresh: 1; url={$page}"); print_r('<br/><br/><center>Loading defaults...</center>'); } } elseif ($run) { bizzthemes_default_layouts('set_defaults'); } # set } }
function manage_options() { global $bizzthemes_site, $wpdb, $themeid, $frameversion, $opt, $optd; if (isset($_POST['upload'])) { if ($_POST['upload'] == 'all') { check_admin_referer('bizzthemes-upload-all', '_wpnonce-bizzthemes-upload-all'); #wp // DEFAULT OPTIONS $def_theme_id = $themeid; $def_frame_version = $frameversion; // UPLOADED OPTIONS $new_options = file_get_contents($_FILES['file']['tmp_name']); // remove BOM $new_options = mb_convert_encoding($new_options, 'UTF-8', 'ASCII,UTF-8,ISO-8859-1'); if (substr($new_options, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { $new_options = substr($new_options, 3); } // decode $new_options = json_decode($new_options, true); $new_theme_id = $new_options['theme_id']; $new_frame_version = $new_options['frame_version']; $new_options_id = $new_options['options_id']; if (function_exists('wp_cache_clean_cache')) { #wp global $file_prefix; wp_cache_clean_cache($file_prefix); #wp } // wrong file $files_array = array('bizzthemes-layouts', 'bizzthemes-settings', 'bizzthemes-design'); $wrongfile = true; foreach ($files_array as $needle) { if (strpos($_FILES['file']['name'], $needle) !== false) { $wrongfile = false; } } if ($wrongfile) { wp_redirect(admin_url('admin.php?page=bizz-tools&type=Layouts&error=wrongfile')); } #wp // file error if ($_FILES['file']['error'] > 0) { wp_redirect(admin_url('admin.php?page=bizz-tools&type=All&error=file')); } else { // all fine if ($new_options['options_id'] == 'layouts') { if (version_compare($def_frame_version, $new_frame_version, '!=')) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Layouts&error=version&tried={$new_frame_version}&yours={$def_frame_version}")); } elseif ($def_theme_id != $new_theme_id) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Layouts&error=theme&tried={$new_theme_id}&yours={$def_theme_id}")); } else { // read options $new_all_widgets = $new_options['options_value']['all_widgets']; $new_sidebars_widgets = $new_options['options_value']['sidebars_widgets']; // $new_sidebars_widgets = $new_options['options_value']['sidebars_widgets'][0]['option_value']; $new_widget_posts = isset($new_options['options_value']['widget_posts']) ? $new_options['options_value']['widget_posts'] : array(); $new_grid_posts = isset($new_options['options_value']['grid_posts']) ? $new_options['options_value']['grid_posts'] : array(); // reset old grids $query = "DELETE FROM {$wpdb->posts} WHERE post_type LIKE 'bizz_grid' OR post_type LIKE 'bizz_widget' AND post_content_filtered = '{$themeid}' "; $wpdb->query($query); // reset backed up widgets delete_option($themeid . '_sidebars_widgets'); // update defaults option update_option('bizz_defaults_' . $themeid, true); // update widgets // bizz_update_widgets($new_sidebars_widgets, $new_all_widgets); // update posts bizzthemes_update_options('set_new', $new_all_widgets); bizzthemes_update_options('set_new', $new_sidebars_widgets); bizzthemes_insert_posts('set_new', array_merge($new_widget_posts, $new_grid_posts)); // redirect wp_redirect(admin_url('admin.php?page=bizz-tools&imported=true&type=Layouts')); #wp } } elseif ($new_options['options_id'] == 'settings') { if (version_compare($def_frame_version, $new_frame_version, '!=')) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Settings&error=version&tried={$new_frame_version}&yours={$def_frame_version}")); } else { // read options $new_options = $new_options['options_value']; // insert data update_option('bizzthemes_options', $new_options); // redirect wp_redirect(admin_url('admin.php?page=bizz-tools&imported=true&type=Settings')); #wp } } elseif ($new_options['options_id'] == 'design') { if (version_compare($def_frame_version, $new_frame_version, '!=')) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Design&error=version&tried={$new_frame_version}&yours={$def_frame_version}")); } elseif ($def_theme_id != $new_theme_id) { wp_redirect(admin_url("admin.php?page=bizz-tools&type=Design&error=theme&tried={$new_theme_id}&yours={$def_theme_id}")); } else { // read options $new_options = $new_options['options_value']; // insert data update_option('bizzthemes_design', $new_options); // reset custom designs bizz_generate_css(); // redirect wp_redirect(admin_url('admin.php?page=bizz-tools&imported=true&type=Design')); #wp } } } } } elseif (isset($_GET['download'])) { if ($_GET['download'] == 'layouts') { $widgets_array = bizz_get_active_widgets(); $bizz_get_widget_posts = bizz_get_widget_posts(); $bizz_get_grid_posts = bizz_get_grid_posts(); $sidebars_widgets = get_option('sidebars_widgets'); check_admin_referer('bizzthemes-download-layouts'); #wp header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="bizzthemes-layouts-' . date("Y-m-d") . '.json"'); $json_string = json_encode(array('theme_id' => $themeid, 'frame_version' => $frameversion, 'options_id' => 'layouts', 'options_value' => array('all_widgets' => $widgets_array, 'widget_posts' => $bizz_get_widget_posts, 'grid_posts' => $bizz_get_grid_posts, 'sidebars_widgets' => array('0' => array('option_name' => 'sidebars_widgets', 'option_value' => $sidebars_widgets, 'type' => 'sidebars_widgets'))))); echo str_replace("'", "\\'", $json_string); exit; } elseif ($_GET['download'] == 'settings') { check_admin_referer('bizzthemes-download-settings'); #wp header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="bizzthemes-settings-' . date("Y-m-d") . '.json"'); echo json_encode(array('theme_id' => $themeid, 'frame_version' => $frameversion, 'options_id' => 'settings', 'options_value' => $opt)); exit; } elseif ($_GET['download'] == 'design') { check_admin_referer('bizzthemes-download-design'); #wp header('Content-Description: File Transfer'); header('Cache-Control: public, must-revalidate'); header('Pragma: hack'); header('Content-Type: text/plain'); header('Content-Disposition: attachment; filename="bizzthemes-design-' . date("Y-m-d") . '.json"'); echo json_encode(array('theme_id' => $themeid, 'frame_version' => $frameversion, 'options_id' => 'design', 'options_value' => $optd)); exit; } } elseif (isset($_GET['restore'])) { if ($_GET['restore'] == 'layouts') { check_admin_referer('bizzthemes-restore-layouts'); #wp // fire the engine $default_action = 'set_defaults'; bizzthemes_default_layouts($default_action); wp_redirect(admin_url('admin.php?page=bizz-tools&restored=true&type=Layouts')); #wp } if ($_GET['restore'] == 'layouts-blank') { check_admin_referer('bizzthemes-restore-layouts'); #wp // fire the engine $default_action = 'reset'; bizzthemes_default_layouts($default_action); wp_redirect(admin_url('admin.php?page=bizz-tools&blank=true&type=Layouts')); #wp } elseif ($_GET['restore'] == 'settings') { check_admin_referer('bizzthemes-restore-settings'); #wp $query = "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'bizzthemes_options' OR option_name LIKE '%pag_exclude%' OR option_name LIKE '%pst_exclude%' "; $wpdb->query($query); wp_redirect(admin_url('admin.php?page=bizz-tools&restored=true&type=Settings')); #wp } elseif ($_GET['restore'] == 'design') { check_admin_referer('bizzthemes-restore-design'); #wp $query = "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'bizzthemes_design' "; $wpdb->query($query); bizz_generate_css(); wp_redirect(admin_url('admin.php?page=bizz-tools&restored=true&type=Design')); #wp } } }