/** * * Function to create callback for template save ajax request * * @return null * **/ function dynamo_template_save_callback() { // getting access to the template global object. global $dynamo_tpl; // check user capability to made operation if (current_user_can('manage_options')) { // check security with nonce. if (function_exists('check_ajax_referer')) { check_ajax_referer('DynamoWPNonce', 'security'); } // save the settings - iterate throught all $_POST variables foreach ($_POST as $key => $value) { if (strpos($key, $dynamo_tpl->name . '_') !== false) { update_option($key, esc_attr($value)); } } CompileOptionsLess('options.less'); // return the results __('Settings saved', DPTPLNAME); // this is required to return a proper result die; } else { wp_die(__('You don\'t have sufficient permissions to access this page!', DPTPLNAME)); } }
function dynamo_importexport_options() { // getting access to the template and database global object. global $dynamo_tpl; global $wpdb; wp_register_style('dp-import-export-css', get_template_directory_uri() . '/css/back-end/importexport.css'); wp_enqueue_style('dp-import-export-css'); // check permissions if (!current_user_can('manage_options')) { wp_die(__('You don\'t have sufficient permissions to access this page!', DPTPLNAME)); } // Import Starts Here ?> <div class="dpWrap wrap"> <h1><big><?php echo $dynamo_tpl->full_name; ?> </big><small><?php _e('Based on the Dynamo WP framework', DPTPLNAME); ?> </small></h1> <div class="dpImport"> <h2>Import Template Settings</h2> <?php if (isset($_FILES['import']) && check_admin_referer('dynamo_importexport')) { if ($_FILES['import']['error'] > 0) { echo "<div class='error'><p>No file selected, please make sure to select a file.</p></div>"; } else { $file_name = $_FILES['import']['name']; $file_ext = explode(".", $file_name); $file_ext = strtolower(end($file_ext)); $file_size = $_FILES['import']['size']; if ($file_ext == "json" && $file_size < 100000) { $encode_options = file_get_contents($_FILES['import']['tmp_name']); $options = json_decode($encode_options, true); if (is_array($options) && count($options) > 0) { foreach ($options as $key => $value) { update_option($key, esc_attr($value)); } } CompileOptionsLess('options.less'); echo "<div class='updated'><p>All template options are restored successfully.</p></div>"; } else { echo "<div class='error'><p>Invalid file or file size too big.</p></div>"; } } } ?> <p>1. Click "Browse" button and choose a backup file that you backup before.</p> <p>2. Click "Restore Template Settings" button to restore your template settings.</p> <form method='post' enctype='multipart/form-data'> <p class="submit"> <?php wp_nonce_field('dynamo_importexport'); ?> <input type='file' name='import' /> <input type='submit' name='submit' class="dpMedia" value='Restore Template Settings'/> </p> </form> </div> <?php // Export Starts Here if (!isset($_POST['export'])) { ?> <div class="dpExport"> <h2>Export Template Settings</h2> <p>When you click "Backup Template Settings" button, system will generate a template backup file for you to save on your computer.</p> <p>This backup file contains your template configuration and setting options.</p> <p>After exporting, you can either use the backup file to restore your template settings on this site again or another Wordpress site when using same template.</p> <form method='post'> <p class="submit"> <?php wp_nonce_field('dynamo_importexport'); ?> <input type='submit' name='export' class="dpMedia" value='Backup Template Settings'/> </p> </form> </div> <?php } elseif (check_admin_referer('dynamo_importexport')) { $option_prefix = $dynamo_tpl->name; $blogname = str_replace(" ", "", get_option('blogname')); $date = date("d_m_Y_H_i_s"); $json_name = $blogname . "_" . $dynamo_tpl->name . "_" . $date; // Generating filename. // get all rows with options containing specific prefix $options = $wpdb->get_results('SELECT option_value, option_name FROM ' . $wpdb->options . ' WHERE option_name LIKE \'' . $option_prefix . '%\';'); $value = array(); if ($options) { foreach ($options as $key) { $value[$key->option_name] = $key->option_value; } } $json_file = json_encode($value); // Encode data into json data ob_clean(); echo $json_file; header("Content-Type: text/json; charset=" . get_option('blog_charset')); header("Content-Disposition: attachment; filename={$json_name}.json"); exit; } ?> </div> <?php // Export Ends Here }
public function import_options($file) { global $wpdb; $file = get_template_directory() . '/dynamo_framework/import/files/' . $file; $encode_options = file_get_contents($file); $options = json_decode($encode_options, true); if (is_array($options) && count($options) > 0) { foreach ($options as $key => $value) { update_option($key, esc_attr($value)); } } CompileOptionsLess('options.less'); $homepage = get_page_by_title('Home'); if ($homepage) { update_option('page_on_front', $homepage->ID); update_option('show_on_front', 'page'); } $locations = get_theme_mod('nav_menu_locations'); $term = get_term_by('name', 'Sample Menu', 'nav_menu'); $locations['mainmenu'] = $term->term_id; $term = get_term_by('name', 'Footer Menu', 'nav_menu'); $locations['footer-menu'] = $term->term_id; set_theme_mod('nav_menu_locations', $locations); }