function us_custom_styles() { global $of_options, $smof_data; // Resave theme custom CSS if the theme was updated $theme_version = us_get_main_theme_version(); $last_custom_css_version = get_option('us_custom_css_version'); if (empty($last_custom_css_version) or version_compare($last_custom_css_version, $theme_version, '<')) { $options_machine = new Options_Machine($of_options); $smof_data = array_merge($options_machine->Defaults, $smof_data); of_save_options($smof_data); us_save_styles($smof_data); update_option('us_custom_css_version', $theme_version); } $wp_upload_dir = wp_upload_dir(); $styles_dir = $wp_upload_dir['basedir'] . '/us_custom_css'; $styles_dir = str_replace('\\', '/', $styles_dir); $styles_file = $styles_dir . '/us_astra_custom_styles.css'; if (file_exists($styles_file)) { wp_register_style('us_custom_css', $wp_upload_dir['baseurl'] . '/us_custom_css/us_astra_custom_styles.css', array(), '1', 'all'); wp_enqueue_style('us_custom_css'); } else { global $load_styles_directly; $load_styles_directly = true; } if (get_template_directory_uri() != get_stylesheet_directory_uri()) { wp_register_style('astra-style', get_stylesheet_directory_uri() . '/style.css', array(), '1', 'all'); wp_enqueue_style('astra-style'); } }
/** * Ajax Save Options * * @uses get_option() * * @since 1.0.0 */ function of_ajax_callback() { global $options_machine, $of_options, $smof_data; $nonce = $_POST['security']; if (!wp_verify_nonce($nonce, 'of_ajax_nonce')) { die('-1'); } //get options array from db $all = of_get_options(); $save_type = $_POST['type']; //Uploads if ($save_type == 'upload') { $clickedID = $_POST['data']; // Acts as the name $filename = $_FILES[$clickedID]; $filename['name'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', $filename['name']); $override['test_form'] = false; $override['action'] = 'wp_handle_upload'; $uploaded_file = wp_handle_upload($filename, $override); $upload_tracking[] = $clickedID; //update $options array w/ image URL $upload_image = $all; //preserve current data $upload_image[$clickedID] = $uploaded_file['url']; of_save_options($upload_image); if (!empty($uploaded_file['error'])) { echo 'Upload Error: ' . $uploaded_file['error']; } else { echo $uploaded_file['url']; } // Is the Response } elseif ($save_type == 'image_reset') { $id = $_POST['data']; // Acts as the name $delete_image = $all; //preserve rest of data $delete_image[$id] = ''; //update array key with empty value of_save_options($delete_image); } elseif ($save_type == 'backup_options') { $backup = $all; $backup['backup_log'] = date('r'); of_save_options($backup, BACKUPS); die('1'); } elseif ($save_type == 'restore_options') { $smof_data = get_option(BACKUPS); update_option(OPTIONS, $smof_data); of_save_options($smof_data); if (!us_save_styles($smof_data)) { die(0); } die('1'); } elseif ($save_type == 'import_options') { $smof_data = unserialize(base64_decode($_POST['data'])); //100% safe - ignore theme check nag of_save_options($smof_data); if (!us_save_styles($smof_data)) { die(0); } die('1'); } elseif ($save_type == 'save') { wp_parse_str(stripslashes($_POST['data']), $smof_data); unset($smof_data['security']); unset($smof_data['of_save']); of_save_options($smof_data); // TODO If portfolio slug has changed, do flush_rewrite_rules(); if (!us_save_styles($smof_data)) { die(0); } die('1'); } elseif ($save_type == 'reset') { of_save_options($options_machine->Defaults); if (!us_save_styles($options_machine->Defaults)) { die(0); } die('1'); //options reset } die; }
function us_demo_import_options() { //select which files to import // $aviable_demos = array ('demo1', 'demo2',); // $demo_version = 'demo1'; // if (in_array($_POST['demo'], $aviable_demos)) { // $demo_version = $_POST['demo']; // } $smof_data = unserialize(base64_decode(file_get_contents(get_template_directory() . '/xml/options.txt'))); //100% safe - ignore theme check nag of_save_options($smof_data); us_save_styles($smof_data); echo 'ok'; die; }
function us_demo_import_options() { global $us_template_directory; $config = us_config('demo-import'); //select which files to import $aviable_demos = array_keys($config); $demo_version = $aviable_demos[0]; if (in_array($_POST['demo'], $aviable_demos)) { $demo_version = $_POST['demo']; } $smof_data = unserialize(base64_decode(file_get_contents($us_template_directory . '/demo-import/' . $demo_version . '-options.txt'))); //100% safe - ignore theme check nag of_save_options($smof_data); us_save_styles($smof_data); wp_send_json_success(); }
public function migrate_theme_options() { // Getting Options global $smof_data, $of_options; if (!isset($of_options) or empty($of_options)) { // Forcing options to be loaded even before the main init remove_action('init', 'of_options'); of_options(); } $options_changed = FALSE; foreach ($this->translators as $version => $translator) { if (method_exists($translator, 'translate_theme_options')) { $options_changed = ($translator->translate_theme_options($smof_data) or $options_changed); } } if ($options_changed) { // Filling the missed options with default values $options_machine = new Options_Machine($of_options); $smof_data = array_merge($options_machine->Defaults, $smof_data); $smof_data['generate_css_file'] = FALSE; // Saving the changed options of_save_options($smof_data); //update_option( OPTIONS, $smof_data ); us_save_styles($smof_data); } }