$shape, )); } function yoone_snow_render_overlay() { if (!yoone_snow_is_enabled()) { return; } static $yoone_snow_rendered = false; if ($yoone_snow_rendered) { return; } $yoone_snow_rendered = true; echo ''; } add_action('wp_enqueue_scripts', 'yoone_snow_enqueue_assets'); add_action('wp_body_open', 'yoone_snow_render_overlay'); add_action('wp_footer', 'yoone_snow_render_overlay', 100); // 注册设置页面和设置项 用于选择雪花形状 function yoone_snow_register_settings() { // 注册设置项 选项名称为 yoone_snow_shape 默认值为 dot register_setting('yoone_snow_options', 'yoone_snow_shape', array( 'type' => 'string', 'sanitize_callback' => function($value) { // 对提交的值进行校验 只允许 dot flake mixed 三种 $allowed = array('dot', 'flake', 'mixed'); if (!is_string($value)) { return 'dot'; } return in_array($value, $allowed, true) ? $value : 'dot'; }, 'default' => 'dot', )); // 添加设置分区 标题为 Snow Settings add_settings_section( 'yoone_snow_section', 'Snow Settings', function() { // 输出分区描述 使用英文标点保证兼容 echo '
Configure snow appearance
'; }, 'yoone_snow' ); // 添加设置字段 下拉选择雪花形状 add_settings_field( 'yoone_snow_shape', 'Snow Shape', function() { // 渲染选择框 选项值 dot flake mixed $current = get_option('yoone_snow_shape', 'dot'); echo ''; echo 'Choose dot snowflake or mixed
'; }, 'yoone_snow', 'yoone_snow_section' ); } // 添加设置页面到后台菜单 条目在设置菜单下 function yoone_snow_add_settings_page() { add_options_page( 'Yoone Snow', 'Yoone Snow', 'manage_options', 'yoone_snow', function() { // 渲染设置页面 表单提交到 options.php echo '