wp-china-yes/Service/Setting.php
feibisi f431a7556d Refactor and extend service architecture
Refactored service initialization to support modular loading and error handling. Enhanced Acceleration service with unified output buffering, regex/string replacement, performance logging, and version control for static assets. Added new services for comments, language, lazy translation, migration, modern settings, translation management, and widgets. Improved font loading logic and added RTL mirror support. Updated avatar service to support preconnect for multiple providers. Various bug fixes and code organization improvements.
2025-09-27 01:38:32 +08:00

1592 lines
No EOL
59 KiB
PHP
Executable file
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
namespace WenPai\ChinaYes\Service;
defined( 'ABSPATH' ) || exit;
use WP_CHINA_YES;
use function WenPai\ChinaYes\get_settings;
use function WenPai\ChinaYes\Service\tr;
/**
* Class Setting
* 插件设置服务
* @package WenPai\ChinaYes\Service
*/
class Setting {
private $prefix = 'wp_china_yes';
private $settings;
public function __construct() {
$this->settings = get_settings();
add_filter( 'wp_china_yes_enqueue_assets', '__return_true' );
add_filter( 'wp_china_yes_fa4', '__return_true' );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', [ $this, 'admin_menu' ] );
$this->admin_init();
}
/**
* 动态获取设置页面的 URL
*
* @return string
*/
private function get_settings_page_url() {
if ( is_multisite() ) {
return network_admin_url( 'settings.php?page=wp-china-yes' );
}
return admin_url( 'options-general.php?page=wp-china-yes' );
}
/**
* 挂载设置项
*/
public function admin_init() {
WP_CHINA_YES::createOptions( $this->prefix, [
'framework_title' => $this->settings['custom_name'],
'menu_hidden' => $this->settings['hide'],
'menu_title' => $this->settings['custom_name'],
'menu_slug' => 'wp-china-yes',
'menu_type' => 'submenu',
'menu_parent' => is_multisite() ? 'settings.php' : 'options-general.php',
'show_bar_menu' => false,
'show_sub_menu' => false,
'show_search' => false,
'show_reset_section' => true,
'footer_text' => sprintf( '%s 设置', $this->settings['custom_name'] ),
'theme' => 'light',
'enqueue_webfont' => false,
'async_webfont' => true,
'database' => is_multisite() ? 'network' : '',
] );
// 获取启用的 sections
$enabled_sections = $this->settings['enabled_sections'] ?? ['welcome', 'store', 'admincdn', 'cravatar', 'other', 'about'];
if (in_array('welcome', $enabled_sections)) {
$settings_page_url = $this->get_settings_page_url();
ob_start();
include CHINA_YES_PLUGIN_PATH . 'templates/welcome-section.php';
$welcome_content = ob_get_clean();
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '欢迎使用',
'icon' => 'icon icon-home-1',
'fields' => [
[
'type' => 'content',
'content' =>$welcome_content,
]
],
] );
}
if (in_array('store', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '应用市场',
'icon' => 'icon icon-shop',
'fields' => [
[
'id' => 'store',
'type' => 'radio',
'title' => '应用市场',
'inline' => true,
'options' => [
'wenpai' => '文派开源',
'proxy' => '官方镜像',
'off' => '不启用'
],
'default' => 'wenpai',
'subtitle' => '是否启用市场加速',
'desc' => '<a href="https://wenpai.org/" target="_blank">文派开源WenPai.org</a>中国境内自建托管仓库,同时集成文派翻译平台。<a href="https://wpmirror.com/" target="_blank">官方加速源WPMirror</a>直接从 .org 反代至大陆分发;可参考<a href="https://wpcy.com/document/wordpress-marketplace-acceleration" target="_blank">源站说明</a>。',
],
[
'id' => 'bridge',
'type' => 'switcher',
'default' => true,
'title' => '云桥更新',
'subtitle' => '是否启用更新加速',
'desc' => '<a href="https://wpbridge.com" target="_blank">文派云桥wpbridge</a>托管更新和应用分发渠道,可解决因 WordPress 社区分裂导致的混乱、旧应用无法更新,频繁 API 请求拖慢网速等问题。',
],
[
'id' => 'arkpress',
'type' => 'switcher',
'default' => false,
'title' => '联合存储库',
'subtitle' => '自动监控加速节点可用性',
'desc' => '<a href="https://maiyun.org" target="_blank">ArkPress.org </a>支持自动监控各加速节点可用性,当节点不可用时自动切换至可用节点或关闭加速,以保证您的网站正常访问',
],
],
] );
}
if (in_array('admincdn', $enabled_sections)) {
WP_CHINA_YES::createSection($this->prefix, [
'title' => '萌芽加速',
'icon' => 'icon icon-flash-1',
'fields' => [
[
'id' => 'admincdn_public',
'type' => 'checkbox',
'title' => '萌芽加速',
'inline' => true,
'options' => [
'googlefonts' => 'Google 字体',
'googleajax' => 'Google 前端库',
'cdnjs' => 'CDNJS 前端库',
'jsdelivr' => 'jsDelivr 前端库',
'bootstrapcdn' => 'Bootstrap 前端库',
],
'default' => [
'googlefonts' => 'googlefonts',
'googleajax' => '',
'cdnjs' => '',
'jsdelivr' => '',
'bootstrapcdn' => '',
],
'subtitle' => '是否启用萌芽加速',
'desc' => '<a href="https://admincdn.com/" target="_blank">萌芽加速adminCDN</a>将 WordPress 插件依赖的静态文件切换为公共资源,解决卡顿、加载慢等问题。您可按需启用加速项目,更多细节控制和功能,请查看<a href="https://wpcy.com/document/admincdn" target="_blank">推荐设置</a>。',
],
[
'id' => 'admincdn_files',
'type' => 'checkbox',
'title' => '文件加速',
'inline' => true,
'options' => [
'admin' => '后台加速',
'frontend' => '前台加速',
'emoji' => 'Emoji加速',
'sworg' => '预览加速',
],
'default' => [
'admin' => 'admin',
'frontend' => '',
'emoji' => 'emoji',
'sworg' => '',
],
'subtitle' => '是否启用文件加速',
'desc' => tr('专为 WordPress 系统内置依赖的静态资源进行加速,加快网站访问速度,如遇异常请停用对应选项。预览加速可在不切换应用市场时加速插件目录预览截图。',
'wp-china-yes'),
],
[
'id' => 'admincdn_dev',
'type' => 'checkbox',
'title' => '开发加速',
'inline' => true,
'options' => [
'react' => 'React 前端库',
'jquery' => 'jQuery 前端库',
'vuejs' => 'Vue.js 前端库',
'datatables' => 'DataTables 前端库',
'tailwindcss' => 'Tailwind CSS'
],
'default' => [
'react' => '',
'jquery' => 'jquery',
'vuejs' => '',
'datatables' => '',
'tailwindcss' => '',
],
'subtitle' => '是否启用文件加速',
'desc' => tr('部分高级 WordPress 插件主题会包含最新前端资源,可在此勾选对应的 adminCDN 子库专项加速。',
'wp-china-yes'),
],
[
'id' => 'admincdn_version_enable',
'type' => 'switcher',
'title' => '版本控制',
'subtitle' => '是否启用版本控制功能',
'desc' => tr('启用后可为CSS和JS文件自动添加版本号解决浏览器缓存问题。',
'wp-china-yes'),
'default' => false,
'class' => 'wp_china_yes-field wp_china_yes-field-switcher',
],
[
'id' => 'admincdn_version',
'type' => 'checkbox',
'title' => '版本控制选项',
'inline' => true,
'options' => [
'css' => 'CSS文件版本控制',
'js' => 'JS文件版本控制',
'disable_query' => '禁用查询参数版本',
'timestamp' => '使用时间戳版本',
],
'default' => [
'css' => 'css',
'js' => 'js',
'disable_query' => '',
'timestamp' => 'timestamp',
],
'subtitle' => '详细版本控制配置',
'desc' => tr('自动为CSS和JS文件添加基于文件修改时间的版本号解决浏览器缓存问题确保用户获取最新资源。',
'wp-china-yes'),
'dependency' => ['admincdn_version_enable', '==', 'true'],
],
],
]);
}
if (in_array('cravatar', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '初认头像',
'icon' => 'icon icon-profile-circle',
'fields' => [
[
'id' => 'cravatar',
'type' => 'radio',
'title' => '初认头像',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'weavatar' => '备用源WeAvatar.com',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用头像加速',
'desc' => tr( '<a href="https://cravatar.com/" target="_blank">初认头像Cravatar</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('windfonts', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '文风字体',
'icon' => 'icon icon-text',
'fields' => [
[
'id' => 'windfonts',
'type' => 'radio',
'title' => '文风字体',
'inline' => true,
'options' => [
'on' => '全局启用',
'frontend' => '前台启用',
'optimize' => '本机字体',
'off' => '不启用',
],
'default' => 'off',
'subtitle' => '是否启用文风字体定制',
'desc' => tr( '<a href="https://windfonts.com/" target="_blank">文风字体Windfonts</a>为您的网站增添无限活力。专为中文网页设计,旨在提升用户阅读体验和视觉享受。新手使用请先查看<a href="https://wpcy.com/document/chinese-fonts" target="_blank">字体使用说明</a>。',
'wp-china-yes' ),
],
[
'id' => 'windfonts_list',
'type' => 'group',
'title' => '字体列表',
'subtitle' => '使用的文风字体列表',
'desc' => '支持添加多个文风字体使用新的API接口格式支持更灵活的字体配置',
'button_title' => '添加字体',
'accordion_title_number' => true,
'dependency' => [
'windfonts',
'any',
'on,frontend',
],
'fields' => [
[
'id' => 'family',
'type' => 'text',
'title' => '字体名称',
'subtitle' => '字体family参数',
'desc' => tr( '支持多种格式:<br>• <code>FontName</code> - 基础字体名<br>• <code>FontName:wght@400;700</code> - 指定权重<br>• <code>FontName:lang@zh</code> - 指定语言<br>• <code>FontName:wght@400:lang@zh</code> - 同时指定权重和语言<br>详见<a href="https://app.windfonts.com/docs" target="_blank">API文档</a>',
'wp-china-yes' ),
'default' => 'cszt',
],
[
'id' => 'subset',
'type' => 'select',
'title' => '字体子集',
'subtitle' => '字体变体(优先级高于权重)',
'options' => [
'' => '不指定',
'regular' => 'Regular',
'bold' => 'Bold',
'light' => 'Light',
'medium' => 'Medium',
'semibold' => 'Semibold',
'thin' => 'Thin',
'extralight' => 'Extra Light',
'extrabold' => 'Extra Bold',
'black' => 'Black',
],
'default' => 'regular',
'desc' => tr( '直接指定字体变体,优先级大于权重设置',
'wp-china-yes' ),
],
[
'id' => 'lang',
'type' => 'select',
'title' => '语言设置',
'subtitle' => '字体语言支持',
'options' => [
'' => '不指定',
'zh' => '纯中文字符',
],
'desc' => tr( '设置为"纯中文字符"时,字体样式只对中文字符生效',
'wp-china-yes' ),
],
[
'id' => 'weight',
'type' => 'number',
'title' => '字体字重',
'subtitle' => '字体字重大小当未指定subset时生效',
'desc' => tr( '设置字体权重大小字体粗细当指定了subset时此设置无效',
'wp-china-yes' ),
'default' => 400,
'attributes' => [
'min' => 100,
'max' => 900,
'step' => 100,
],
'validate' => 'csf_validate_numeric',
],
[
'id' => 'style',
'type' => 'select',
'title' => '字体样式',
'subtitle' => '字体样式选择',
'options' => [
'normal' => '正常',
'italic' => '斜体',
'oblique' => '倾斜',
],
'default' => 'normal',
'desc' => tr( '设置字体样式(正常、斜体、倾斜)',
'wp-china-yes' ),
],
[
'id' => 'selector',
'type' => 'textarea',
'title' => '字体应用',
'subtitle' => '字体应用元素',
'desc' => tr( '设置字体应用的元素CSS 选择器)',
'wp-china-yes' ),
'default' => 'a:not([class]),p,h1,h2,h3,h4,h5,h6,ul,ol,li,button,blockquote,pre,code,table,th,td,label,b,i:not([class]),em,small,strong,sub,sup,ins,del,mark,abbr,dfn,span:not([class])',
'sanitize' => false,
],
[
'id' => 'enable',
'type' => 'switcher',
'title' => '启用字体',
'subtitle' => '是否启用该字体',
'default' => true,
],
],
],
[
'id' => 'windfonts_typography_cn',
'type' => 'checkbox',
'title' => '中文排印',
'inline' => true,
'options' => [
'corner' => '直角括号',
'space' => '文本空格',
'punctuation' => '标点显示',
'indent' => '段首缩进',
'align' => '两端对齐',
],
'default' => '',
'subtitle' => '是否启用中文排印优化',
'desc' => tr( '文风字体中文排印优化可提升中文网页的视觉美感,适用于正式内容的网站。',
'wp-china-yes' ),
],
[
'id' => 'windfonts_typography_en',
'type' => 'checkbox',
'title' => '英文排印',
'inline' => true,
'options' => [
'optimize' => '排版优化',
'spacing' => '去双空格',
'orphan' => '避免孤行',
'widow' => '避免寡行',
'punctuation' => '中英标点',
],
'default' => '',
'subtitle' => '是否启用英文排印优化',
'desc' => tr( 'Windfonts 英文排印优化可提升英文网页的视觉美感,适用于多语内容网站。',
'wp-china-yes' ),
],
[
'id' => 'windfonts_reading_enable',
'type' => 'switcher',
'title' => 'RTL镜像测试',
'subtitle' => '是否启用RTL镜像测试功能',
'desc' => tr( '启用后可以帮助LTR语言使用者测试RTL网站布局效果。',
'wp-china-yes' ),
'default' => false,
'class' => 'wp_china_yes-field wp_china_yes-field-switcher',
],
[
'id' => 'windfonts_reading',
'type' => 'radio',
'title' => 'RTL镜像模式',
'inline' => true,
'options' => [
'global' => '全局启用',
'frontend' => '前台启用',
'off' => '不启用',
],
'default' => 'off',
'subtitle' => 'RTL镜像测试模式选择',
'desc' => tr( 'RTL镜像测试功能可以帮助LTR语言使用者测试RTL网站布局通过水平镜像让RTL布局看起来像LTR。',
'wp-china-yes' ),
'dependency' => ['windfonts_reading_enable', '==', 'true'],
],
],
] );
}
if (in_array('motucloud', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '墨图云集',
'icon' => 'icon icon-gallery',
'fields' => [
[
'id' => 'motucloud',
'type' => 'radio',
'title' => '墨图云集',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'weavatar' => '备用源WeAvatar.com',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用墨图云集',
'desc' => tr( '<a href="https://motucloud.com/" target="_blank">墨图云集MotuCloud</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('fewmail', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '飞秒邮箱',
'icon' => 'icon icon-sms-tracking',
'fields' => [
[
'id' => 'fewmail',
'type' => 'radio',
'title' => '飞秒邮箱',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'weavatar' => '备用源WeAvatar.com',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用飞秒邮箱',
'desc' => tr( '<a href="https://fewmail.com/" target="_blank">飞秒邮箱FewMail</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('wordyeah', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '无言会语',
'icon' => 'icon icon-message-text',
'fields' => [
[
'id' => 'comments_enable',
'type' => 'switcher',
'title' => '评论增强',
'subtitle' => '是否启用评论增强功能',
'desc' => tr( '启用后可以使用角色徽章、表单验证、阿巴阿巴模式等评论增强功能。',
'wp-china-yes' ),
'default' => false,
'class' => 'wp_china_yes-field wp_china_yes-field-switcher',
],
[
'id' => 'comments_role_badge',
'type' => 'switcher',
'title' => '角色徽章',
'subtitle' => '为评论作者显示角色标识',
'desc' => tr( '在评论作者名称后显示用户角色徽章(管理员、编辑、作者等),提升评论区权威性。',
'wp-china-yes' ),
'default' => true,
'dependency' => ['comments_enable', '==', 'true'],
],
[
'id' => 'comments_remove_website',
'type' => 'switcher',
'title' => '移除网站字段',
'subtitle' => '从评论表单中移除网站URL字段',
'desc' => tr( '移除评论表单中的网站字段,减少垃圾评论,简化表单填写。',
'wp-china-yes' ),
'default' => false,
'dependency' => ['comments_enable', '==', 'true'],
],
[
'id' => 'comments_validation',
'type' => 'switcher',
'title' => '评论验证',
'subtitle' => '启用前端表单验证',
'desc' => tr( '对评论表单进行前端验证,确保评论内容质量,提升用户体验。',
'wp-china-yes' ),
'default' => true,
'dependency' => ['comments_enable', '==', 'true'],
],
[
'id' => 'comments_herp_derp',
'type' => 'switcher',
'title' => '阿巴阿巴模式',
'subtitle' => '启用阿巴阿巴模式',
'desc' => tr( '提供阿巴阿巴模式切换按钮,可以模糊显示评论内容,增加趣味性。',
'wp-china-yes' ),
'default' => false,
'dependency' => ['comments_enable', '==', 'true'],
],
[
'id' => 'comments_sticky_moderate',
'type' => 'switcher',
'title' => '置顶审核',
'subtitle' => '启用置顶审核功能',
'desc' => tr( '在后台评论管理中添加置顶审核功能,优化审核流程。',
'wp-china-yes' ),
'default' => false,
'dependency' => ['comments_enable', '==', 'true'],
],
],
] );
}
if (in_array('blocks', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '笔笙区块',
'icon' => 'icon icon-document-1',
'fields' => [
[
'id' => 'bisheng',
'type' => 'radio',
'title' => '笔笙区块',
'inline' => true,
'options' => [
'cn' => '审核评论',
'global' => '强化评论',
'ban' => '禁用评论',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用笔笙区块',
'desc' => tr( '<a href="https://ibisheng.com/" target="_blank">笔笙区块Bisheng</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('deerlogin', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '灯鹿用户',
'icon' => 'icon icon-user-tick',
'fields' => [
[
'id' => 'deerlogin',
'type' => 'radio',
'title' => '灯鹿用户',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用灯鹿用户',
'desc' => tr( '<a href="https://deerlogin.com/" target="_blank">灯鹿用户DeerLogin</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('waimao', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '跨飞外贸',
'icon' => 'icon icon-chart-success',
'fields' => [
[
'id' => 'waimao_enable',
'type' => 'switcher',
'title' => '跨飞外贸',
'subtitle' => '启用外贸网站优化功能',
'default' => false,
'desc' => '启用后可以使用专为外贸网站设计的语言切换和优化功能。',
],
[
'id' => 'waimao_language_split',
'type' => 'switcher',
'title' => '前后台语言分离',
'subtitle' => '允许前台和后台使用不同语言',
'dependency' => ['waimao_enable', '==', 'true'],
'default' => false,
'desc' => '启用后后台将使用个人资料中的语言设置前台使用WordPress系统语言设置。',
],
[
'id' => 'waimao_admin_language',
'type' => 'select',
'title' => '后台语言',
'subtitle' => '设置后台管理界面语言',
'dependency' => ['waimao_language_split', '==', 'true'],
'options' => $this->get_available_languages(),
'default' => $this->get_current_admin_language(),
'desc' => '选择后台管理界面使用的语言,将应用到当前用户的个人资料设置。',
],
[
'id' => 'waimao_frontend_language',
'type' => 'select',
'title' => '前台语言',
'subtitle' => '设置前台网站语言',
'dependency' => ['waimao_language_split', '==', 'true'],
'options' => $this->get_available_languages(),
'default' => $this->get_current_frontend_language(),
'desc' => '选择前台网站使用的语言将应用到WordPress系统语言设置。',
],
[
'id' => 'waimao_auto_detect',
'type' => 'switcher',
'title' => '自动语言检测',
'subtitle' => '根据访客浏览器语言自动切换',
'dependency' => ['waimao_language_split', '==', 'true'],
'default' => false,
'desc' => '启用后,前台将根据访客的浏览器语言偏好自动选择合适的语言显示。',
],
],
] );
}
if (in_array('woocn', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => 'Woo电商',
'icon' => 'icon icon-shopping-cart',
'fields' => [
[
'id' => 'woocn',
'type' => 'radio',
'title' => 'Woo电商',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用灯鹿用户',
'desc' => tr( '<a href="https://deerlogin.com/" target="_blank">灯鹿用户DeerLogin</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('lelms', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '乐尔达思',
'icon' => 'icon icon-teacher',
'fields' => [
[
'id' => 'lelms',
'type' => 'radio',
'title' => '乐尔达思',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用乐尔达思',
'desc' => tr( '<a href="https://lelms.com/" target="_blank">乐尔达思LeLMS</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('wapuu', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '瓦普文创',
'icon' => 'icon icon-ticket-discount',
'fields' => [
[
'id' => 'wapuu',
'type' => 'radio',
'title' => '瓦普文创',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用瓦普文创',
'desc' => tr( '<a href="https://wapuu.com/" target="_blank">瓦普文创Wapuu</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('adblock', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '广告拦截',
'icon' => 'icon icon-eye-slash',
'fields' => [
[
'id' => 'adblock',
'type' => 'radio',
'title' => '广告拦截',
'inline' => true,
'options' => [
'on' => '启用',
'off' => '不启用',
],
'default' => 'off',
'subtitle' => '是否启用后台广告拦截',
'desc' => tr( '<a href="https://wpcy.com/adblocker" target="_blank">文派叶子🍃WPCY.COM</a>独家特色功能,让您拥有清爽整洁的 WordPress 后台,清除各类常用插件侵入式后台广告、通知及无用信息,拿回<a href="https://wpcy.com/document/ad-blocking-for-developers " target="_blank">后台控制权</a>。',
'wp-china-yes' ),
],
[
'id' => 'adblock_rule',
'type' => 'group',
'title' => '规则列表',
'subtitle' => '使用的广告拦截规则列表',
'desc' => tr( '默认规则跟随插件更新,插件更新后可删除规则重新添加以<a href="https://wpcy.com/adblocker" target="_blank">获取更多</a>最新拦截规则,出现异常,请尝试先停用规则<a href="https://wpcy.com/document/troubleshooting-ad-blocking" target="_blank">排查原因</a>。',
'wp-china-yes' ),
'button_title' => '添加规则',
'accordion_title_number' => true,
'dependency' => [
'adblock',
'any',
'on',
],
'fields' => [
[
'id' => 'name',
'type' => 'text',
'title' => '规则名称',
'subtitle' => '自定义规则名称',
'desc' => tr( '自定义规则名称,方便识别',
'wp-china-yes' ),
'default' => '默认规则',
],
[
'id' => 'selector',
'type' => 'textarea',
'title' => '应用元素',
'subtitle' => '规则应用元素',
'desc' => tr( '设置规则应用的广告元素CSS 选择器)',
'wp-china-yes' ),
'default' => '.wpseo_content_wrapper',
'sanitize' => false,
],
[
'id' => 'enable',
'type' => 'switcher',
'title' => '启用规则',
'subtitle' => '是否启用该规则',
'default' => true,
],
],
],
],
] );
}
if (in_array('notice', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '通知管理',
'icon' => 'icon icon-notification-bing',
'fields' => [
[
'id' => 'notice_block',
'type' => 'radio',
'title' => '通知管理',
'inline' => true,
'options' => [
'on' => '启用',
'off' => '不启用',
],
'default' => 'off',
'subtitle' => '是否启用后台通知管理',
'desc' => '管理和控制 WordPress 后台各类通知的显示。',
],
[
'id' => 'disable_all_notices',
'type' => 'switcher',
'title' => '禁用所有通知',
'subtitle' => '一键禁用所有后台通知',
'default' => false,
'dependency' => ['notice_block', '==', 'on'],
],
[
'id' => 'notice_control',
'type' => 'checkbox',
'title' => '选择性禁用',
'inline' => true,
'subtitle' => '选择需要禁用的通知类型',
'desc' => '可以按住 Ctrl/Command 键进行多选',
'chosen' => true,
'multiple' => true,
'options' => [
'core' => '核心更新通知',
'error' => '错误通知',
'warning' => '警告通知',
'info' => '信息通知',
'success' => '成功通知',
],
'dependency' => ['notice_block|disable_all_notices', '==|==', 'on|false'],
'default' => [],
],
[
'id' => 'notice_method',
'type' => 'radio',
'title' => '禁用方式',
'inline' => true,
'options' => [
'hook' => '移除钩子(推荐)',
'css' => 'CSS隐藏',
'both' => '双重保险',
],
'default' => 'hook',
'dependency' => ['notice_block|disable_all_notices', '==|==', 'on|false'],
],
],
] );
}
if (in_array('plane', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '飞行模式',
'icon' => 'icon icon-airplane',
'fields' => [
[
'id' => 'plane',
'type' => 'radio',
'title' => '飞行模式',
'inline' => true,
'options' => [
'on' => '启用',
'off' => '不启用',
],
'default' => 'off',
'subtitle' => '是否启用飞行模式',
'desc' => tr( '飞行模式可屏蔽 WordPress 插件主题在中国无法访问的 API 请求,加速网站前后台访问。注:部分外部请求为产品更新检测,若已屏蔽请定期检测。',
'wp-china-yes' ),
],
[
'id' => 'plane_rule',
'type' => 'group',
'title' => '规则列表',
'subtitle' => '飞行模式使用的 URL 屏蔽规则列表',
'desc' => tr( '支持添加多条 <a href="https://wpcy.com/document/advertising-blocking-rules" target="_blank">URL 屏蔽规则</a>',
'wp-china-yes' ),
'button_title' => '添加规则',
'accordion_title_number' => true,
'dependency' => [
'plane',
'any',
'on',
],
'fields' => [
[
'id' => 'name',
'type' => 'text',
'title' => '规则名称',
'subtitle' => '自定义规则名称',
'desc' => tr( '自定义规则名称,方便识别',
'wp-china-yes' ),
'default' => '未命名规则',
],
[
'id' => 'url',
'type' => 'textarea',
'title' => 'URL',
'subtitle' => 'URL',
'desc' => tr( '填入需要屏蔽的 URL 链接,一行一条,注意不要串行',
'wp-china-yes' ),
'default' => '',
'placeholder' => 'example.com',
'sanitize' => false,
],
[
'id' => 'enable',
'type' => 'switcher',
'title' => '启用规则',
'subtitle' => '是否启用该规则',
'default' => true,
],
],
]
],
] );
}
if (in_array('monitor', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '脉云维护',
'icon' => 'icon icon-story',
'fields' => [
[
'id' => 'monitor',
'type' => 'switcher',
'default' => true,
'title' => '节点监控',
'subtitle' => '自动监控加速节点可用性',
'desc' => tr( '<a href="https://maiyun.org" target="_blank">脉云维护MainCloud</a>支持自动监控各加速节点可用性,当节点不可用时自动切换至可用节点或关闭加速,以保证您的网站正常访问',
'wp-china-yes' ),
],
[
'id' => 'memory',
'type' => 'switcher',
'default' => true,
'title' => '系统监控',
'subtitle' => '自动监控系统运行状态',
'desc' => tr( '支持在管理后台页脚中显示系统运行状态包括内存使用、CPU负载、MySQL版本、调试状态等信息',
'wp-china-yes' ),
],
[
'id' => 'memory_display',
'type' => 'checkbox',
'title' => '显示参数',
'inline' => true,
'options' => [
'memory_usage' => '内存使用量',
'wp_limit' => '内存限制',
'server_ip' => '服务器 IP',
'hostname' => '主机名称',
'os_info' => '操作系统',
'mysql_version'=> 'MySQL版本',
'cpu_usage' => 'CPU使用率',
'debug_status' => '调试状态',
'php_info' => 'PHP 版本'
],
'default' => [
'memory_usage',
'wp_limit',
'server_ip',
'php_info',
],
'subtitle' => '选择页脚要显示的信息',
'desc' => '为网站维护人员提供参考依据,无需登录服务器即可查看相关信息参数',
'dependency' => ['memory', '==', 'true'],
],
[
'id' => 'disk',
'type' => 'switcher',
'default' => true,
'title' => '站点监控',
'subtitle' => '自动监控站点运行状态',
'desc' => tr( '支持在管理后台页脚中显示系统运行状态包括内存使用、CPU负载、MySQL版本、调试状态等信息',
'wp-china-yes' ),
],
[
'id' => 'disk_display',
'type' => 'checkbox',
'title' => '显示参数',
'inline' => true,
'options' => [
'disk_usage' => '磁盘用量',
'disk_limit' => '剩余空间',
'media_num' => '媒体数量',
'admin_num' => '管理数量',
'user_num' => '用户数量',
'lastlogin' => '上次登录',
],
'default' => [
'disk_usage',
'disk_limit',
'media_num',
'admin_num',
],
'subtitle' => '选择概览要显示的信息',
'desc' => '为网站管理人员提供参考依据,进入后台仪表盘即可查看相关信息参数',
'dependency' => ['disk', '==', 'true'],
],
[
'id' => 'maintenance_mode',
'type' => 'switcher',
'default' => false,
'title' => '启用维护模式',
'subtitle' => '启用或禁用网站维护模式',
'desc' => '启用后,网站将显示维护页面,只有管理员可以访问。',
],
[
'id' => 'maintenance_settings',
'type' => 'fieldset',
'title' => '维护模式设置',
'fields' => [
[
'id' => 'maintenance_title',
'type' => 'text',
'title' => '页面标题',
'default' => '网站维护中',
],
[
'id' => 'maintenance_heading',
'type' => 'text',
'title' => '主标题',
'default' => '网站维护中',
],
[
'id' => 'maintenance_message',
'type' => 'textarea',
'title' => '维护说明',
'default' => '网站正在进行例行维护,请稍后访问。感谢您的理解与支持!',
],
],
'dependency' => ['maintenance_mode', '==', 'true'],
]
],
] );
}
if (in_array('security', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '雨滴安全',
'icon' => 'icon icon-shield',
'fields' => [
[
'id' => 'yoodefender',
'type' => 'radio',
'title' => '雨滴安全',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用雨滴安全',
'desc' => tr( '<a href="https://yoodefender.com/" target="_blank">雨滴安全YooDefender</a>安全设置可以帮助增强 WordPress 的安全性,请根据实际需求启用相关选项。更多选项请安装 WPBan 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
[
'id' => 'disallow_file_edit',
'type' => 'switcher',
'title' => '禁用文件编辑',
'subtitle' => '禁用 WordPress 后台的主题和插件编辑器',
'default' => true,
'desc' => '启用后,用户无法通过 WordPress 后台编辑主题和插件文件。',
],
[
'id' => 'disallow_file_mods',
'type' => 'switcher',
'title' => '禁用文件修改',
'subtitle' => '禁止用户安装、更新或删除主题和插件',
'default' => false,
'desc' => '启用后,用户无法通过 WordPress 后台安装、更新或删除主题和插件。',
],
],
] );
}
if (in_array('performance', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '性能优化',
'icon' => 'icon icon-speedometer',
'fields' => [
[
'id' => 'performance',
'type' => 'switcher',
'title' => '性能优化',
'subtitle' => '是否启用性能优化',
'default' => true,
'desc' => '性能优化设置可以帮助提升 WordPress 的运行效率,请根据服务器配置合理调整。',
],
[
'id' => 'wp_memory_limit',
'type' => 'text',
'title' => '内存限制',
'subtitle' => '设置 WordPress 内存限制',
'default' => '40M',
'desc' => '设置 WordPress 的内存限制,例如 64M、128M、256M 等。',
'dependency' => ['performance', '==', 'true'],
],
[
'id' => 'wp_max_memory_limit',
'type' => 'text',
'title' => '后台内存限制',
'subtitle' => '设置 WordPress 后台内存限制',
'default' => '256M',
'desc' => '设置 WordPress 后台的内存限制,例如 128M、256M、512M 等。',
'dependency' => ['performance', '==', 'true'],
],
[
'id' => 'wp_post_revisions',
'type' => 'number',
'title' => '文章修订版本',
'subtitle' => '控制文章修订版本的数量',
'default' => -1, // -1 表示启用所有修订版本
'desc' => '设置为 0 禁用修订版本,或设置为一个固定值(如 5限制修订版本数量。',
'dependency' => ['performance', '==', 'true'],
],
[
'id' => 'autosave_interval',
'type' => 'number',
'title' => '自动保存间隔',
'subtitle' => '设置文章自动保存的时间间隔(秒)',
'default' => 60,
'desc' => '设置文章自动保存的时间间隔,默认是 60 秒。',
'dependency' => ['performance', '==', 'true'],
],
],
] );
}
if (in_array('brand', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '品牌白标',
'icon' => 'icon icon-password-check',
'fields' => [
[
'id' => 'custom_name',
'type' => 'text',
'title' => '品牌白标',
'subtitle' => '自定义插件显示品牌名',
'desc' => '专为 WordPress 建站服务商和代理机构提供的<a href="https://wpcy.com/white-label" target="_blank">自定义品牌 OEM </a>功能,输入您的品牌词启用后生效',
'default' => "文派叶子",
],
[
'id' => 'header_logo',
'type' => 'media',
'title' => '品牌 Logo',
'subtitle' => '自定义插件显示品牌 Logo',
'library' => 'image',
'preview' => true,
'preview_size' => 'thumbnail',
'preview_width' => 120,
'preview_height' => 120,
'button_title' => '上传 Logo',
'remove_title' => '移除 Logo',
'placeholder' => '未选择 Logo',
'desc' => '上传或选择媒体库的图片作为品牌 Logo',
'default' => [
'url' => plugins_url('wp-china-yes/assets/images/wpcy-logo.png'),
'id' => 0,
'width' => 120,
'height' => 120,
'thumbnail' => plugins_url('wp-china-yes/assets/images/wpcy-logo.png'),
'alt' => '文派叶子 Logo',
'title' => '文派叶子',
'description' => '文派叶子默认Logo'
],
],
[
'id' => 'hide_option',
'type' => 'switcher',
'default' => false,
'title' => '隐藏设置',
'subtitle' => '隐藏插件设置信息',
'desc' => tr( '如果您不希望让客户知道本站启用了<a href="https://wpcy.com/" target="_blank">文派叶子🍃WPCY.COM</a>插件及服务,可开启此选项。',
'wp-china-yes' ),
],
[
'id' => 'hide_elements',
'type' => 'checkbox',
'title' => '隐藏元素',
'subtitle' => '选择需要隐藏的界面元素',
'desc' => '隐藏插件界面中的品牌相关元素,提升白标效果',
'inline' => true,
'options' => [
'hide_logo' => '隐藏 Logo',
'hide_title' => '隐藏插件名',
'hide_version' => '隐藏版本号',
'hide_copyright' => '隐藏版权信息',
],
'default' => [],
'dependency' => ['hide_option', '==', 'true'],
],
[
'id' => 'hide_menu_confirm',
'type' => 'checkbox',
'title' => '隐藏菜单确认',
'subtitle' => '⚠️ 危险操作请先保存访问URL',
'desc' => '当前页面URL<code>' . (is_multisite() ? network_admin_url('settings.php?page=wp-china-yes') : admin_url('options-general.php?page=wp-china-yes')) . '</code><br>隐藏菜单后只能通过此URL访问设置页面',
'options' => [
'confirmed' => '我已保存URL并了解风险确认要隐藏菜单'
],
'default' => [],
'dependency' => ['hide_option', '==', 'true'],
],
[
'id' => 'hide_menu',
'type' => 'switcher',
'title' => '隐藏菜单',
'subtitle' => '从WordPress后台菜单中隐藏插件入口',
'desc' => '启用后插件菜单将从后台消失只能通过直接URL访问',
'default' => false,
'dependency' => ['hide_menu_confirm|confirmed', '==', 'confirmed'],
],
[
'id' => 'enable_custom_rss',
'type' => 'switcher',
'title' => '品牌新闻',
'subtitle' => '是否启用定制新闻源',
'desc' => '启用后,您可以自定义[文派茶馆]新闻源,输入自己的 RSS 源之后即可显示信息流。',
'default' => false
],
[
'id' => 'custom_rss_url',
'type' => 'text',
'title' => '自定义 RSS 源',
'subtitle' => '添加自定义 RSS 新闻源',
'desc' => '请输入有效的 RSS Feed URL长期无更新时会恢复显示默认新闻源。',
'default' => 'https://one.weixiaoduo.com/feed',
'dependency' => ['enable_custom_rss', '==', true]
],
[
'id' => 'custom_rss_refresh',
'type' => 'select',
'title' => 'RSS 刷新频率',
'options' => [
'1800' => '30分钟',
'3600' => '1小时',
'7200' => '2小时',
'14400' => '4小时',
'28800' => '8小时'
],
'default' => '14400',
'dependency' => ['enable_custom_rss', '==', true]
],
[
'id' => 'rss_display_options',
'type' => 'checkbox',
'inline' => true,
'title' => 'RSS 显示选项',
'subtitle' => '选择需要显示的内容',
'options' => [
'show_date' => '显示日期',
'show_summary' => '显示摘要',
'show_footer' => '显示页脚',
],
'default' => ['show_date', 'show_summary', 'show_footer'], // 默认全部勾选
'dependency' => ['enable_custom_rss', '==', true]
],
],
]);
}
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '其他设置',
'icon' => 'icon icon-setting',
'fields' => [
[
'id' => 'enable_db_tools',
'type' => 'switcher',
'title' => '数据库工具',
'subtitle' => '启用数据库维护功能',
'default' => false,
'desc' => '启用后可访问WordPress内置的数据库修复工具。使用前请备份数据库。',
],
[
'id' => 'db_tools_link',
'type' => 'content',
'title' => '数据库修复工具',
'subtitle' => '访问WordPress数据库修复工具',
'dependency' => [ 'enable_db_tools', '==', 'true' ],
'content' => '
<div class="wp_china_yes-notice wp_china_yes-notice-warning">
<p><strong>重要提醒</strong>:使用数据库修复工具前请务必备份数据库!</p>
<p><a class="button button-primary" href="' . esc_url( admin_url( 'maint/repair.php' ) ) . '" target="_blank">打开数据库修复工具</a></p>
<p><small>此工具将在新窗口中打开,修复完成后建议关闭此功能。</small></p>
</div>
',
],
[
'id' => 'enable_sections',
'type' => 'switcher',
'title' => '功能模块管理',
'subtitle' => '启用自定义功能选项卡',
'default' => true,
'desc' => '启用后可自定义显示的功能模块。注意:禁用功能后重新启用需要重新配置相关设置。',
],
[
'id' => 'quick_select',
'type' => 'button_set',
'title' => '快速选择',
'subtitle' => '一键选择常用配置方案',
'dependency' => ['enable_sections', '==', 'true'],
'multiple' => false,
'options' => [
'recommended' => '推荐配置',
'minimal' => '最小配置',
'full' => '完整配置',
'custom' => '自定义配置',
],
'default' => 'custom',
'desc' => '选择预设配置方案,或选择"自定义配置"进行个性化设置。',
],
[
'id' => 'enabled_sections',
'type' => 'checkbox',
'title' => '功能选项卡',
'subtitle' => '选择要显示的功能模块',
'dependency' => ['enable_sections', '==', 'true'],
'inline' => true,
'options' => [
'welcome' => '欢迎使用',
'store' => '应用市场',
'admincdn' => '萌芽加速',
'cravatar' => '初认头像',
'windfonts' => '文风字体',
'motucloud' => '墨图云集',
'fewmail' => '飞秒邮箱',
'wordyeah' => '无言会语',
'blocks' => '笔笙区块',
'deerlogin' => '灯鹿用户',
'waimao' => '跨飞外贸',
'woocn' => 'Woo电商',
'lelms' => '乐尔达思',
'wapuu' => '瓦普文创',
'adblock' => '广告拦截',
'notice' => '通知管理',
'plane' => '飞行模式',
'monitor' => '脉云维护',
'forums' => '赛博论坛',
'forms' => '重力表单',
'panel' => '天控面板',
'security' => '雨滴安全',
'domain' => '蛋叮域名',
'performance' => '性能优化',
'brand' => '品牌白标',
'sms' => '竹莺短信',
'chat' => '点洽客服',
'translate' => '文脉翻译',
'ecosystem' => '生态系统',
'deer' => '建站套件',
'docs' => '帮助文档',
'about' => '关于插件',
'other' => '其他设置'
],
'default' => ['welcome', 'store', 'admincdn', 'cravatar', 'wordyeah', 'other', 'about'],
'desc' => '选择要显示的功能模块,取消勾选的模块将在设置页面中隐藏。',
],
[
'type' => 'content',
'dependency' => ['enable_sections', '==', 'true'],
'content' => '
<script>
jQuery(document).ready(function($) {
var presets = {
recommended: ["welcome", "store", "admincdn", "cravatar", "windfonts", "performance", "other", "about"],
minimal: ["welcome", "store", "admincdn", "cravatar", "other", "about"],
full: ["welcome", "store", "admincdn", "cravatar", "windfonts", "motucloud", "fewmail", "wordyeah", "blocks", "deerlogin", "waimao", "woocn", "lelms", "wapuu", "adblock", "notice", "plane", "monitor", "forums", "forms", "panel", "security", "domain", "performance", "brand", "sms", "chat", "translate", "ecosystem", "deer", "docs", "about", "other"]
};
$("input[name=\\"wp_china_yes[quick_select]\\"]").on("change", function() {
var selectedPreset = $(this).val();
if (presets[selectedPreset]) {
var checkboxes = $("input[name=\\"wp_china_yes[enabled_sections][]\\"]");
checkboxes.prop("checked", false);
$.each(presets[selectedPreset], function(index, value) {
$("input[name=\\"wp_china_yes[enabled_sections][]\\"][value=\\"" + value + "\\"]").prop("checked", true);
});
}
});
});
</script>
',
],
],
] );
if (in_array('deer', $enabled_sections)) {
$settings_page_url = $this->get_settings_page_url();
ob_start();
include CHINA_YES_PLUGIN_PATH . 'templates/website-section.php';
$website_content = ob_get_clean();
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '建站套件',
'icon' => 'icon icon-mouse',
'fields' => [
[
'type' => 'content',
'content' =>$website_content,
]
],
] );
}
if (in_array('docs', $enabled_sections)) {
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '帮助文档',
'icon' => 'icon icon-lifebuoy',
'fields' => [
[
'id' => 'docs',
'type' => 'radio',
'title' => '帮助文档',
'inline' => true,
'options' => [
'cn' => '默认线路',
'global' => '国际线路',
'off' => '不启用'
],
'default' => 'cn',
'subtitle' => '是否启用灯鹿用户',
'desc' => tr( '<a href="https://deerlogin.com/" target="_blank">灯鹿用户DeerLogin</a>Gravatar 在中国的完美替代方案,您可以在 Cravatar.com 上传头像,更多选项请安装 WPAavatar 插件。可自选<a href="https://wpcy.com/document/gravatar-alternatives" target="_blank">加速线路</a>。',
'wp-china-yes' ),
],
],
] );
}
if (in_array('about', $enabled_sections)) {
$settings_page_url = $this->get_settings_page_url();
ob_start();
include CHINA_YES_PLUGIN_PATH . 'templates/about-section.php';
$about_content = ob_get_clean();
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '关于插件',
'icon' => 'icon icon-info-circle',
'fields' => [
[
'type' => 'content',
'content' =>$about_content,
]
],
] );
}
// 备份选项功能
WP_CHINA_YES::createSection( $this->prefix, [
'title' => '备份选项',
'icon' => 'icon icon-download',
'fields' => [
[
'type' => 'content',
'content' => '
<div class="wpcy-about__section">
<div class="wpcy-about__grid columns-1">
<div class="column wpcy-kit-banner">
<span class="wpcy-icon-inner"><i class="icon icon-info-circle"></i></span>
<h2>使用说明</h2>
<p><strong>导出设置:</strong>点击"导出"按钮将当前所有插件配置保存为JSON文件文件会自动下载到您的电脑。</p>
<p><strong>导入设置:</strong>选择之前导出的JSON备份文件点击"导入"按钮恢复所有设置。</p>
</div>
</div>
</div>
',
],
[
'type' => 'backup',
'title' => '备份与恢复操作',
'subtitle' => '导出当前设置或导入之前保存的配置文件',
'desc' => '使用上方说明进行备份和恢复操作,确保数据安全。',
]
],
] );
}
/**
* 加载后台资源
*/
public function enqueue_admin_assets( $hook_suffix ) {
if ( strpos( $hook_suffix, 'wp-china-yes' ) === false ) {
return;
}
wp_enqueue_style( 'wpcy-admin', CHINA_YES_PLUGIN_URL . 'assets/css/setting.css', [], CHINA_YES_VERSION );
}
/**
* 挂载设置页面
*/
public function admin_menu() {
// 自定义名称
add_filter( 'all_plugins', function ( $plugins ) {
if ( isset( $plugins['wp-china-yes/wp-china-yes.php'] ) ) {
$plugins['wp-china-yes/wp-china-yes.php']['Name'] = $this->settings['custom_name'];
}
return $plugins;
} );
// 插件页设置
add_filter( 'plugin_action_links', function ( $links, $file ) {
if ( 'wp-china-yes/wp-china-yes.php' !== $file ) {
return $links;
}
$settings_link = '<a href="' . add_query_arg( array( 'page' => 'wp-china-yes' ),
is_multisite() ? 'settings.php' : 'options-general.php' ) . '">' . esc_html( tr( '设置',
'wp-china-yes' ) ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}, 10, 2 );
}
/**
* 获取WordPress可用语言列表
*/
private function get_available_languages() {
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
$languages = wp_get_available_translations();
$language_options = [
'' => 'English (United States)'
];
foreach ( $languages as $locale => $language ) {
$language_options[ $locale ] = $language['native_name'];
}
return $language_options;
}
/**
* 获取当前后台语言设置
*/
private function get_current_admin_language() {
$user_locale = get_user_meta( get_current_user_id(), 'locale', true );
return $user_locale ?: get_locale();
}
/**
* 获取当前前台语言设置
*/
private function get_current_frontend_language() {
return get_option( 'WPLANG', '' );
}
}