0 ? $v : 1; } private static function autoload_versions($domain) { $domains = self::DOMAINS; if (!in_array($domain, $domains, true)) { $domains[] = $domain; } $alloptions = wp_load_alloptions(); $absent = array(); foreach ($domains as $d) { if (isset(self::$l1[self::AUTOLOADED_MEMO . $d])) { continue; } self::$l1[self::AUTOLOADED_MEMO . $d] = true; $name = self::VERSION_OPTION_PREFIX . $d; if (!array_key_exists($name, $alloptions)) { $absent[] = $name; } } if (!$absent) { return; } global $wpdb; $in = implode(',', array_fill(0, count($absent), '%s')); $stored = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name IN ($in)", $absent)); $stored = array_map('strval', (array) $stored); if ($stored) { if (function_exists('wp_set_option_autoload_values')) { wp_set_option_autoload_values(array_fill_keys($stored, true)); } else { $in = implode(',', array_fill(0, count($stored), '%s')); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->options} SET autoload = 'yes' WHERE option_name IN ($in)", $stored)); foreach ($stored as $name) { wp_cache_delete($name, 'options'); } wp_cache_delete('alloptions', 'options'); } } $missing = array_values(array_diff($absent, $stored)); if ($missing) { $autoload = function_exists('wp_autoload_values_to_autoload') ? 'on' : 'yes'; $rows = array(); $args = array(); foreach ($missing as $name) { $rows[] = "(%s, '1', %s)"; $args[] = $name; $args[] = $autoload; } $wpdb->query($wpdb->prepare("INSERT IGNORE INTO {$wpdb->options} (option_name, option_value, autoload) VALUES " . implode(', ', $rows), $args)); $notoptions = wp_cache_get('notoptions', 'options'); if (is_array($notoptions)) { foreach ($missing as $name) { unset($notoptions[$name]); } wp_cache_set('notoptions', $notoptions, 'options'); } foreach ($missing as $name) { wp_cache_delete($name, 'options'); } wp_cache_delete('alloptions', 'options'); } } private static function compose_key($domain, $key) { return $domain . ':' . self::get_version($domain) . ':' . $key; } public static function user_context_key($user_id = null) { if ($user_id === null) { $user_id = get_current_user_id(); } $user_id = (int) $user_id; $ctx = self::roles_and_classes_key($user_id); if (!class_exists('AIEO_DMM_Person_Key', false) && is_readable(__DIR__ . '/services/class-aieo-dmm-person-key.php')) { require_once __DIR__ . '/services/class-aieo-dmm-person-key.php'; } $sig = class_exists('AIEO_DMM_Person_Key', false) ? AIEO_DMM_Person_Key::signature() : ''; if ('' === $sig) { return $ctx; } $memo = '__uperson:' . $user_id . ':' . ((int) get_current_user_id() === $user_id ? 'c' : 'o') . ':' . $sig; if (!isset(self::$l1[$memo])) { self::$l1[$memo] = AIEO_DMM_Person_Key::for_user($user_id); } return '' === self::$l1[$memo] ? $ctx : $ctx . ':' . self::$l1[$memo]; } private static function roles_and_classes_key($user_id) { if (isset(self::$l1['__uctx:' . $user_id])) { return self::$l1['__uctx:' . $user_id]; } $roles = array(); if ($user_id > 0) { $user = get_userdata($user_id); if ($user && !empty($user->roles) && is_array($user->roles)) { $roles = $user->roles; } } else { $roles = array('guest'); } sort($roles); $loyalty = array(); if ($user_id > 0 && class_exists('AIEO_DMM_Pricing_Engine')) { $loyalty = AIEO_DMM_Pricing_Engine::instance()->get_loyalty_class_ids_for_user($user_id); sort($loyalty); } $ctx = md5(implode(',', $roles) . '|' . implode(',', $loyalty)); self::$l1['__uctx:' . $user_id] = $ctx; return $ctx; } }