/** * Execute upgrade routines if necessary * * @access private * @since 3.8.9 */ function _wpsc_maybe_upgrade() { $current_db_ver = (int) get_option('wpsc_db_version', 0); if (!_wpsc_needs_upgrade()) { return; } for ($i = $current_db_ver + 1; $i <= WPSC_DB_VERSION; $i++) { $file_path = WPSC_FILE_PATH . '/wpsc-admin/db-upgrades/routines/' . $i . '.php'; if (file_exists($file_path)) { require_once $file_path; } if (!function_exists('_wpsc_db_upgrade_' . $i)) { continue; } wpsc_core_flush_temporary_data(); call_user_func('_wpsc_db_upgrade_' . $i); update_option('wpsc_db_version', $i); } wpsc_core_flush_temporary_data(); }
/** * When we change versions, aggressively clear temporary data and WordPress cache. * * @since 3.8.14.1 * * @access private */ function _wpsc_clear_wp_cache_on_version_change() { if (defined('DOING_AJAX') && DOING_AJAX) { return; } $version_we_last_stored = get_option(__FUNCTION__, false); if ($version_we_last_stored != WPSC_VERSION) { // version changed, clear temporary data wpsc_core_flush_temporary_data(); // version changed, flush the object cache wp_cache_flush(); if (false === $version_we_last_stored) { // first time through we create the autoload option, we will read it every time add_option(__FUNCTION__, WPSC_VERSION, null, true); } else { update_option(__FUNCTION__, WPSC_VERSION); } } }
/** * Save submitted options to the database. * @since 3.8.8 * @uses check_admin_referer() Prevents CSRF. * @uses update_option() Saves options to the database. * @uses wpdb::query() Queries the database. * @uses wpdb::get_col() Queries the database. * @access public */ private function save_options($selected = '') { global $wpdb, $wpsc_gateways; $updated = 0; //This is to change the Overall target market selection check_admin_referer('update-options', 'wpsc-update-options'); //Should be refactored along with the Marketing tab if (isset($_POST['change-settings'])) { if (isset($_POST['wpsc_also_bought']) && $_POST['wpsc_also_bought'] == 'on') { update_option('wpsc_also_bought', 1); } else { update_option('wpsc_also_bought', 0); } if (isset($_POST['display_find_us']) && $_POST['display_find_us'] == 'on') { update_option('display_find_us', 1); } else { update_option('display_find_us', 0); } if (isset($_POST['wpsc_share_this']) && $_POST['wpsc_share_this'] == 'on') { update_option('wpsc_share_this', 1); } else { update_option('wpsc_share_this', 0); } if (isset($_POST['wpsc_ga_disable_tracking']) && $_POST['wpsc_ga_disable_tracking'] == '1') { update_option('wpsc_ga_disable_tracking', 1); } else { update_option('wpsc_ga_disable_tracking', 0); } if (isset($_POST['wpsc_ga_currently_tracking']) && $_POST['wpsc_ga_currently_tracking'] == '1') { update_option('wpsc_ga_currently_tracking', 1); } else { update_option('wpsc_ga_currently_tracking', 0); } if (isset($_POST['wpsc_ga_advanced']) && $_POST['wpsc_ga_advanced'] == '1') { update_option('wpsc_ga_advanced', 1); update_option('wpsc_ga_currently_tracking', 1); } else { update_option('wpsc_ga_advanced', 0); } if (isset($_POST['wpsc_ga_tracking_id']) && !empty($_POST['wpsc_ga_tracking_id'])) { update_option('wpsc_ga_tracking_id', esc_attr($_POST['wpsc_ga_tracking_id'])); } else { update_option('wpsc_ga_tracking_id', ''); } } if (empty($_POST['countrylist2']) && !empty($_POST['wpsc_options']['currency_sign_location'])) { $selected = 'none'; } if (!isset($_POST['countrylist2'])) { $_POST['countrylist2'] = ''; } if (!isset($_POST['country_id'])) { $_POST['country_id'] = ''; } if (!isset($_POST['country_tax'])) { $_POST['country_tax'] = ''; } if ($_POST['countrylist2'] != null || !empty($selected)) { $AllSelected = false; if ($selected == 'all') { $wpdb->query("UPDATE `" . WPSC_TABLE_CURRENCY_LIST . "` SET visible = '1'"); $AllSelected = true; } if ($selected == 'none') { $wpdb->query("UPDATE `" . WPSC_TABLE_CURRENCY_LIST . "` SET visible = '0'"); $AllSelected = true; } if ($AllSelected != true) { $countrylist = $wpdb->get_col("SELECT id FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY country ASC "); //find the countries not selected $unselectedCountries = array_diff($countrylist, $_POST['countrylist2']); foreach ($unselectedCountries as $unselected) { $wpdb->update(WPSC_TABLE_CURRENCY_LIST, array('visible' => 0), array('id' => $unselected), '%d', '%d'); } //find the countries that are selected $selectedCountries = array_intersect($countrylist, $_POST['countrylist2']); foreach ($selectedCountries as $selected) { $wpdb->update(WPSC_TABLE_CURRENCY_LIST, array('visible' => 1), array('id' => $selected), '%d', '%d'); } } WPSC_Countries::clear_cache(); wpsc_core_flush_temporary_data(); } $previous_currency = get_option('currency_type'); //To update options if (isset($_POST['wpsc_options'])) { $_POST['wpsc_options'] = stripslashes_deep($_POST['wpsc_options']); // make sure stock keeping time is a number if (isset($_POST['wpsc_options']['wpsc_stock_keeping_time'])) { $skt = $_POST['wpsc_options']['wpsc_stock_keeping_time']; // I hate repeating myself $skt = (double) $skt; if ($skt <= 0 || $skt < 1 && $_POST['wpsc_options']['wpsc_stock_keeping_interval'] == 'hour') { unset($_POST['wpsc_options']['wpsc_stock_keeping_time']); unset($_POST['wpsc_options']['wpsc_stock_keeping_interval']); } } foreach ($_POST['wpsc_options'] as $key => $value) { if ($value != get_option($key)) { update_option($key, $value); $updated++; } } } if ($previous_currency != get_option('currency_type')) { $currency_code = $wpdb->get_var("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id` IN ('" . absint(get_option('currency_type')) . "')"); $selected_gateways = get_option('custom_gateway_options'); $already_changed = array(); foreach ($selected_gateways as $selected_gateway) { if (isset($wpsc_gateways[$selected_gateway]['supported_currencies'])) { if (in_array($currency_code, $wpsc_gateways[$selected_gateway]['supported_currencies']['currency_list'])) { $option_name = $wpsc_gateways[$selected_gateway]['supported_currencies']['option_name']; if (!in_array($option_name, $already_changed)) { update_option($option_name, $currency_code); $already_changed[] = $option_name; } } } } } foreach ($GLOBALS['wpsc_shipping_modules'] as $shipping) { if (is_object($shipping)) { $shipping->submit_form(); } } //This is for submitting shipping details to the shipping module if (!isset($_POST['update_gateways'])) { $_POST['update_gateways'] = ''; } if (!isset($_POST['custom_shipping_options'])) { $_POST['custom_shipping_options'] = null; } if ($_POST['update_gateways'] == 'true') { update_option('custom_shipping_options', $_POST['custom_shipping_options']); $shipadd = 0; foreach ($GLOBALS['wpsc_shipping_modules'] as $shipping) { foreach ((array) $_POST['custom_shipping_options'] as $shippingoption) { if ($shipping->internal_name == $shippingoption) { $shipadd++; } } } } }
function _wpsc_meta_migrate_anonymous_user_cron() { global $wpdb; set_time_limit(10 * 60); // 10 minutes maximum for the cron // WPEC created user records with a funky format, no email is a dead giveaway, as is login, user name and display name being idnentical with the '_' $sql = 'SELECT count( ID ) FROM ' . $wpdb->users . ' WHERE user_login LIKE "\\_%" AND user_email = "" AND user_login = user_nicename AND user_login = display_name LIMIT 1'; $ids_to_migrate = $user_ids = $wpdb->get_var($sql); if ($ids_to_migrate) { $response = wp_remote_post(admin_url('admin-ajax.php') . '?action=wpsc_migrate_anonymous_user', array('blocking' => true)); wp_schedule_single_event(time() + 30, 'wpsc_migrate_anonymous_user_cron'); } else { wpsc_core_flush_temporary_data(); } }