고급 코드 예시
이 예시들은 Ultimate Multisite와의 고급 통합 패턴을 보여줍니다.
동적 가격 엔진
볼륨, 충성도, 시즌별 할인 등을 적용하는 규칙 기반 가격 엔진:
class Dynamic_Pricing_Engine {
public function __construct() {
add_filter('wu_cart_total', [$this, 'apply_dynamic_pricing'], 20, 2);
}
public function apply_dynamic_pricing($total, $cart) {
$customer = $cart->get_customer();
$rules = $this->get_pricing_rules();
foreach ($rules as $rule) {
if ($this->rule_applies($rule, $cart, $customer)) {
$total = $this->apply_rule($rule, $total, $cart);
}
}
return $total;
}
private function get_pricing_rules() {
return [
[
'type' => 'volume_discount',
'condition' => ['total_greater_than' => 100],
'discount' => 0.1
],
[
'type' => 'loyalty_discount',
'condition' => ['customer_tenure_months' => 12],
'discount' => 0.15
],
[
'type' => 'seasonal_promo',
'condition' => ['date_range' => ['2024-11-01', '2024-12-31']],
'discount' => 0.2
]
];
}
private function rule_applies($rule, $cart, $customer) {
foreach ($rule['condition'] as $condition => $value) {
switch ($condition) {
case 'total_greater_than':
if ($cart->get_total() <= $value) return false;
break;
case 'customer_tenure_months':
if (!$customer || $customer->get_months_active() < $value) return false;
break;
case 'date_range':
$now = current_time('Y-m-d');
if ($now < $value[0] || $now > $value[1]) return false;
break;
}
}
return true;
}
private function apply_rule($rule, $total, $cart) {
$discount_amount = $total * $rule['discount'];
wu_log_add('pricing', sprintf(
'Applied %s rule: %.2f discount on total %.2f',
$rule['type'],
$discount_amount,
$total
));
return $total - $discount_amount;
}
}
new Dynamic_Pricing_Engine();
고급 사이트 프로비저닝
플랜 기능에 따라 플러그인, SSL, CDN, 백업, 모니터링을 자동으로 구성합니다:
class Advanced_Site_Provisioner {
public function __construct() {
add_action('wu_site_published', [$this, 'provision_site'], 10, 2);
}
public function provision_site($site, $membership) {
$plan = $membership->get_plan();
switch_to_blog($site->get_id());
// Install plugins based on plan
$this->install_plan_plugins($plan);
// Configure SSL
if ($plan->has_feature('ssl')) {
$this->setup_ssl($site);
}
// Setup CDN
if ($plan->has_feature('cdn')) {
$this->configure_cdn($site);
}
// Configure backups
if ($plan->has_feature('backups')) {
$this->setup_automated_backups($site, $plan->get_backup_frequency());
}
// Setup monitoring
$this->setup_site_monitoring($site, $membership->get_customer());
restore_current_blog();
$this->send_provisioning_complete_email($site, $membership);
}
private function install_plan_plugins($plan) {
$plugins = $plan->get_included_plugins();
foreach ($plugins as $plugin_slug) {
if ($this->plugin_exists($plugin_slug)) {
activate_plugin($plugin_slug);
$this->configure_plugin($plugin_slug, $plan);
}
}
}
private function setup_ssl($site) {
$ssl_service = new SSL_Provider_API();
$result = $ssl_service->request_certificate($site->get_domain());
if ($result->success) {
$site->add_meta('ssl_certificate_id', $result->certificate_id);
$site->add_meta('ssl_status', 'active');
}
}
private function configure_cdn($site) {
$cdn_service = new CDN_Provider_API();
$zone = $cdn_service->create_zone([
'name' => $site->get_domain(),
'type' => 'full'
]);
if ($zone->success) {
$site->add_meta('cdn_zone_id', $zone->id);
$this->update_cdn_dns($site, $zone);
}
}
private function setup_automated_backups($site, $frequency) {
$backup_service = new Backup_Provider_API();
$schedule = $backup_service->create_schedule([
'site_id' => $site->get_id(),
'frequency' => $frequency,
'retention' => 30
]);
$site->add_meta('backup_schedule_id', $schedule->id);
}
private function setup_site_monitoring($site, $customer) {
$monitoring_service = new Monitoring_API();
$monitor = $monitoring_service->create_monitor([
'url' => $site->get_domain(),
'customer_email' => $customer->get_email(),
'check_interval' => 300
]);
$site->add_meta('monitoring_id', $monitor->id);
}
}
new Advanced_Site_Provisioner();