wp-china-yes/client/class-site-identity.php
WenPai Dev 13d1d99487 feat: 集成文派云桥客户端 v2.1
- 新增 client/ 目录,包含 Bridge 客户端四个模块:
  - class-site-health.php: 每日站点健康上报(含 WooCommerce 扩展数据)
  - class-site-identity.php: 站点 UUID 唯一标识
  - class-fallback.php: 多级降级策略(Bridge → WordPress.org → 缓存)
  - wenpai-bridge-client.php: 引导加载器
- Plugin.php 新增 init_bridge_client() 方法,受 bridge 设置开关控制
- 版本号升级至 3.9.0

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-15 09:31:19 +00:00

55 lines
1.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* WenPai Bridge — 站点唯一标识管理
*
* 纯 PHP 独立模块,不依赖任何框架。
* 仅使用 WordPress 原生 API。
*
* @package WenPai\Bridge
* @since 1.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* 站点 UUID 生成与管理。
*
* UUID v4 格式,首次调用时生成并持久化到 wp_options。
* 多站点环境下使用 get_option非 get_site_option确保每个子站点独立 UUID。
*/
class WenPai_Bridge_Site_Identity {
/** @var string Option key */
const OPTION_KEY = 'wpcy_site_uuid';
/**
* 获取或生成站点唯一标识。
*
* 使用 add_option 避免并发竞态条件:
* add_option 在 key 已存在时返回 false不会覆盖。
*
* @return string UUID v4 字符串
*/
public static function get_uuid(): string {
$uuid = get_option( self::OPTION_KEY );
if ( ! $uuid ) {
$uuid = wp_generate_uuid4();
if ( ! add_option( self::OPTION_KEY, $uuid, '', 'yes' ) ) {
// 其他进程已创建,重新读取
$uuid = get_option( self::OPTION_KEY );
}
}
return $uuid;
}
/**
* 重置站点 UUID用户主动操作
*
* @return string 新生成的 UUID
*/
public static function reset_uuid(): string {
$uuid = wp_generate_uuid4();
update_option( self::OPTION_KEY, $uuid );
return $uuid;
}
}