Compare commits
90 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f431a7556d | ||
|
|
be0c09a887 | ||
|
|
6531d841bf | ||
|
|
bcb26466c3 | ||
|
|
64748fe6ff | ||
|
|
70af2db0f5 | ||
|
|
8beff870f2 | ||
|
|
bfec4c147e | ||
|
|
6083aa8057 | ||
|
|
f9a7968c00 | ||
|
|
5370b07c36 | ||
|
|
8d3a71414d | ||
|
|
7e08f33923 | ||
|
|
fdce4da05e | ||
|
|
eda5b77a48 | ||
|
|
9ea04f6ac4 | ||
|
|
33e0545965 | ||
|
|
071d022ccf | ||
|
|
8c29188c1b | ||
|
|
f2a89c42da | ||
|
|
a500ff9b6d | ||
|
|
25fdf04fcc | ||
|
|
435ffd6980 | ||
|
|
adb8efd320 | ||
|
|
7121b4b7ef | ||
|
|
789c920032 | ||
|
|
2b7c57a427 | ||
|
|
82ca5e5dc4 | ||
|
|
a87985970d | ||
|
|
b0a4bc3d42 | ||
|
|
219631bc7e | ||
|
|
cb06d1bef4 | ||
|
|
cb98197084 | ||
|
|
9c678616f2 | ||
|
|
ada09d9f8c | ||
|
|
210e2ffbce | ||
|
|
529bb10f34 | ||
|
|
2391c18bae | ||
|
|
dd912a9e31 | ||
|
|
7f1b9a5672 | ||
|
|
73f4d6eba5 | ||
|
|
a2675c4fc6 | ||
|
|
8a4d74e997 | ||
|
|
de8b6ccaa6 | ||
|
|
4a7c871c5c | ||
|
|
ce02646463 | ||
|
|
c947537af6 | ||
|
|
2c86b5c546 | ||
|
|
7d38bc7adc | ||
|
|
cd8e420e81 | ||
|
|
2223b022b7 | ||
|
|
597c0943d5 | ||
|
|
b255b86947 | ||
|
|
41c27fe487 | ||
|
|
646c032e70 | ||
|
|
e1a6083779 | ||
|
|
af8107006b | ||
|
|
d01723c737 | ||
|
|
9fa7b40a5c | ||
|
|
2d6e85e4d2 | ||
|
|
a384063b9b | ||
|
|
b187c2da3e | ||
|
|
ee63f3abae | ||
|
|
391e3db4c3 | ||
|
|
946e4debcf | ||
|
|
61528c80c3 | ||
|
|
63c2b06b7e | ||
|
|
dd5babdc31 | ||
|
|
05e3987783 | ||
|
|
fb6c65e25f | ||
|
|
516b8cf9dd | ||
|
|
dea8b71025 | ||
|
|
6fc235f454 | ||
|
|
bcf2ae35bd | ||
|
|
2c9beee820 | ||
|
|
15424b0581 | ||
|
|
a0cc8dd261 | ||
|
|
86afa929b1 | ||
|
|
421890785a | ||
|
|
f53413d8e7 | ||
|
|
a8f491ff06 | ||
|
|
a4a13bbe5f | ||
|
|
826ede7840 | ||
|
|
52835c5714 | ||
|
|
a30afa7175 | ||
|
|
efbd8c6890 | ||
|
|
55c057889d | ||
|
|
effc22c0fc | ||
|
|
4f652f38d4 | ||
|
|
e1c514819d |
101
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
name: 报告问题 (Bug Report)
|
||||
description: 创建一个报告以帮助我们改进 (Create a report to help us improve)
|
||||
title: "[Bug Report]: "
|
||||
labels: ["bug"]
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
**请仅使用 简体中文 或 英文 进行填写**
|
||||
**Please only use Simplified Chinese or English to fill in**
|
||||
- type: checkboxes
|
||||
id: checks
|
||||
attributes:
|
||||
label: 在提问之前 (Before asking)
|
||||
description: |
|
||||
提问之前,先回答几个小问题。
|
||||
Before asking questions, answer a few quick questions.
|
||||
options:
|
||||
- label: 我已经搜索了现有的 Issues 和 Discussions (I've searched the existing Issues and Discussions)
|
||||
required: true
|
||||
- label: 我已经阅读了 README 中除版本记录以外的所有内容 (I've read everything in the README except the version notes)
|
||||
required: true
|
||||
- label: 我在提问题之前至少花费了 5 分钟来思考和准备 (I spend at least 5 minutes thinking and preparing before asking a question)
|
||||
required: true
|
||||
- label: 这个问题出现在最新版的 WP-China-Yes 上 (This question appears on the latest version of WP-China-Yes)
|
||||
required: false
|
||||
- label: 我使用过旧版的 WP-China-Yes 并且没有出现这个问题 (I've used an older version of WP-China-Yes and didn't have this problem)
|
||||
required: false
|
||||
- label: 这个问题出现了至少 3 次 (This question has occurred at least 3 times)
|
||||
required: false
|
||||
- type: textarea
|
||||
id: describe
|
||||
attributes:
|
||||
label: 描述问题 (Describe the problem)
|
||||
description: |
|
||||
简明概要地描述你遇到的问题。
|
||||
Briefly describe the problem you are having.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: 预期行为 (Expected behavior)
|
||||
description: |
|
||||
简明概要地描述你期望发生的事情。
|
||||
Briefly describe what you expect to happen.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduce
|
||||
attributes:
|
||||
label: 如何复现 (How to reproduce)
|
||||
description: |
|
||||
重现该问题的详细步骤。
|
||||
Detailed steps to reproduce the problem.
|
||||
value: |
|
||||
1. 安装 WP-China-Yes
|
||||
2. 设置 '...'
|
||||
3. 点击 '...'
|
||||
4. 出现问题
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: 相关日志 (Related logs)
|
||||
description: |
|
||||
请复制并粘贴任何相关的日志输出。
|
||||
Please copy and paste any relevant log output.
|
||||
可以把文件拖入这个区域以添加日志文件。
|
||||
Files can be dragged into this area to add log files.
|
||||
日志文件可通过开启 WordPress 的调试模式获取。
|
||||
Log files can be accessed by enabling WordPress debug mode.
|
||||
render: Text
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: 截图 (Screenshots)
|
||||
description: |
|
||||
如果有,添加屏幕截图可帮助更快定位你的问题。
|
||||
If so, adding screenshots can help locate your issue faster.
|
||||
可以复制图片后在此区域内粘贴以添加图片。
|
||||
Pictures can be copied and pasted in this area to add pictures.
|
||||
如有必要,使用马赛克遮盖敏感信息。
|
||||
Use a mosaic to obscure sensitive information if necessary.
|
||||
validations:
|
||||
required: false
|
||||
- type: textarea
|
||||
id: others
|
||||
attributes:
|
||||
label: 还有别的吗 (Anything else)
|
||||
description: |
|
||||
运行环境?浏览器?WordPress 版本?相关的配置?链接?参考资料?
|
||||
Environment? Browser? WordPress version? Related configuration? Link? References?
|
||||
任何能让我们对你所遇到的问题有更多了解的东西。
|
||||
Anything that can give us more insight into the problem you're having.
|
||||
validations:
|
||||
required: false
|
||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 讨论、问答和非项目问题 (Discussions, questions, and non-project issues)
|
||||
url: https://jq.qq.com/?_wv=1027&k=I1oJKSTH
|
||||
about: 其他不明之处,请移步我们的QQ群 12370907 (For other unclear things, please move to our qq group 12370907)
|
||||
55
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
name: 功能请求 (Feature request)
|
||||
description: 为这个项目提出一个想法 (Suggest an idea for this project)
|
||||
title: "[Feature Request]: "
|
||||
labels: ["enhancement"]
|
||||
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
**请仅使用 简体中文 或 英文 进行填写**
|
||||
**Please only use Simplified Chinese or English to fill in**
|
||||
- type: checkboxes
|
||||
attributes:
|
||||
label: 在提问之前 (Before asking)
|
||||
description: |
|
||||
提问之前,先回答几个小问题。
|
||||
Before asking questions, answer a few quick questions.
|
||||
options:
|
||||
- label: 我已经搜索了全部 Issues 和 Commits (I have searched all Issues and Commits)
|
||||
required: true
|
||||
- label: 它们当中没有我将要提交的新功能 (None of them have new feature that I'm going to submit)
|
||||
required: true
|
||||
- type: textarea
|
||||
id: feature
|
||||
attributes:
|
||||
label: 描述功能 (Describe feature)
|
||||
description: |
|
||||
简明概要地描述你的新功能,以及它将解决什么问题。
|
||||
Briefly describe your new feature and what problem it will solve.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: workflow
|
||||
attributes:
|
||||
label: 工作流程 (Workflow)
|
||||
description: |
|
||||
请向我们提供有关该功能的实现流程。
|
||||
Please provide us with the implementation flow for this feature.
|
||||
value: |
|
||||
1. 新建文件 ....
|
||||
2. 添加函数 ....
|
||||
3. ...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: others
|
||||
attributes:
|
||||
label: 还有别的吗 (Anything else)
|
||||
description: |
|
||||
运行环境?浏览器?WordPress 版本?相关的配置?链接?参考资料?
|
||||
Environment? Browser? WordPress version? Related configuration? Link? References?
|
||||
任何能让我们对该功能的实现有更多帮助的东西。
|
||||
Anything that can help us more with the implementation of this feature.
|
||||
validations:
|
||||
required: false
|
||||
31
.github/workflows/update-changelog.yml
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
name: "Update Changelog"
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [released]
|
||||
|
||||
jobs:
|
||||
update:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
|
||||
- name: Update Changelog
|
||||
uses: stefanzweifel/changelog-updater-action@v1
|
||||
with:
|
||||
latest-version: ${{ github.event.release.tag_name }}
|
||||
release-notes: ${{ github.event.release.body }}
|
||||
|
||||
- name: Commit updated CHANGELOG
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
branch: master
|
||||
commit_message: "docs: Update CHANGELOG"
|
||||
file_pattern: CHANGELOG.md
|
||||
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.idea
|
||||
vendor
|
||||
68
CHANGELOG.md
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to `WP-China-Yes` will be documented in this file.
|
||||
|
||||
## v3.8 - 2025-02-05
|
||||
|
||||
* 文派叶子 v3.8 重大更新!全新UI 设计更接近 WordPress 原生体验。
|
||||
|
||||
1. 替换业务域名 WP-China-Yes.com 为新域名 WPCY.COM ;
|
||||
2. 修复 adminCDN 支持 jsDelivr 加速无效等问题;
|
||||
3. 新增 Bootstrap CDN 转接至 adminCDN 加速支持;
|
||||
4. 新增 Windfonts 中文排版优化:支持段首空格 2em;
|
||||
5. 新增 Windfonts 中文排版优化:支持文本内容对齐;
|
||||
6. 新增 [脉云维护] 菜单并支持WP系统状态监控,可在页脚位置显示内存、CPU用量等信息;
|
||||
7. 新增 [欢迎使用] 用户引导页面,更清晰的功能指导和简介。
|
||||
8. 新增 [建站工具] 文派·寻鹿建站套件展示页面,内容待完善。
|
||||
9. 优化 [萌芽加速] 设置,与 WordPress 程序端加速选项分离便于添加后续项目;
|
||||
10. 优化 [关于插件] 页面更简约的赞助商 Logo 和贡献者名单展示。
|
||||
11. 补充 changelog.txt 文本文件,跟随插件副本分发。
|
||||
12. 补充 copyright.txt 版权文件,跟随插件副本分发。
|
||||
|
||||
## v3.7.1 - 2024-11-19
|
||||
|
||||
1. 性能优化
|
||||
2. 修复监控无法关闭的问题
|
||||
|
||||
**Full Changelog**: https://github.com/WenPai-org/wp-china-yes/compare/v3.6.5...v3.7.1
|
||||
|
||||
## v3.6.5 - 2024-08-23
|
||||
|
||||
1. 优化 CLI 判断
|
||||
2. 回退替换钩子修改
|
||||
|
||||
**Full Changelog**: https://github.com/WenPai-org/wp-china-yes/compare/v3.6.4...v3.6.5
|
||||
|
||||
## v3.6.4 - 2024-08-23
|
||||
|
||||
1. WP-CLI 下不运行 adminCDN 部分,防止影响缓冲区。
|
||||
2. 部分文案调整支持多语言。
|
||||
|
||||
**Full Changelog**: https://github.com/WenPai-org/wp-china-yes/compare/v3.6.3...v3.6.4
|
||||
|
||||
## v3.6.3 - 2024-08-23
|
||||
|
||||
1. 为自动监控功能添加开关
|
||||
2. adminCDN 支持 jsDelivr 加速
|
||||
3. Windfonts 支持优化模式开关
|
||||
|
||||
**adminCDN 的 jsd 加速默认屏蔽 gh 端点,如有主题插件作者需要使用请联系加白。**
|
||||
**Full Changelog**: https://github.com/WenPai-org/wp-china-yes/compare/v3.6.2...v3.6.3
|
||||
|
||||
## v3.6.2 - 2024-03-09
|
||||
|
||||
1. UI 重构
|
||||
2. 修复市场加速导致 Beta 测试插件失效的问题
|
||||
3. 更新接口及测试 URL
|
||||
|
||||
**Full Changelog**: https://github.com/WenPai-org/wp-china-yes/compare/v3.6.1...v3.6.2
|
||||
|
||||
## v3.6.1 - 2024-03-08
|
||||
|
||||
1. 重构全部代码
|
||||
2. 应用市场调整为[文派开源](https://wenpai.org)
|
||||
3. 加速服务调整为[萌芽加速](https://admincdn.com)
|
||||
4. 头像调整为[初认头像](https://cravatar.com)
|
||||
5. 支持自动检测节点可用性
|
||||
|
||||
**Full Changelog**: https://github.com/WenPai-org/wp-china-yes/compare/V3.5.5...v3.6.1
|
||||
122
Plugin.php
Executable file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WenPai\ChinaYes\Service\Base;
|
||||
|
||||
class Plugin {
|
||||
|
||||
/**
|
||||
* 创建插件实例
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', [ $this, 'load_textdomain' ] );
|
||||
add_action( 'plugins_loaded', [ $this, 'init_services' ] );
|
||||
|
||||
if ( is_admin() ) {
|
||||
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] );
|
||||
}
|
||||
}
|
||||
|
||||
public function init_services() {
|
||||
try {
|
||||
new Base();
|
||||
} catch ( \Exception $e ) {
|
||||
error_log( 'WP-China-Yes: Failed to initialize Base service: ' . $e->getMessage() );
|
||||
add_action( 'admin_notices', function() use ( $e ) {
|
||||
echo '<div class="notice notice-error"><p>WP-China-Yes initialization error: ' . esc_html( $e->getMessage() ) . '</p></div>';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件激活时执行
|
||||
*/
|
||||
public static function activate() {
|
||||
// 兼容性检测
|
||||
self::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件删除时执行
|
||||
*/
|
||||
public static function uninstall() {
|
||||
// 清除设置
|
||||
is_multisite() ? delete_site_option( 'wp_china_yes' ) : delete_option( 'wp_china_yes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载翻译文件
|
||||
*/
|
||||
public function load_textdomain() {
|
||||
load_plugin_textdomain( 'wp-china-yes', false, dirname( plugin_basename( CHINA_YES_PLUGIN_FILE ) ) . '/languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件加载时执行
|
||||
*/
|
||||
public function plugins_loaded() {
|
||||
add_action( 'admin_notices', [ $this, 'admin_notices' ] );
|
||||
/**
|
||||
* 插件列表页中所有插件增加「参与翻译」链接
|
||||
*/
|
||||
add_filter( sprintf( '%splugin_action_links', is_multisite() ? 'network_admin_' : '' ), function ( $links, $plugin = '' ) {
|
||||
$links[] = '<a target="_blank" href="https://translate.wenpai.org/projects/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">参与翻译</a>';
|
||||
$links[] = '<a target="_blank" href="https://wpcy.com/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">去广告</a>';
|
||||
|
||||
return $links;
|
||||
}, 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件兼容性检测函数
|
||||
*/
|
||||
public static function check() {
|
||||
$notices = [];
|
||||
if ( version_compare( PHP_VERSION, '7.0.0', '<' ) ) {
|
||||
deactivate_plugins( 'wp-china-yes/wp-china-yes.php' );
|
||||
$notices[] = '<div class="notice notice-error"><p>' . sprintf( 'WP-China-Yes 插件需要 PHP 7.0.0 或更高版本,当前版本为 %s,插件已自动禁用。',
|
||||
PHP_VERSION ) . '</p></div>';
|
||||
}
|
||||
if ( is_plugin_active( 'wp-china-no/wp-china-no.php' ) ) {
|
||||
deactivate_plugins( 'wp-china-no/wp-china-no.php' );
|
||||
$notices[] = '<div class="notice notice-error is-dismissible">
|
||||
<p><strong>检测到旧版插件 WP-China-No,已自动禁用!</strong></p>
|
||||
</div>';
|
||||
}
|
||||
if ( is_plugin_active( 'wp-china-plus/wp-china-plus.php' ) ) {
|
||||
deactivate_plugins( 'wp-china-plus/wp-china-plus.php' );
|
||||
$notices[] = '<div class="notice notice-error is-dismissible">
|
||||
<p><strong>检测到不兼容的插件 WP-China-Plus,已自动禁用!</strong></p>
|
||||
</div>';
|
||||
}
|
||||
if ( is_plugin_active( 'kill-429/kill-429.php' ) ) {
|
||||
deactivate_plugins( 'kill-429/kill-429.php' );
|
||||
$notices[] = '<div class="notice notice-error is-dismissible">
|
||||
<p><strong>检测到不兼容的插件 Kill 429,已自动禁用!</strong></p>
|
||||
</div>';
|
||||
}
|
||||
if ( defined( 'WP_PROXY_HOST' ) || defined( 'WP_PROXY_PORT' ) ) {
|
||||
$notices[] = '<div class="notice notice-warning is-dismissible">
|
||||
<p><strong>检测到已在 WordPress 配置文件中设置代理服务器,这可能会导致插件无法正常工作!</strong></p>
|
||||
</div>';
|
||||
}
|
||||
|
||||
set_transient( 'wp-china-yes-admin-notices', $notices, 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出管理后台提示信息
|
||||
*/
|
||||
public function admin_notices() {
|
||||
$notices = get_transient( 'wp-china-yes-admin-notices' );
|
||||
if ( $notices ) {
|
||||
foreach ( $notices as $notice ) {
|
||||
echo $notice;
|
||||
}
|
||||
delete_transient( 'wp-china-yes-admin-notices' );
|
||||
}
|
||||
}
|
||||
}
|
||||
169
Service/123-Maintenance.php
Executable file
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class Maintenance {
|
||||
private $settings;
|
||||
private $allowed_pages = [
|
||||
'wp-login.php',
|
||||
'wp-register.php',
|
||||
'wp-cron.php',
|
||||
'async-upload.php',
|
||||
'admin-ajax.php'
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
// 使用更早的钩子并设置高优先级
|
||||
add_action('plugins_loaded', [$this, 'init'], 1);
|
||||
}
|
||||
|
||||
public function init() {
|
||||
$this->settings = get_settings();
|
||||
|
||||
// 仅在调试模式下输出调试信息
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
error_log('Maintenance Settings Raw: ' . print_r($this->settings, true));
|
||||
error_log('Maintenance Mode Value: ' . var_export($this->settings['maintenance_mode'], true));
|
||||
}
|
||||
|
||||
// 如果维护模式启用,挂载相关钩子
|
||||
if ($this->settings['maintenance_mode']) {
|
||||
add_action('template_redirect', [$this, 'check_maintenance_mode'], 1);
|
||||
add_action('admin_bar_menu', [$this, 'add_admin_bar_notice'], 100);
|
||||
add_action('init', [$this, 'check_ajax_maintenance'], 1);
|
||||
}
|
||||
}
|
||||
|
||||
public function check_ajax_maintenance() {
|
||||
if (wp_doing_ajax() && !current_user_can('manage_options')) {
|
||||
wp_die('维护模式已启用');
|
||||
}
|
||||
}
|
||||
|
||||
public function check_maintenance_mode() {
|
||||
// 如果是命令行环境,直接返回
|
||||
if (php_sapi_name() === 'cli') {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果是管理员,直接返回
|
||||
if (current_user_can('manage_options')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否是允许的页面
|
||||
global $pagenow;
|
||||
if (in_array($pagenow, $this->allowed_pages)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否是后台请求
|
||||
if (is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否是 REST API 请求
|
||||
if (defined('REST_REQUEST') && REST_REQUEST) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否是 AJAX 请求
|
||||
if (wp_doing_ajax()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示维护页面
|
||||
$this->show_maintenance_page();
|
||||
}
|
||||
|
||||
private function show_maintenance_page() {
|
||||
$maintenance_settings = $this->settings['maintenance_settings'] ?? [];
|
||||
|
||||
$title = $maintenance_settings['maintenance_title'] ?? '网站维护中';
|
||||
$heading = $maintenance_settings['maintenance_heading'] ?? '网站维护中';
|
||||
$message = $maintenance_settings['maintenance_message'] ?? '网站正在进行例行维护,请稍后访问。感谢您的理解与支持!';
|
||||
|
||||
// 添加基本的样式
|
||||
$style = '
|
||||
<style>
|
||||
body {
|
||||
background: #f1f1f1;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
}
|
||||
.maintenance-wrapper {
|
||||
text-align: center;
|
||||
padding: 50px 20px;
|
||||
max-width: 800px;
|
||||
margin: 100px auto;
|
||||
background: white;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
}
|
||||
.maintenance-wrapper h1 {
|
||||
color: #333;
|
||||
font-size: 36px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.maintenance-wrapper h2 {
|
||||
color: #666;
|
||||
font-size: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.maintenance-message {
|
||||
color: #555;
|
||||
line-height: 1.6;
|
||||
font-size: 16px;
|
||||
}
|
||||
</style>
|
||||
';
|
||||
|
||||
$output = $style . sprintf(
|
||||
'<div class="maintenance-wrapper">
|
||||
<h1>%s</h1>
|
||||
<h2>%s</h2>
|
||||
<div class="maintenance-message">%s</div>
|
||||
</div>',
|
||||
esc_html($heading),
|
||||
esc_html($title),
|
||||
wp_kses_post($message)
|
||||
);
|
||||
|
||||
// 设置维护模式响应头
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||
header('Status: 503 Service Temporarily Unavailable');
|
||||
header('Retry-After: 3600');
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
}
|
||||
|
||||
// 确保输出被清空
|
||||
if (ob_get_level()) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
wp_die($output, $title, [
|
||||
'response' => 503,
|
||||
'back_link' => false
|
||||
]);
|
||||
}
|
||||
|
||||
public function add_admin_bar_notice($wp_admin_bar) {
|
||||
if (!current_user_can('manage_options')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 添加调试信息
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
error_log('Admin bar notice added for maintenance mode.');
|
||||
}
|
||||
|
||||
$wp_admin_bar->add_node([
|
||||
'id' => 'maintenance-mode-notice',
|
||||
'title' => '<span style="color: #ff0000;">维护模式已启用</span>',
|
||||
'href' => admin_url('admin.php?page=wp-china-yes#tab=脉云维护')
|
||||
]);
|
||||
}
|
||||
}
|
||||
554
Service/Acceleration.php
Executable file
|
|
@ -0,0 +1,554 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class Acceleration {
|
||||
private $settings;
|
||||
private $replacements = [];
|
||||
private $regex_patterns = [];
|
||||
private $compiled_patterns = [];
|
||||
private $buffer_started = false;
|
||||
private static $cache = [];
|
||||
private $performance_data = [];
|
||||
private $debug_mode = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
$this->debug_mode = defined('WP_DEBUG') && WP_DEBUG;
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 admincdn 功能
|
||||
*/
|
||||
private function init() {
|
||||
if (!$this->should_enable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('wp_head', function () {
|
||||
echo "<!-- 此站点使用的前端静态资源库由萌芽加速(adminCDN)提供,智能加速转接基于文派叶子 WPCY.COM -->\n";
|
||||
}, 1);
|
||||
|
||||
$this->prepare_replacements();
|
||||
$this->start_output_buffer();
|
||||
$this->init_version_control();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否应该启用加速功能
|
||||
*/
|
||||
private function should_enable() {
|
||||
return !empty($this->settings['admincdn']) ||
|
||||
!empty($this->settings['admincdn_files']) ||
|
||||
!empty($this->settings['admincdn_public']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备所有替换规则
|
||||
*/
|
||||
private function prepare_replacements() {
|
||||
if ($this->has_admin_acceleration()) {
|
||||
$this->prepare_admin_replacements();
|
||||
}
|
||||
|
||||
if ($this->has_frontend_acceleration()) {
|
||||
$this->prepare_frontend_replacements();
|
||||
}
|
||||
|
||||
if ($this->has_public_library_acceleration()) {
|
||||
$this->prepare_public_library_replacements();
|
||||
}
|
||||
|
||||
if ($this->has_dev_library_acceleration()) {
|
||||
$this->prepare_dev_library_replacements();
|
||||
}
|
||||
|
||||
if ($this->has_special_features()) {
|
||||
$this->prepare_special_replacements();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否启用管理后台加速
|
||||
*/
|
||||
private function has_admin_acceleration() {
|
||||
return !empty($this->settings['admincdn']) &&
|
||||
in_array('admin', (array) $this->settings['admincdn']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否启用前台加速
|
||||
*/
|
||||
private function has_frontend_acceleration() {
|
||||
return !empty($this->settings['admincdn_files']) &&
|
||||
in_array('frontend', (array) $this->settings['admincdn_files']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否启用公共库加速
|
||||
*/
|
||||
private function has_public_library_acceleration() {
|
||||
return !empty($this->settings['admincdn_public']) &&
|
||||
is_array($this->settings['admincdn_public']) &&
|
||||
count($this->settings['admincdn_public']) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否启用开发库加速
|
||||
*/
|
||||
private function has_dev_library_acceleration() {
|
||||
return !empty($this->settings['admincdn_dev']) &&
|
||||
is_array($this->settings['admincdn_dev']) &&
|
||||
count($this->settings['admincdn_dev']) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否启用特殊功能
|
||||
*/
|
||||
private function has_special_features() {
|
||||
return !empty($this->settings['admincdn_files']) &&
|
||||
(in_array('emoji', (array) $this->settings['admincdn_files']) ||
|
||||
in_array('sworg', (array) $this->settings['admincdn_files']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动统一的输出缓冲
|
||||
*/
|
||||
private function start_output_buffer() {
|
||||
if ($this->buffer_started || php_sapi_name() == 'cli') {
|
||||
return;
|
||||
}
|
||||
|
||||
$hook = is_admin() ? 'admin_init' : 'template_redirect';
|
||||
|
||||
add_action($hook, function () {
|
||||
if (!$this->buffer_started) {
|
||||
ob_start([$this, 'process_buffer']);
|
||||
$this->buffer_started = true;
|
||||
}
|
||||
}, 1);
|
||||
|
||||
add_action('wp_footer', [$this, 'end_buffer'], 999);
|
||||
add_action('admin_footer', [$this, 'end_buffer'], 999);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理输出缓冲内容
|
||||
*/
|
||||
public function process_buffer($buffer) {
|
||||
if (empty($buffer)) {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
$start_time = microtime(true);
|
||||
$buffer_size = strlen($buffer);
|
||||
$buffer_hash = md5($buffer);
|
||||
|
||||
if (isset(self::$cache[$buffer_hash])) {
|
||||
$this->log_performance('cache_hit', microtime(true) - $start_time, $buffer_size);
|
||||
return self::$cache[$buffer_hash];
|
||||
}
|
||||
|
||||
$original_buffer = $buffer;
|
||||
$replacements_made = 0;
|
||||
|
||||
if (!empty($this->regex_patterns)) {
|
||||
$regex_start = microtime(true);
|
||||
$this->compile_patterns();
|
||||
|
||||
foreach ($this->compiled_patterns as $pattern_data) {
|
||||
$before = $buffer;
|
||||
$buffer = preg_replace($pattern_data['pattern'], $pattern_data['replacement'], $buffer);
|
||||
|
||||
if (preg_last_error() !== PREG_NO_ERROR) {
|
||||
$this->log_error('Regex error in pattern: ' . $pattern_data['pattern']);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($before !== $buffer) {
|
||||
$replacements_made++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->log_performance('regex_processing', microtime(true) - $regex_start, count($this->compiled_patterns));
|
||||
}
|
||||
|
||||
if (!empty($this->replacements)) {
|
||||
$str_start = microtime(true);
|
||||
$searches = array_keys($this->replacements);
|
||||
$replaces = array_values($this->replacements);
|
||||
$before = $buffer;
|
||||
$buffer = str_replace($searches, $replaces, $buffer);
|
||||
|
||||
if ($before !== $buffer) {
|
||||
$replacements_made++;
|
||||
}
|
||||
|
||||
$this->log_performance('string_processing', microtime(true) - $str_start, count($this->replacements));
|
||||
}
|
||||
|
||||
if (count(self::$cache) < 100) {
|
||||
self::$cache[$buffer_hash] = $buffer;
|
||||
}
|
||||
|
||||
$total_time = microtime(true) - $start_time;
|
||||
$this->log_performance('total_processing', $total_time, $replacements_made);
|
||||
|
||||
if ($this->debug_mode && $replacements_made > 0) {
|
||||
$buffer .= sprintf(
|
||||
'<!-- Acceleration: %d replacements in %.4fs, buffer size: %s -->',
|
||||
$replacements_made,
|
||||
$total_time,
|
||||
$this->format_bytes($buffer_size)
|
||||
);
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录性能数据
|
||||
*/
|
||||
private function log_performance($operation, $time, $count) {
|
||||
if (!$this->debug_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->performance_data[] = [
|
||||
'operation' => $operation,
|
||||
'time' => $time,
|
||||
'count' => $count,
|
||||
'timestamp' => microtime(true)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录错误信息
|
||||
*/
|
||||
private function log_error($message) {
|
||||
if ($this->debug_mode) {
|
||||
error_log('Acceleration: ' . $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化字节数
|
||||
*/
|
||||
private function format_bytes($bytes) {
|
||||
$units = ['B', 'KB', 'MB', 'GB'];
|
||||
$bytes = max($bytes, 0);
|
||||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||
$pow = min($pow, count($units) - 1);
|
||||
$bytes /= pow(1024, $pow);
|
||||
return round($bytes, 2) . ' ' . $units[$pow];
|
||||
}
|
||||
|
||||
/**
|
||||
* 编译正则表达式模式
|
||||
*/
|
||||
private function compile_patterns() {
|
||||
if (!empty($this->compiled_patterns)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->regex_patterns as $pattern => $replacement) {
|
||||
if (!$this->is_valid_regex($pattern)) {
|
||||
error_log('Acceleration: Invalid regex pattern: ' . $pattern);
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->compiled_patterns[] = [
|
||||
'pattern' => $pattern,
|
||||
'replacement' => $replacement
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证正则表达式是否有效
|
||||
*/
|
||||
private function is_valid_regex($pattern) {
|
||||
return @preg_match($pattern, '') !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束输出缓冲
|
||||
*/
|
||||
public function end_buffer() {
|
||||
if ($this->buffer_started && ob_get_level()) {
|
||||
ob_end_flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备管理后台替换规则
|
||||
*/
|
||||
private function prepare_admin_replacements() {
|
||||
if (!is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array('admin', (array) $this->settings['admincdn']) &&
|
||||
!stristr($GLOBALS['wp_version'], 'alpha') &&
|
||||
!stristr($GLOBALS['wp_version'], 'beta') &&
|
||||
!stristr($GLOBALS['wp_version'], 'RC')) {
|
||||
|
||||
global $concatenate_scripts;
|
||||
$concatenate_scripts = false;
|
||||
|
||||
$pattern = '~' . preg_quote(home_url('/'), '~') . '(wp-admin|wp-includes)/(css|js)/~';
|
||||
$replacement = sprintf('https://wpstatic.admincdn.com/%s/$1/$2/', $GLOBALS['wp_version']);
|
||||
$this->regex_patterns[$pattern] = $replacement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备前台替换规则
|
||||
*/
|
||||
private function prepare_frontend_replacements() {
|
||||
if (in_array('frontend', (array) $this->settings['admincdn_files'])) {
|
||||
$pattern = '#(?<=[(\"\'])(?:' . quotemeta(home_url()) . ')?/(?:((?:wp-content|wp-includes)[^\"\')]+\.(css|js)[^\"\')]+))(?=[\"\')])#';
|
||||
$this->regex_patterns[$pattern] = 'https://public.admincdn.com/$0';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备公共库替换规则
|
||||
*/
|
||||
private function prepare_public_library_replacements() {
|
||||
$public_libraries = [
|
||||
'googlefonts' => ['fonts.googleapis.com', 'googlefonts.admincdn.com'],
|
||||
'googleajax' => ['ajax.googleapis.com', 'googleajax.admincdn.com'],
|
||||
'cdnjs' => ['cdnjs.cloudflare.com/ajax/libs', 'cdnjs.admincdn.com'],
|
||||
'jsdelivr' => ['cdn.jsdelivr.net', 'jsd.admincdn.com'],
|
||||
'bootstrapcdn' => ['maxcdn.bootstrapcdn.com', 'jsd.admincdn.com'],
|
||||
];
|
||||
|
||||
foreach ($public_libraries as $key => $replacement) {
|
||||
if (in_array($key, (array) $this->settings['admincdn_public'])) {
|
||||
$this->replacements[$replacement[0]] = $replacement[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备开发库替换规则
|
||||
*/
|
||||
private function prepare_dev_library_replacements() {
|
||||
$dev_libraries = [
|
||||
'react' => ['unpkg.com/react', 'jsd.admincdn.com/npm/react'],
|
||||
'jquery' => ['code.jquery.com', 'jsd.admincdn.com/npm/jquery'],
|
||||
'vuejs' => ['unpkg.com/vue', 'jsd.admincdn.com/npm/vue'],
|
||||
'datatables' => ['cdn.datatables.net', 'jsd.admincdn.com/npm/datatables.net'],
|
||||
'tailwindcss' => ['unpkg.com/tailwindcss', 'jsd.admincdn.com/npm/tailwindcss'],
|
||||
];
|
||||
|
||||
foreach ($dev_libraries as $key => $replacement) {
|
||||
if (in_array($key, (array) $this->settings['admincdn_dev'])) {
|
||||
$this->replacements[$replacement[0]] = $replacement[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备特殊功能替换规则
|
||||
*/
|
||||
private function prepare_special_replacements() {
|
||||
if (in_array('emoji', (array) $this->settings['admincdn_files'])) {
|
||||
$this->prepare_emoji_replacements();
|
||||
}
|
||||
|
||||
if (in_array('sworg', (array) $this->settings['admincdn_files'])) {
|
||||
$this->prepare_sworg_replacements();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备Emoji替换规则
|
||||
*/
|
||||
private function prepare_emoji_replacements() {
|
||||
remove_action('wp_head', 'print_emoji_detection_script', 7);
|
||||
remove_action('admin_print_scripts', 'print_emoji_detection_script');
|
||||
remove_action('wp_print_styles', 'print_emoji_styles');
|
||||
remove_action('admin_print_styles', 'print_emoji_styles');
|
||||
remove_filter('the_content_feed', 'wp_staticize_emoji');
|
||||
remove_filter('comment_text_rss', 'wp_staticize_emoji');
|
||||
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
|
||||
|
||||
$this->replacements['s.w.org/images/core/emoji'] = 'jsd.admincdn.com/npm/@twemoji/api/dist';
|
||||
|
||||
add_action('wp_head', function () {
|
||||
?>
|
||||
<script>
|
||||
window._wpemojiSettings = {
|
||||
"baseUrl": "https://jsd.admincdn.com/npm/@twemoji/api@15.0.3/dist/72x72/",
|
||||
"ext": ".png",
|
||||
"svgUrl": "https://jsd.admincdn.com/npm/@twemoji/api@15.0.3/dist/svg/",
|
||||
"svgExt": ".svg",
|
||||
"source": {
|
||||
"concatemoji": "<?php echo includes_url('js/wp-emoji-release.min.js'); ?>"
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<?php
|
||||
}, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备WordPress.org资源替换规则
|
||||
*/
|
||||
private function prepare_sworg_replacements() {
|
||||
$this->replacements['ts.w.org'] = 'ts.wenpai.net';
|
||||
|
||||
add_filter('theme_screenshot_url', function ($url) {
|
||||
return str_replace('ts.w.org', 'ts.wenpai.net', $url);
|
||||
});
|
||||
|
||||
add_filter('themes_api_result', function ($res, $action, $args) {
|
||||
if (is_object($res) && !empty($res->screenshots)) {
|
||||
foreach ($res->screenshots as &$screenshot) {
|
||||
if (isset($screenshot->src)) {
|
||||
$screenshot->src = str_replace('ts.w.org', 'ts.wenpai.net', $screenshot->src);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}, 10, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载 admincdn 功能(保持向后兼容)
|
||||
*/
|
||||
private function load_admincdn() {
|
||||
$this->settings['admincdn_files'] = $this->settings['admincdn_files'] ?? [];
|
||||
$this->settings['admincdn_public'] = $this->settings['admincdn_public'] ?? [];
|
||||
$this->settings['admincdn_dev'] = $this->settings['admincdn_dev'] ?? [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 初始化版本控制功能
|
||||
*/
|
||||
private function init_version_control() {
|
||||
if (empty($this->settings['admincdn_version_enable'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$version_settings = (array) $this->settings['admincdn_version'];
|
||||
|
||||
if (empty($version_settings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array('css', $version_settings)) {
|
||||
add_filter('style_loader_src', [$this, 'version_filter']);
|
||||
}
|
||||
|
||||
if (in_array('js', $version_settings)) {
|
||||
add_filter('script_loader_src', [$this, 'version_filter']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本控制过滤器
|
||||
*/
|
||||
public function version_filter($src) {
|
||||
$version_settings = (array) $this->settings['admincdn_version'];
|
||||
|
||||
$url_parts = wp_parse_url($src);
|
||||
|
||||
if (!isset($url_parts['path'])) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
$extension = pathinfo($url_parts['path'], PATHINFO_EXTENSION);
|
||||
if (!$extension || !in_array($extension, ['css', 'js'])) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
if (!in_array($extension, $version_settings)) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
if (defined('AUTOVER_DISABLE_' . strtoupper($extension))) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
$file_path = rtrim(ABSPATH, '/') . urldecode($url_parts['path']);
|
||||
if (!is_file($file_path)) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
$timestamp_version = filemtime($file_path) ?: filemtime(utf8_decode($file_path));
|
||||
if (!$timestamp_version) {
|
||||
return $src;
|
||||
}
|
||||
|
||||
if (!isset($url_parts['query'])) {
|
||||
$url_parts['query'] = '';
|
||||
}
|
||||
|
||||
$query = [];
|
||||
parse_str($url_parts['query'], $query);
|
||||
|
||||
if (in_array('disable_query', $version_settings)) {
|
||||
unset($query['v']);
|
||||
unset($query['ver']);
|
||||
unset($query['version']);
|
||||
} else {
|
||||
unset($query['v']);
|
||||
unset($query['ver']);
|
||||
|
||||
if (in_array('timestamp', $version_settings)) {
|
||||
$query['ver'] = $timestamp_version;
|
||||
} else {
|
||||
$query['ver'] = md5($timestamp_version);
|
||||
}
|
||||
}
|
||||
|
||||
$url_parts['query'] = http_build_query($query);
|
||||
|
||||
return $this->build_url($url_parts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建URL
|
||||
*/
|
||||
private function build_url(array $parts) {
|
||||
return (isset($parts['scheme']) ? "{$parts['scheme']}:" : '') .
|
||||
((isset($parts['user']) || isset($parts['host'])) ? '//' : '') .
|
||||
(isset($parts['user']) ? "{$parts['user']}" : '') .
|
||||
(isset($parts['pass']) ? ":{$parts['pass']}" : '') .
|
||||
(isset($parts['user']) ? '@' : '') .
|
||||
(isset($parts['host']) ? "{$parts['host']}" : '') .
|
||||
(isset($parts['port']) ? ":{$parts['port']}" : '') .
|
||||
(isset($parts['path']) ? "{$parts['path']}" : '') .
|
||||
(isset($parts['query']) ? "?{$parts['query']}" : '') .
|
||||
(isset($parts['fragment']) ? "#{$parts['fragment']}" : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面字符串替换
|
||||
*
|
||||
* @param string $hook 钩子名称
|
||||
* @param string $replace_func 替换函数
|
||||
* @param array $param 替换参数
|
||||
*/
|
||||
private function page_str_replace($hook, $replace_func, $param) {
|
||||
if (php_sapi_name() == 'cli') {
|
||||
return;
|
||||
}
|
||||
add_action($hook, function () use ($replace_func, $param) {
|
||||
ob_start(function ($buffer) use ($replace_func, $param) {
|
||||
$param[] = $buffer;
|
||||
return call_user_func_array($replace_func, $param);
|
||||
});
|
||||
}, PHP_INT_MAX);
|
||||
}
|
||||
}
|
||||
46
Service/Adblock.php
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Adblock
|
||||
* 广告拦截服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Adblock {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化广告拦截功能
|
||||
*/
|
||||
private function init() {
|
||||
if (!empty($this->settings['adblock']) && $this->settings['adblock'] == 'on') {
|
||||
add_action('admin_head', [$this, 'load_adblock']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载广告拦截
|
||||
*/
|
||||
public function load_adblock() {
|
||||
// 处理广告拦截规则
|
||||
foreach ((array) $this->settings['adblock_rule'] as $rule) {
|
||||
if (empty($rule['enable']) || empty($rule['selector'])) {
|
||||
continue;
|
||||
}
|
||||
echo sprintf('<style>%s{display:none!important;}</style>',
|
||||
htmlspecialchars_decode($rule['selector'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Service/Avatar.php
Executable file
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Avatar
|
||||
* 初认头像服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Avatar {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化初认头像功能
|
||||
*/
|
||||
private function init() {
|
||||
if (!empty($this->settings['cravatar']) && $this->settings['cravatar'] !== 'off') {
|
||||
add_filter('user_profile_picture_description', [$this, 'set_user_profile_picture_for_cravatar'], 1);
|
||||
add_filter('avatar_defaults', [$this, 'set_defaults_for_cravatar'], 1);
|
||||
add_filter('um_user_avatar_url_filter', [$this, 'get_cravatar_url'], 1);
|
||||
add_filter('bp_gravatar_url', [$this, 'get_cravatar_url'], 1);
|
||||
add_filter('get_avatar_url', [$this, 'get_cravatar_url'], 1);
|
||||
|
||||
add_action('wp_head', [$this, 'add_avatar_preconnect'], 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Cravatar URL
|
||||
*/
|
||||
public function get_cravatar_url($url) {
|
||||
switch ($this->settings['cravatar']) {
|
||||
case 'cn':
|
||||
return $this->replace_avatar_url($url, 'cn.cravatar.com');
|
||||
case 'global':
|
||||
return $this->replace_avatar_url($url, 'en.cravatar.com');
|
||||
case 'weavatar':
|
||||
return $this->replace_avatar_url($url, 'weavatar.com');
|
||||
default:
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换头像 URL
|
||||
*/
|
||||
public function replace_avatar_url($url, $domain) {
|
||||
$sources = array(
|
||||
'www.gravatar.com',
|
||||
'0.gravatar.com',
|
||||
'1.gravatar.com',
|
||||
'2.gravatar.com',
|
||||
's.gravatar.com',
|
||||
'secure.gravatar.com',
|
||||
'cn.gravatar.com',
|
||||
'en.gravatar.com',
|
||||
'gravatar.com',
|
||||
'sdn.geekzu.org',
|
||||
'gravatar.duoshuo.com',
|
||||
'gravatar.loli.net',
|
||||
'dn-qiniu-avatar.qbox.me'
|
||||
);
|
||||
|
||||
return str_replace($sources, $domain, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 WordPress 讨论设置中的默认 LOGO 名称
|
||||
*/
|
||||
public function set_defaults_for_cravatar($avatar_defaults) {
|
||||
if ($this->settings['cravatar'] == 'weavatar') {
|
||||
$avatar_defaults['gravatar_default'] = 'WeAvatar';
|
||||
} else {
|
||||
$avatar_defaults['gravatar_default'] = '初认头像';
|
||||
}
|
||||
|
||||
return $avatar_defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置个人资料卡中的头像上传地址
|
||||
*/
|
||||
public function set_user_profile_picture_for_cravatar() {
|
||||
if ($this->settings['cravatar'] == 'weavatar') {
|
||||
return '<a href="https://weavatar.com" target="_blank">您可以在 WeAvatar 修改您的资料图片</a>';
|
||||
} else {
|
||||
return '<a href="https://cravatar.com" target="_blank">您可以在初认头像修改您的资料图片</a>';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_avatar_preconnect() {
|
||||
switch ($this->settings['cravatar']) {
|
||||
case 'cn':
|
||||
echo '<link rel="dns-prefetch" href="//cn.cravatar.com">' . "\n";
|
||||
echo '<link rel="preconnect" href="https://cn.cravatar.com" crossorigin>' . "\n";
|
||||
break;
|
||||
case 'global':
|
||||
echo '<link rel="dns-prefetch" href="//en.cravatar.com">' . "\n";
|
||||
echo '<link rel="preconnect" href="https://en.cravatar.com" crossorigin>' . "\n";
|
||||
break;
|
||||
case 'weavatar':
|
||||
echo '<link rel="dns-prefetch" href="//weavatar.com">' . "\n";
|
||||
echo '<link rel="preconnect" href="https://weavatar.com" crossorigin>' . "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Service/Base.php
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class Base
|
||||
* 插件主服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Base {
|
||||
|
||||
private $services = [];
|
||||
|
||||
public function __construct() {
|
||||
$this->init_services();
|
||||
}
|
||||
|
||||
private function init_services() {
|
||||
$core_services = [
|
||||
'Super',
|
||||
'Monitor',
|
||||
'Memory',
|
||||
'Update',
|
||||
'Database',
|
||||
'Acceleration',
|
||||
'Avatar',
|
||||
'Fonts',
|
||||
'Comments',
|
||||
'Media',
|
||||
'Performance',
|
||||
'Maintenance'
|
||||
];
|
||||
|
||||
foreach ($core_services as $service) {
|
||||
$this->load_service($service);
|
||||
}
|
||||
|
||||
if (is_admin()) {
|
||||
$this->load_service('Setting');
|
||||
$this->load_service('Adblock');
|
||||
}
|
||||
}
|
||||
|
||||
private function load_service($service_name) {
|
||||
$class_name = __NAMESPACE__ . '\\' . $service_name;
|
||||
|
||||
if (class_exists($class_name)) {
|
||||
try {
|
||||
$this->services[$service_name] = new $class_name();
|
||||
} catch (\Exception $e) {
|
||||
error_log("WP-China-Yes: Failed to load service {$service_name}: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_service($service_name) {
|
||||
return $this->services[$service_name] ?? null;
|
||||
}
|
||||
}
|
||||
411
Service/Comments.php
Executable file
|
|
@ -0,0 +1,411 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class Comments {
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
|
||||
add_action('wp_enqueue_scripts', [$this, 'force_enqueue_jquery'], 5);
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
public function force_enqueue_jquery() {
|
||||
if (!is_admin()) {
|
||||
wp_enqueue_script('jquery');
|
||||
}
|
||||
}
|
||||
|
||||
private function init() {
|
||||
if (!isset($this->settings['comments_enable']) || !$this->settings['comments_enable']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->init_role_badge();
|
||||
$this->init_remove_website();
|
||||
$this->init_validation();
|
||||
$this->init_herp_derp();
|
||||
$this->init_sticky_moderate();
|
||||
}
|
||||
|
||||
private function init_role_badge() {
|
||||
if (!isset($this->settings['comments_role_badge']) || !$this->settings['comments_role_badge']) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_role_badge_styles']);
|
||||
add_filter('get_comment_author', [$this, 'add_role_badge'], 10, 3);
|
||||
add_filter('get_comment_author_link', [$this, 'add_role_badge_to_link']);
|
||||
}
|
||||
|
||||
private function init_remove_website() {
|
||||
if (!isset($this->settings['comments_remove_website']) || !$this->settings['comments_remove_website']) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter('comment_form_default_fields', [$this, 'remove_website_field']);
|
||||
}
|
||||
|
||||
private function init_validation() {
|
||||
if (!isset($this->settings['comments_validation']) || !$this->settings['comments_validation']) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_validation_scripts']);
|
||||
add_action('wp_footer', [$this, 'add_validation_script']);
|
||||
add_filter('preprocess_comment', [$this, 'validate_comment_content']);
|
||||
}
|
||||
|
||||
private function init_herp_derp() {
|
||||
if (!isset($this->settings['comments_herp_derp']) || !$this->settings['comments_herp_derp']) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_herp_derp_scripts']);
|
||||
add_action('wp_head', [$this, 'add_herp_derp_styles']);
|
||||
add_filter('comment_text', [$this, 'herp_derp_comment_text'], 40);
|
||||
}
|
||||
|
||||
private function init_sticky_moderate() {
|
||||
if (!isset($this->settings['comments_sticky_moderate']) || !$this->settings['comments_sticky_moderate']) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_action('admin_enqueue_scripts', [$this, 'enqueue_sticky_moderate_scripts']);
|
||||
add_filter('comment_row_actions', [$this, 'add_sticky_moderate_actions'], 10, 2);
|
||||
}
|
||||
|
||||
private $user_role = '';
|
||||
|
||||
public function enqueue_role_badge_styles() {
|
||||
wp_add_inline_style('wp-block-library', '
|
||||
.comment-author-role-badge {
|
||||
display: inline-block;
|
||||
padding: 3px 6px;
|
||||
margin-left: 0.5em;
|
||||
margin-right: 0.5em;
|
||||
background: #e8e8e8;
|
||||
border-radius: 2px;
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
font-size: 0.75rem;
|
||||
font-weight: normal;
|
||||
text-transform: none;
|
||||
text-align: left;
|
||||
line-height: 1;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.comment-author-role-badge--administrator { background: #c1e7f1; }
|
||||
.comment-author-role-badge--contributor { background: #c1f1d1; }
|
||||
.comment-author-role-badge--author { background: #fdf5c5; }
|
||||
.comment-author-role-badge--editor { background: #fdd8c5; }
|
||||
.comment-author-role-badge--subscriber { background: #e8e8e8; }
|
||||
.wp-block-comment-author-name .comment-author-role-badge {
|
||||
display: inline-block;
|
||||
margin-left: 0.5em;
|
||||
font-size: 0.75rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
');
|
||||
}
|
||||
|
||||
public function add_role_badge($author, $comment_id, $comment) {
|
||||
global $wp_roles;
|
||||
|
||||
if ($wp_roles) {
|
||||
$reply_user_id = $comment->user_id;
|
||||
if ($reply_user_id && $reply_user = new \WP_User($reply_user_id)) {
|
||||
if (isset($reply_user->roles[0])) {
|
||||
$user_role = translate_user_role($wp_roles->roles[$reply_user->roles[0]]['name']);
|
||||
$this->user_role = '<div class="comment-author-role-badge comment-author-role-badge--' . $reply_user->roles[0] . '">' . $user_role . '</div>';
|
||||
}
|
||||
} else {
|
||||
$this->user_role = '';
|
||||
}
|
||||
}
|
||||
return $author;
|
||||
}
|
||||
|
||||
public function add_role_badge_to_link($author_link) {
|
||||
return $author_link . $this->user_role;
|
||||
}
|
||||
|
||||
public function remove_website_field($fields) {
|
||||
if (isset($fields['url'])) {
|
||||
unset($fields['url']);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function enqueue_validation_scripts() {
|
||||
if (!is_singular() || !comments_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script('jquery');
|
||||
|
||||
wp_register_script('wpcy-comments-validation', '', ['jquery'], '1.0.0', true);
|
||||
wp_enqueue_script('wpcy-comments-validation');
|
||||
wp_add_inline_script('wpcy-comments-validation', '
|
||||
jQuery(document).ready(function($) {
|
||||
console.log("WP China Yes Comments: Validation script loaded");
|
||||
$("#commentform").on("submit", function(e) {
|
||||
var author = $("#author").val();
|
||||
var email = $("#email").val();
|
||||
var comment = $("#comment").val();
|
||||
var errors = [];
|
||||
|
||||
if ($("#author").length && (!author || author.length < 2)) {
|
||||
errors.push("请输入您的姓名(至少2个字符)");
|
||||
}
|
||||
|
||||
if ($("#email").length && (!email || !isValidEmail(email))) {
|
||||
errors.push("请输入有效的邮箱地址");
|
||||
}
|
||||
|
||||
if ($("#comment").length && (!comment || comment.length < 20)) {
|
||||
errors.push("评论内容至少需要20个字符");
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
e.preventDefault();
|
||||
alert("请修正以下错误:\n" + errors.join("\n"));
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
function isValidEmail(email) {
|
||||
var regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return regex.test(email);
|
||||
}
|
||||
});
|
||||
');
|
||||
}
|
||||
|
||||
public function add_validation_script() {
|
||||
if (!is_singular() || !comments_open()) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<style>
|
||||
.comment-form .required {
|
||||
color: #d63638;
|
||||
}
|
||||
.comment-form input:invalid,
|
||||
.comment-form textarea:invalid {
|
||||
border-color: #d63638;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function validate_comment_content($commentdata) {
|
||||
if (strlen($commentdata['comment_content']) < 20) {
|
||||
wp_die('评论内容至少需要20个字符。', '评论验证失败', ['back_link' => true]);
|
||||
}
|
||||
|
||||
if (str_contains($commentdata['comment_content'], 'href=')) {
|
||||
wp_die('评论中不允许包含活动链接,请返回编辑。', '评论验证失败', ['back_link' => true]);
|
||||
}
|
||||
|
||||
return $commentdata;
|
||||
}
|
||||
|
||||
public function enqueue_herp_derp_scripts() {
|
||||
if (!is_singular() || !comments_open()) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script('jquery');
|
||||
|
||||
wp_register_script('wpcy-comments-herpderp', '', ['jquery'], '1.0.0', true);
|
||||
wp_enqueue_script('wpcy-comments-herpderp');
|
||||
wp_add_inline_script('wpcy-comments-herpderp', '
|
||||
jQuery(document).ready(function($) {
|
||||
console.log("WP China Yes Comments: Herp Derp jQuery ready");
|
||||
|
||||
function derp(p, herpa) {
|
||||
if (!p.herp) {
|
||||
p.herp = p.innerHTML;
|
||||
var textContent = p.herp.replace(/<[^>]*>/g, "");
|
||||
var derpText = "";
|
||||
var chars = textContent.split("");
|
||||
var inWord = false;
|
||||
|
||||
for (var i = 0; i < chars.length; i++) {
|
||||
var char = chars[i];
|
||||
|
||||
if (/[a-zA-Z]/.test(char)) {
|
||||
if (!inWord) {
|
||||
if (derpText && !/\s$/.test(derpText)) derpText += " ";
|
||||
derpText += "阿巴";
|
||||
inWord = true;
|
||||
}
|
||||
} else if (/[\u4e00-\u9fff]/.test(char)) {
|
||||
if (inWord && !/\s$/.test(derpText)) derpText += " ";
|
||||
derpText += Math.random() > 0.5 ? "阿" : "巴";
|
||||
inWord = false;
|
||||
} else if (/\s/.test(char)) {
|
||||
if (inWord) {
|
||||
inWord = false;
|
||||
}
|
||||
if (derpText && !/\s$/.test(derpText)) {
|
||||
derpText += " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p.derp = derpText.trim();
|
||||
}
|
||||
p.innerHTML = (herpa ? p.herp : p.derp);
|
||||
}
|
||||
|
||||
function herpa(derpa) {
|
||||
$(".herpc").each(function() {
|
||||
derp(this, !derpa);
|
||||
});
|
||||
}
|
||||
|
||||
function initHerpDerp() {
|
||||
var commentsContainer = $("#comments, .comments-area, .comment-list, ol.commentlist, .wp-block-comments");
|
||||
console.log("Comments containers found:", commentsContainer.length);
|
||||
|
||||
if (commentsContainer.length === 0) {
|
||||
console.log("No comments container found, trying body");
|
||||
var bodyContainer = $("body");
|
||||
if (bodyContainer.length > 0) {
|
||||
var herpDiv = $("<div class=\"herpderp\" style=\"position: fixed; top: 10px; right: 10px; z-index: 9999; background: white; padding: 5px; border: 1px solid #ccc;\"></div>");
|
||||
var checkbox = $("<input type=\"checkbox\" id=\"herp-derp-toggle\">");
|
||||
var label = $("<label for=\"herp-derp-toggle\">阿巴阿巴</label>");
|
||||
|
||||
herpDiv.append(label).append(checkbox);
|
||||
|
||||
checkbox.on("change", function() {
|
||||
console.log("Herp derp toggled:", this.checked);
|
||||
herpa(this.checked);
|
||||
});
|
||||
|
||||
bodyContainer.append(herpDiv);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var targetContainer = commentsContainer.first();
|
||||
console.log("Target container:", targetContainer[0]);
|
||||
|
||||
var herpDiv = $("<div class=\"herpderp\"></div>");
|
||||
var checkbox = $("<input type=\"checkbox\" id=\"herp-derp-toggle\">");
|
||||
var label = $("<label for=\"herp-derp-toggle\">阿巴阿巴</label>");
|
||||
|
||||
herpDiv.append(label).append(checkbox);
|
||||
|
||||
checkbox.on("change", function() {
|
||||
console.log("Herp derp toggled:", this.checked);
|
||||
herpa(this.checked);
|
||||
});
|
||||
|
||||
targetContainer.before(herpDiv);
|
||||
}
|
||||
|
||||
initHerpDerp();
|
||||
});
|
||||
');
|
||||
}
|
||||
|
||||
public function add_herp_derp_styles() {
|
||||
if (!is_singular() || !comments_open()) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<style type="text/css">
|
||||
.herpderp {
|
||||
float: right;
|
||||
text-transform: uppercase;
|
||||
font-size: 7pt;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.herpderp input[type="checkbox"] {
|
||||
margin-left: 5px;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function herp_derp_comment_text($text) {
|
||||
if (!is_singular() || is_feed()) {
|
||||
return $text;
|
||||
}
|
||||
return '<span class="herpc">' . $text . '</span>';
|
||||
}
|
||||
|
||||
public function enqueue_sticky_moderate_scripts($hook) {
|
||||
if ($hook !== 'edit-comments.php') {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script('jquery');
|
||||
wp_add_inline_script('jquery', '
|
||||
jQuery(document).ready(function($) {
|
||||
$(".comment-sticky-moderate").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
var commentId = $(this).data("comment-id");
|
||||
var action = $(this).hasClass("sticky") ? "unsticky" : "sticky";
|
||||
|
||||
$.post(ajaxurl, {
|
||||
action: "sticky_moderate_comment",
|
||||
comment_id: commentId,
|
||||
sticky_action: action,
|
||||
nonce: "' . wp_create_nonce('sticky_moderate_nonce') . '"
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
');
|
||||
|
||||
add_action('wp_ajax_sticky_moderate_comment', [$this, 'handle_sticky_moderate_ajax']);
|
||||
}
|
||||
|
||||
public function add_sticky_moderate_actions($actions, $comment) {
|
||||
if ($comment->comment_approved == '0') {
|
||||
$is_sticky = get_comment_meta($comment->comment_ID, '_sticky_moderate', true);
|
||||
$text = $is_sticky ? '取消置顶' : '置顶审核';
|
||||
$class = $is_sticky ? 'sticky' : '';
|
||||
|
||||
$actions['sticky_moderate'] = sprintf(
|
||||
'<a href="#" class="comment-sticky-moderate %s" data-comment-id="%d">%s</a>',
|
||||
$class,
|
||||
$comment->comment_ID,
|
||||
$text
|
||||
);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
public function handle_sticky_moderate_ajax() {
|
||||
if (!wp_verify_nonce($_POST['nonce'], 'sticky_moderate_nonce')) {
|
||||
wp_die('安全验证失败');
|
||||
}
|
||||
|
||||
$comment_id = intval($_POST['comment_id']);
|
||||
$action = sanitize_text_field($_POST['sticky_action']);
|
||||
|
||||
if ($action === 'sticky') {
|
||||
update_comment_meta($comment_id, '_sticky_moderate', 1);
|
||||
} else {
|
||||
delete_comment_meta($comment_id, '_sticky_moderate');
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
}
|
||||
92
Service/Database.php
Executable file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Database
|
||||
* 数据库工具服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Database {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
$this->settings = get_settings();
|
||||
|
||||
// 如果启用了数据库工具,则允许访问数据库修复工具
|
||||
if ( ! empty( $this->settings['enable_db_tools'] ) && $this->settings['enable_db_tools'] ) {
|
||||
define( 'WP_ALLOW_REPAIR', true );
|
||||
}
|
||||
|
||||
// 处理调试常量
|
||||
$this->handle_debug_constants();
|
||||
|
||||
// 安全相关常量
|
||||
$this->handle_security_constants();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理调试模式相关常量
|
||||
*/
|
||||
private function handle_debug_constants() {
|
||||
if ( ! empty( $this->settings['enable_debug'] ) && $this->settings['enable_debug'] ) {
|
||||
// 只有在常量未定义时才定义
|
||||
if ( ! defined( 'WP_DEBUG' ) ) {
|
||||
define( 'WP_DEBUG', true );
|
||||
}
|
||||
if ( ! empty( $this->settings['debug_options']['wp_debug_log'] ) && ! defined( 'WP_DEBUG_LOG' ) ) {
|
||||
define( 'WP_DEBUG_LOG', true );
|
||||
}
|
||||
if ( ! empty( $this->settings['debug_options']['wp_debug_display'] ) && ! defined( 'WP_DEBUG_DISPLAY' ) ) {
|
||||
define( 'WP_DEBUG_DISPLAY', true );
|
||||
}
|
||||
if ( ! empty( $this->settings['debug_options']['script_debug'] ) && ! defined( 'SCRIPT_DEBUG' ) ) {
|
||||
define( 'SCRIPT_DEBUG', true );
|
||||
}
|
||||
if ( ! empty( $this->settings['debug_options']['save_queries'] ) && ! defined( 'SAVEQUERIES' ) ) {
|
||||
define( 'SAVEQUERIES', true );
|
||||
}
|
||||
} else {
|
||||
// 禁用调试模式时的默认值
|
||||
if ( ! defined( 'WP_DEBUG' ) ) {
|
||||
define( 'WP_DEBUG', false );
|
||||
}
|
||||
if ( ! defined( 'WP_DEBUG_LOG' ) ) {
|
||||
define( 'WP_DEBUG_LOG', false );
|
||||
}
|
||||
if ( ! defined( 'WP_DEBUG_DISPLAY' ) ) {
|
||||
define( 'WP_DEBUG_DISPLAY', false );
|
||||
}
|
||||
if ( ! defined( 'SCRIPT_DEBUG' ) ) {
|
||||
define( 'SCRIPT_DEBUG', false );
|
||||
}
|
||||
if ( ! defined( 'SAVEQUERIES' ) ) {
|
||||
define( 'SAVEQUERIES', false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理安全相关常量
|
||||
*/
|
||||
private function handle_security_constants() {
|
||||
if ( ! empty( $this->settings['disallow_file_edit'] ) && ! defined( 'DISALLOW_FILE_EDIT' ) ) {
|
||||
define( 'DISALLOW_FILE_EDIT', $this->settings['disallow_file_edit'] );
|
||||
}
|
||||
if ( ! empty( $this->settings['disallow_file_mods'] ) && ! defined( 'DISALLOW_FILE_MODS' ) ) {
|
||||
define( 'DISALLOW_FILE_MODS', $this->settings['disallow_file_mods'] );
|
||||
}
|
||||
if ( ! empty( $this->settings['force_ssl_admin'] ) && ! defined( 'FORCE_SSL_ADMIN' ) ) {
|
||||
define( 'FORCE_SSL_ADMIN', $this->settings['force_ssl_admin'] );
|
||||
}
|
||||
if ( ! empty( $this->settings['force_ssl_login'] ) && ! defined( 'FORCE_SSL_LOGIN' ) ) {
|
||||
define( 'FORCE_SSL_LOGIN', $this->settings['force_ssl_login'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
96
Service/ExampleModernService.php
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
use WenPai\ChinaYes\Service\TranslationManager;
|
||||
use WenPai\ChinaYes\Service\LazyTranslation;
|
||||
|
||||
class ExampleModernService {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
add_action('init', [$this, 'initializeService'], 15);
|
||||
}
|
||||
|
||||
public function initializeService() {
|
||||
$this->setupTranslatedContent();
|
||||
}
|
||||
|
||||
private function setupTranslatedContent() {
|
||||
$translatedOptions = [
|
||||
'store_section' => [
|
||||
'title' => $this->t('应用市场'),
|
||||
'description' => $this->t('选择您的应用市场加速方式'),
|
||||
'options' => [
|
||||
'wenpai' => $this->t('文派开源'),
|
||||
'proxy' => $this->t('官方镜像'),
|
||||
'off' => $this->t('不启用')
|
||||
]
|
||||
],
|
||||
'acceleration_section' => [
|
||||
'title' => $this->t('萌芽加速'),
|
||||
'description' => $this->t('前端资源加速设置'),
|
||||
'options' => [
|
||||
'googlefonts' => 'Google 字体',
|
||||
'googleajax' => 'Google 前端库',
|
||||
'cdnjs' => 'CDNJS 前端库'
|
||||
]
|
||||
],
|
||||
'notification_section' => [
|
||||
'title' => $this->t('通知管理'),
|
||||
'description' => $this->t('管理和控制 WordPress 后台各类通知的显示。'),
|
||||
'options' => [
|
||||
'disable_all' => $this->t('禁用所有通知'),
|
||||
'selective' => $this->t('选择性禁用'),
|
||||
'method' => $this->t('禁用方式')
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$this->processTranslatedOptions($translatedOptions);
|
||||
}
|
||||
|
||||
private function processTranslatedOptions($options) {
|
||||
foreach ($options as $section => $data) {
|
||||
error_log("处理部分: " . $data['title']);
|
||||
error_log("描述: " . $data['description']);
|
||||
|
||||
foreach ($data['options'] as $key => $value) {
|
||||
error_log("选项 {$key}: {$value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function t($text) {
|
||||
return TranslationManager::translate($text);
|
||||
}
|
||||
|
||||
public function demonstrateLazyTranslation() {
|
||||
$lazyTitle = LazyTranslation::create('应用市场');
|
||||
$lazyArray = LazyTranslation::createArray([
|
||||
'title' => '萌芽加速',
|
||||
'subtitle' => '文件加速',
|
||||
'options' => [
|
||||
'enable' => '启用',
|
||||
'disable' => '禁用'
|
||||
]
|
||||
]);
|
||||
|
||||
return [
|
||||
'lazy_title' => $lazyTitle,
|
||||
'lazy_array' => $lazyArray,
|
||||
'resolved_title' => (string)$lazyTitle,
|
||||
'resolved_array' => LazyTranslation::resolveArray($lazyArray)
|
||||
];
|
||||
}
|
||||
|
||||
public function getTranslationStatus() {
|
||||
return [
|
||||
'translations_loaded' => TranslationManager::isLoaded(),
|
||||
'init_action_fired' => did_action('init'),
|
||||
'plugins_loaded_fired' => did_action('plugins_loaded'),
|
||||
'current_hook' => current_action()
|
||||
];
|
||||
}
|
||||
}
|
||||
340
Service/Fonts.php
Executable file
|
|
@ -0,0 +1,340 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Fonts
|
||||
* 文风字体服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Fonts {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化文风字体功能
|
||||
*/
|
||||
private function init() {
|
||||
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] != 'off') {
|
||||
$this->load_typography();
|
||||
}
|
||||
|
||||
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] == 'optimize') {
|
||||
add_action('init', function () {
|
||||
wp_enqueue_style('windfonts-optimize', CHINA_YES_PLUGIN_URL . 'assets/css/fonts.css', [], CHINA_YES_VERSION);
|
||||
});
|
||||
}
|
||||
|
||||
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] == 'on') {
|
||||
add_action('wp_head', [$this, 'load_windfonts']);
|
||||
add_action('admin_head', [$this, 'load_windfonts']);
|
||||
}
|
||||
|
||||
if (!empty($this->settings['windfonts']) && $this->settings['windfonts'] == 'frontend') {
|
||||
add_action('wp_head', [$this, 'load_windfonts']);
|
||||
}
|
||||
|
||||
$this->init_rtl_mirror();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化RTL镜像测试功能
|
||||
*/
|
||||
private function init_rtl_mirror() {
|
||||
if (empty($this->settings['windfonts_reading_enable'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$reading_setting = $this->settings['windfonts_reading'] ?? 'off';
|
||||
|
||||
if ($reading_setting === 'global' || $reading_setting === 'frontend') {
|
||||
$this->load_rtl_mirror($reading_setting);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载文风字体
|
||||
*/
|
||||
public function load_windfonts() {
|
||||
static $license_shown = false;
|
||||
|
||||
if (!$license_shown) {
|
||||
echo <<<HTML
|
||||
<link rel="preconnect" href="https://cn.windfonts.com">
|
||||
<!-- 此中文网页字体由文风字体(Windfonts)免费提供,您可以自由引用,请务必保留此授权许可标注 https://wenfeng.org/license -->
|
||||
HTML;
|
||||
$license_shown = true;
|
||||
}
|
||||
|
||||
$loaded = [];
|
||||
foreach ((array) $this->settings['windfonts_list'] as $font) {
|
||||
if (empty($font['enable'])) {
|
||||
continue;
|
||||
}
|
||||
if (empty($font['family'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$css_url = $this->build_font_css_url($font);
|
||||
|
||||
if (in_array($css_url, $loaded)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$font_family = $this->extract_font_family_name($font['family']);
|
||||
|
||||
echo sprintf(<<<HTML
|
||||
<link rel="stylesheet" type="text/css" crossorigin="anonymous" href="%s">
|
||||
<style>
|
||||
%s {
|
||||
font-style: %s;
|
||||
font-weight: %s;
|
||||
font-family: '%s',sans-serif!important;
|
||||
}
|
||||
</style>
|
||||
HTML
|
||||
,
|
||||
$css_url,
|
||||
htmlspecialchars_decode($font['selector']),
|
||||
$font['style'] ?? 'normal',
|
||||
$font['weight'] ?? 400,
|
||||
$font_family
|
||||
);
|
||||
$loaded[] = $css_url;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建字体CSS URL
|
||||
*/
|
||||
private function build_font_css_url($font) {
|
||||
$base_url = 'https://app.windfonts.com/api/css';
|
||||
$params = [];
|
||||
|
||||
$params['family'] = $font['family'];
|
||||
|
||||
if (!empty($font['subset'])) {
|
||||
$params['subset'] = $font['subset'];
|
||||
}
|
||||
|
||||
if (!empty($font['lang'])) {
|
||||
$params['lang'] = $font['lang'];
|
||||
}
|
||||
|
||||
return $base_url . '?' . http_build_query($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取字体家族名称
|
||||
*/
|
||||
private function extract_font_family_name($family_param) {
|
||||
if (strpos($family_param, ':') !== false) {
|
||||
return explode(':', $family_param)[0];
|
||||
}
|
||||
return $family_param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载排印优化
|
||||
*/
|
||||
public function load_typography() {
|
||||
$this->load_chinese_typography();
|
||||
$this->load_english_typography();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载中文排印优化
|
||||
*/
|
||||
private function load_chinese_typography() {
|
||||
$cn_settings = (array) $this->settings['windfonts_typography_cn'];
|
||||
|
||||
if (in_array('indent', $cn_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content p {
|
||||
text-indent: 2em;
|
||||
}
|
||||
.entry-content .wp-block-group p,
|
||||
.entry-content .wp-block-columns p,
|
||||
.entry-content .wp-block-media-text p,
|
||||
.entry-content .wp-block-quote p {
|
||||
text-indent: 0;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('align', $cn_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
if (is_single()) {
|
||||
echo '<style>
|
||||
.entry-content p {
|
||||
text-align: justify;
|
||||
}
|
||||
.entry-content .wp-block-group p,
|
||||
.entry-content .wp-block-columns p,
|
||||
.entry-content .wp-block-media-text p,
|
||||
.entry-content .wp-block-quote p {
|
||||
text-align: unset !important;
|
||||
}
|
||||
.entry-content .wp-block-columns .has-text-align-center {
|
||||
text-align: center !important;
|
||||
}
|
||||
</style>';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('corner', $cn_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content {
|
||||
font-feature-settings: "halt" 1;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('space', $cn_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content {
|
||||
word-spacing: 0.1em;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('punctuation', $cn_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content {
|
||||
text-spacing: trim-start;
|
||||
hanging-punctuation: first last;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载英文排印优化
|
||||
*/
|
||||
private function load_english_typography() {
|
||||
$en_settings = (array) $this->settings['windfonts_typography_en'];
|
||||
|
||||
if (in_array('optimize', $en_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content {
|
||||
text-rendering: optimizeLegibility;
|
||||
font-variant-ligatures: common-ligatures;
|
||||
font-variant-numeric: oldstyle-nums;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('spacing', $en_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content {
|
||||
white-space: pre-line;
|
||||
}
|
||||
.entry-content p {
|
||||
white-space: normal;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('orphan', $en_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content p {
|
||||
orphans: 3;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('widow', $en_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content p {
|
||||
widows: 3;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
|
||||
if (in_array('punctuation', $en_settings)) {
|
||||
add_action('wp_head', function () {
|
||||
echo '<style>
|
||||
.entry-content {
|
||||
font-feature-settings: "kern" 1, "liga" 1, "clig" 1;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 加载RTL镜像测试功能
|
||||
*/
|
||||
private function load_rtl_mirror($mode = 'global') {
|
||||
$rtl_styles = '<style type="text/css" media="screen">
|
||||
html {
|
||||
transform: scaleX(-1);
|
||||
}
|
||||
html::after {
|
||||
content: "RTL镜像测试模式";
|
||||
position: fixed;
|
||||
display: inline-block;
|
||||
left: 50%;
|
||||
top: -3px;
|
||||
padding: 10px 20px;
|
||||
font-size: 12px;
|
||||
font-family: sans-serif;
|
||||
text-transform: uppercase;
|
||||
background: #21759b;
|
||||
color: #fff;
|
||||
white-space: nowrap;
|
||||
z-index: 9999999;
|
||||
border-radius: 3px;
|
||||
transform: scaleX(-1) translateX(50%);
|
||||
transform-origin: 50% 0;
|
||||
}
|
||||
#wpadminbar { margin-top: -32px; }
|
||||
.wp-admin #wpadminbar { margin-top: 0; }
|
||||
</style>';
|
||||
|
||||
if ($mode === 'global') {
|
||||
add_action('wp_head', function () use ($rtl_styles) {
|
||||
echo $rtl_styles;
|
||||
}, 9999);
|
||||
|
||||
add_action('admin_print_styles', function () use ($rtl_styles) {
|
||||
echo $rtl_styles;
|
||||
}, 9999);
|
||||
} elseif ($mode === 'frontend') {
|
||||
add_action('wp_head', function () use ($rtl_styles) {
|
||||
echo $rtl_styles;
|
||||
}, 9999);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
277
Service/Language.php
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Language
|
||||
* 语言切换服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Language {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
|
||||
if ( $this->is_enabled( $this->settings['waimao_enable'] ?? false ) ) {
|
||||
if ( $this->is_enabled( $this->settings['waimao_language_split'] ?? false ) ) {
|
||||
$this->init_language_split();
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'wp_china_yes_wp_china_yes_save_after', [ $this, 'apply_language_settings' ] );
|
||||
|
||||
add_action( 'update_option_WPLANG', [ $this, 'sync_frontend_language_to_plugin' ], 10, 2 );
|
||||
add_action( 'updated_user_meta', [ $this, 'sync_admin_language_to_plugin' ], 10, 4 );
|
||||
add_action( 'admin_init', [ $this, 'sync_plugin_settings_from_wp' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化语言分离功能
|
||||
*/
|
||||
private function init_language_split() {
|
||||
add_filter( 'locale', [ $this, 'set_locale' ], 10, 1 );
|
||||
add_filter( 'determine_locale', [ $this, 'determine_locale' ], 10, 1 );
|
||||
|
||||
if ( $this->is_enabled( $this->settings['waimao_auto_detect'] ?? false ) ) {
|
||||
add_action( 'init', [ $this, 'auto_detect_language' ], 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置语言环境
|
||||
*/
|
||||
public function set_locale( $locale ) {
|
||||
if ( is_admin() ) {
|
||||
return $this->get_admin_locale();
|
||||
} else {
|
||||
return $this->get_frontend_locale();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确定语言环境
|
||||
*/
|
||||
public function determine_locale( $locale ) {
|
||||
if ( is_admin() ) {
|
||||
return $this->get_admin_locale();
|
||||
} else {
|
||||
return $this->get_frontend_locale();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用语言设置到WordPress系统
|
||||
*/
|
||||
public function apply_language_settings( $data ) {
|
||||
$this->settings = $data;
|
||||
|
||||
$waimao_enable = $this->settings['waimao_enable'] ?? false;
|
||||
$language_split = $this->settings['waimao_language_split'] ?? false;
|
||||
|
||||
if ( $this->is_enabled( $waimao_enable ) ) {
|
||||
if ( $this->is_enabled( $language_split ) ) {
|
||||
|
||||
if ( ! empty( $this->settings['waimao_admin_language'] ) ) {
|
||||
$user_id = get_current_user_id();
|
||||
if ( $user_id ) {
|
||||
update_user_meta( $user_id, 'locale', $this->settings['waimao_admin_language'] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $this->settings['waimao_frontend_language'] ) ) {
|
||||
$old_wplang = get_option( 'WPLANG', '' );
|
||||
$new_wplang = $this->settings['waimao_frontend_language'];
|
||||
|
||||
if ( $old_wplang !== $new_wplang ) {
|
||||
update_option( 'WPLANG', $new_wplang );
|
||||
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
|
||||
error_log( "WPLANG updated from '{$old_wplang}' to '{$new_wplang}'" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查设置是否启用(处理布尔值和字符串)
|
||||
*/
|
||||
private function is_enabled( $value ) {
|
||||
return $value === true || $value === 'true' || $value === '1' || $value === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后台语言
|
||||
*/
|
||||
private function get_admin_locale() {
|
||||
$admin_language = $this->settings['waimao_admin_language'] ?? get_locale();
|
||||
return $admin_language;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取前台语言
|
||||
*/
|
||||
private function get_frontend_locale() {
|
||||
if ( $this->is_enabled( $this->settings['waimao_auto_detect'] ?? false ) ) {
|
||||
$detected_locale = $this->detect_browser_language();
|
||||
if ( $detected_locale ) {
|
||||
return $detected_locale;
|
||||
}
|
||||
}
|
||||
|
||||
$frontend_language = $this->settings['waimao_frontend_language'] ?? get_option('WPLANG', 'en_US');
|
||||
return $frontend_language;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动检测语言
|
||||
*/
|
||||
public function auto_detect_language() {
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$detected_locale = $this->detect_browser_language();
|
||||
if ( $detected_locale ) {
|
||||
add_filter( 'locale', function() use ( $detected_locale ) {
|
||||
return $detected_locale;
|
||||
}, 20 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测浏览器语言
|
||||
*/
|
||||
private function detect_browser_language() {
|
||||
if ( ! isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$supported_languages = [
|
||||
'zh-cn' => 'zh_CN',
|
||||
'zh-tw' => 'zh_TW',
|
||||
'zh-hk' => 'zh_TW',
|
||||
'en-us' => 'en_US',
|
||||
'en-gb' => 'en_GB',
|
||||
'en' => 'en_US',
|
||||
'ja' => 'ja',
|
||||
'ko' => 'ko_KR',
|
||||
'de' => 'de_DE',
|
||||
'fr' => 'fr_FR',
|
||||
'es' => 'es_ES',
|
||||
'ru' => 'ru_RU',
|
||||
];
|
||||
|
||||
$accept_language = strtolower( $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
|
||||
$languages = explode( ',', $accept_language );
|
||||
|
||||
foreach ( $languages as $language ) {
|
||||
$language = trim( explode( ';', $language )[0] );
|
||||
|
||||
if ( isset( $supported_languages[ $language ] ) ) {
|
||||
return $supported_languages[ $language ];
|
||||
}
|
||||
|
||||
$language_code = explode( '-', $language )[0];
|
||||
if ( isset( $supported_languages[ $language_code ] ) ) {
|
||||
return $supported_languages[ $language_code ];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可用语言列表
|
||||
*/
|
||||
public static function get_available_languages() {
|
||||
return [
|
||||
'zh_CN' => '简体中文',
|
||||
'zh_TW' => '繁体中文',
|
||||
'en_US' => 'English (US)',
|
||||
'en_GB' => 'English (UK)',
|
||||
'ja' => '日本語',
|
||||
'ko_KR' => '한국어',
|
||||
'de_DE' => 'Deutsch',
|
||||
'fr_FR' => 'Français',
|
||||
'es_ES' => 'Español',
|
||||
'ru_RU' => 'Русский',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查语言文件是否存在
|
||||
*/
|
||||
public function is_language_available( $locale ) {
|
||||
if ( $locale === 'en_US' ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$language_file = WP_LANG_DIR . '/wp-' . $locale . '.mo';
|
||||
return file_exists( $language_file );
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步前台语言设置到插件
|
||||
*/
|
||||
public function sync_frontend_language_to_plugin( $old_value, $new_value ) {
|
||||
if ( $this->is_enabled( $this->settings['waimao_enable'] ?? false ) ) {
|
||||
if ( $this->is_enabled( $this->settings['waimao_language_split'] ?? false ) ) {
|
||||
$current_settings = get_option( 'wp_china_yes', [] );
|
||||
$current_settings['waimao_frontend_language'] = $new_value;
|
||||
update_option( 'wp_china_yes', $current_settings );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步后台语言设置到插件
|
||||
*/
|
||||
public function sync_admin_language_to_plugin( $meta_id, $user_id, $meta_key, $meta_value ) {
|
||||
if ( $meta_key === 'locale' && $user_id === get_current_user_id() ) {
|
||||
if ( $this->is_enabled( $this->settings['waimao_enable'] ?? false ) ) {
|
||||
if ( $this->is_enabled( $this->settings['waimao_language_split'] ?? false ) ) {
|
||||
$current_settings = get_option( 'wp_china_yes', [] );
|
||||
$current_settings['waimao_admin_language'] = $meta_value;
|
||||
update_option( 'wp_china_yes', $current_settings );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从WordPress系统同步语言设置到插件
|
||||
*/
|
||||
public function sync_plugin_settings_from_wp() {
|
||||
if ( $this->is_enabled( $this->settings['waimao_enable'] ?? false ) ) {
|
||||
if ( $this->is_enabled( $this->settings['waimao_language_split'] ?? false ) ) {
|
||||
$current_settings = get_option( 'wp_china_yes', [] );
|
||||
$needs_update = false;
|
||||
|
||||
$wp_frontend_lang = get_option( 'WPLANG', '' );
|
||||
if ( $current_settings['waimao_frontend_language'] !== $wp_frontend_lang ) {
|
||||
$current_settings['waimao_frontend_language'] = $wp_frontend_lang;
|
||||
$needs_update = true;
|
||||
}
|
||||
|
||||
$user_locale = get_user_meta( get_current_user_id(), 'locale', true );
|
||||
if ( $user_locale && $current_settings['waimao_admin_language'] !== $user_locale ) {
|
||||
$current_settings['waimao_admin_language'] = $user_locale;
|
||||
$needs_update = true;
|
||||
}
|
||||
|
||||
if ( $needs_update ) {
|
||||
update_option( 'wp_china_yes', $current_settings );
|
||||
$this->settings = $current_settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
Service/LazyTranslation.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
class LazyTranslation {
|
||||
|
||||
private $text;
|
||||
private $domain;
|
||||
private $context;
|
||||
|
||||
public function __construct($text, $domain = 'wp-china-yes', $context = null) {
|
||||
$this->text = $text;
|
||||
$this->domain = $domain;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return $this->resolve();
|
||||
}
|
||||
|
||||
public function resolve() {
|
||||
if (did_action('init')) {
|
||||
if ($this->context) {
|
||||
return _x($this->text, $this->context, $this->domain);
|
||||
}
|
||||
return __($this->text, $this->domain);
|
||||
}
|
||||
|
||||
return TranslationManager::getFallback($this->text);
|
||||
}
|
||||
|
||||
public function getText() {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function getDomain() {
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
public function getContext() {
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
public static function create($text, $domain = 'wp-china-yes', $context = null) {
|
||||
return new self($text, $domain, $context);
|
||||
}
|
||||
|
||||
public static function createArray($texts, $domain = 'wp-china-yes') {
|
||||
$result = [];
|
||||
foreach ($texts as $key => $text) {
|
||||
if (is_string($text)) {
|
||||
$result[$key] = new self($text, $domain);
|
||||
} else {
|
||||
$result[$key] = $text;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function resolveArray($array) {
|
||||
$result = [];
|
||||
foreach ($array as $key => $value) {
|
||||
if ($value instanceof self) {
|
||||
$result[$key] = $value->resolve();
|
||||
} elseif (is_array($value)) {
|
||||
$result[$key] = self::resolveArray($value);
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
function t($text, $domain = 'wp-china-yes', $context = null) {
|
||||
return LazyTranslation::create($text, $domain, $context);
|
||||
}
|
||||
|
||||
function tr($text, $domain = 'wp-china-yes', $context = null) {
|
||||
if (did_action('init')) {
|
||||
if ($context) {
|
||||
return _x($text, $context, $domain);
|
||||
}
|
||||
return __($text, $domain);
|
||||
}
|
||||
return TranslationManager::getFallback($text);
|
||||
}
|
||||
0
Service/Mail.php
Executable file
136
Service/Maintenance.php
Executable file
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class Maintenance {
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
|
||||
// 维护模式检查
|
||||
if (!empty($this->settings['maintenance_mode'])) {
|
||||
add_action('template_redirect', [$this, 'check_maintenance_mode']);
|
||||
add_action('admin_bar_menu', [$this, 'add_admin_bar_notice'], 100);
|
||||
}
|
||||
|
||||
// 仪表盘统计信息
|
||||
if (!empty($this->settings['disk']) && $this->settings['disk']) {
|
||||
add_action('dashboard_glance_items', [$this, 'add_dashboard_stats']);
|
||||
add_action('admin_head', [$this, 'add_admin_css']);
|
||||
}
|
||||
|
||||
// 添加登录记录钩子
|
||||
add_action('wp_login', [$this, 'record_last_login'], 10, 2);
|
||||
}
|
||||
|
||||
// 添加 CSS 样式
|
||||
public function add_admin_css() {
|
||||
$screen = get_current_screen();
|
||||
if ($screen->id === 'dashboard') {
|
||||
echo '<style>
|
||||
#dashboard_right_now .stat-item span.dashicons {
|
||||
margin: 0 3px 0 -25px;
|
||||
background: white;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
</style>';
|
||||
}
|
||||
}
|
||||
|
||||
public function add_dashboard_stats($items) {
|
||||
if (!is_array($items)) {
|
||||
$items = array();
|
||||
}
|
||||
|
||||
// 获取显示选项设置
|
||||
$display_options = $this->settings['disk_display'] ?? [];
|
||||
|
||||
// 媒体文件统计
|
||||
if (in_array('media_num', $display_options)) {
|
||||
$media_count = wp_count_posts('attachment')->inherit;
|
||||
$items['media'] = sprintf(
|
||||
'<a href="%s" class="stat-item"><span class="dashicons dashicons-format-gallery"></span> %s</a>',
|
||||
admin_url('upload.php'),
|
||||
sprintf('%d 个媒体', $media_count)
|
||||
);
|
||||
}
|
||||
|
||||
// 管理员统计
|
||||
if (in_array('admin_num', $display_options)) {
|
||||
$admin_count = count(get_users(['role' => 'administrator', 'fields' => 'ID']));
|
||||
$items['admins'] = sprintf(
|
||||
'<a href="%s" class="stat-item"><span class="dashicons dashicons-shield-alt"></span> %s</a>',
|
||||
admin_url('users.php?role=administrator'),
|
||||
sprintf('%d 个管理员', $admin_count)
|
||||
);
|
||||
}
|
||||
|
||||
// 用户总数统计
|
||||
if (in_array('user_num', $display_options)) {
|
||||
$total_users = count(get_users(['fields' => 'ID']));
|
||||
$items['users'] = sprintf(
|
||||
'<a href="%s" class="stat-item"><span class="dashicons dashicons-groups"></span> %s</a>',
|
||||
admin_url('users.php'),
|
||||
sprintf('%d 个用户', $total_users)
|
||||
);
|
||||
}
|
||||
|
||||
// 磁盘使用统计
|
||||
$disk_info = $this->get_disk_usage_info();
|
||||
if (in_array('disk_usage', $display_options)) {
|
||||
$items['disk_usage'] = sprintf(
|
||||
'<span class="stat-item"><span class="dashicons dashicons-database"></span> 磁盘用量:%s / %s</span>',
|
||||
size_format($disk_info['used']),
|
||||
size_format($disk_info['total'])
|
||||
);
|
||||
}
|
||||
|
||||
if (in_array('disk_limit', $display_options)) {
|
||||
$items['disk_free'] = sprintf(
|
||||
'<span class="stat-item"><span class="dashicons dashicons-chart-area"></span> 剩余空间:%s (%s%%)</span>',
|
||||
size_format($disk_info['free']),
|
||||
round(($disk_info['free'] / $disk_info['total']) * 100, 2)
|
||||
);
|
||||
}
|
||||
|
||||
// 上次登录时间
|
||||
if (in_array('lastlogin', $display_options)) {
|
||||
$current_user_id = get_current_user_id();
|
||||
$last_login = get_user_meta($current_user_id, 'last_login', true);
|
||||
$items['lastlogin'] = sprintf(
|
||||
'<span class="stat-item"><span class="dashicons dashicons-clock"></span> 上次登录:%s</span>',
|
||||
$last_login ? date('Y.m.d H:i:s', $last_login) : '从未登录'
|
||||
);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function get_disk_usage_info() {
|
||||
$disk_info = get_transient('disk_usage_info');
|
||||
if (false === $disk_info) {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$disk_total = disk_total_space($upload_dir['basedir']);
|
||||
$disk_free = disk_free_space($upload_dir['basedir']);
|
||||
$disk_used = $disk_total - $disk_free;
|
||||
|
||||
$disk_info = [
|
||||
'used' => $disk_used,
|
||||
'total' => $disk_total,
|
||||
'free' => $disk_free,
|
||||
];
|
||||
set_transient('disk_usage_info', $disk_info, HOUR_IN_SECONDS);
|
||||
}
|
||||
return $disk_info;
|
||||
}
|
||||
|
||||
public function record_last_login($user_login, $user) {
|
||||
update_user_meta($user->ID, 'last_login', time());
|
||||
}
|
||||
}
|
||||
90
Service/Media.php
Executable file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class Media {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
private function init() {
|
||||
if (!empty($this->settings['optimize_images'])) {
|
||||
add_filter('wp_image_editors', [$this, 'set_image_editor']);
|
||||
add_filter('jpeg_quality', [$this, 'set_jpeg_quality']);
|
||||
}
|
||||
|
||||
if (!empty($this->settings['lazy_load'])) {
|
||||
add_filter('wp_lazy_loading_enabled', '__return_true');
|
||||
}
|
||||
|
||||
add_filter('wp_get_attachment_image_attributes', [$this, 'add_image_attributes'], 10, 3);
|
||||
|
||||
if (!empty($this->settings['webp_support'])) {
|
||||
add_filter('wp_generate_attachment_metadata', [$this, 'generate_webp_versions']);
|
||||
}
|
||||
}
|
||||
|
||||
public function set_image_editor($editors) {
|
||||
if (extension_loaded('imagick')) {
|
||||
array_unshift($editors, 'WP_Image_Editor_Imagick');
|
||||
}
|
||||
return $editors;
|
||||
}
|
||||
|
||||
public function set_jpeg_quality($quality) {
|
||||
return intval($this->settings['jpeg_quality'] ?? 85);
|
||||
}
|
||||
|
||||
public function add_image_attributes($attr, $attachment, $size) {
|
||||
if (!empty($this->settings['lazy_load']) && !is_admin()) {
|
||||
$attr['loading'] = 'lazy';
|
||||
}
|
||||
|
||||
if (!empty($this->settings['responsive_images'])) {
|
||||
$attr['sizes'] = '(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw';
|
||||
}
|
||||
|
||||
return $attr;
|
||||
}
|
||||
|
||||
public function generate_webp_versions($metadata) {
|
||||
if (!function_exists('imagewebp')) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
$file_path = $upload_dir['basedir'] . '/' . $metadata['file'];
|
||||
|
||||
if (file_exists($file_path)) {
|
||||
$webp_path = preg_replace('/\.(jpe?g|png)$/i', '.webp', $file_path);
|
||||
|
||||
$image_type = wp_check_filetype($file_path)['type'];
|
||||
|
||||
switch ($image_type) {
|
||||
case 'image/jpeg':
|
||||
$image = imagecreatefromjpeg($file_path);
|
||||
break;
|
||||
case 'image/png':
|
||||
$image = imagecreatefrompng($file_path);
|
||||
break;
|
||||
default:
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
if ($image) {
|
||||
imagewebp($image, $webp_path, 85);
|
||||
imagedestroy($image);
|
||||
}
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
}
|
||||
273
Service/Memory.php
Executable file
|
|
@ -0,0 +1,273 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
|
||||
/**
|
||||
* Class Memory
|
||||
* 显示服务器 IP 和内存使用情况
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Memory {
|
||||
private $memory = [];
|
||||
private $server_ip_address = '';
|
||||
private $os_info = '';
|
||||
private $debug_status = '';
|
||||
private $cpu_usage = null;
|
||||
private $mysql_version = '';
|
||||
|
||||
public function __construct() {
|
||||
$settings = get_settings();
|
||||
if (!empty($settings['memory'])) {
|
||||
add_action('plugins_loaded', [$this, 'initialize']);
|
||||
}
|
||||
register_activation_hook(CHINA_YES_PLUGIN_FILE, [$this, 'check_php_version']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化插件
|
||||
*/
|
||||
public function initialize() {
|
||||
add_action('init', [$this, 'check_memory_limit']);
|
||||
add_filter('admin_footer_text', [$this, 'add_footer']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统信息
|
||||
*/
|
||||
private function get_os_info() {
|
||||
$os = php_uname('s');
|
||||
|
||||
// 转换为更直观的名称
|
||||
switch (strtolower($os)) {
|
||||
case 'linux':
|
||||
return 'Linux';
|
||||
case 'darwin':
|
||||
return 'macOS';
|
||||
case 'windows nt':
|
||||
return 'Windows';
|
||||
default:
|
||||
return $os;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取调试状态
|
||||
*/
|
||||
private function get_debug_status() {
|
||||
if (defined('WP_DEBUG') && true === WP_DEBUG) {
|
||||
return '<strong><font color="#F60">WP_DEBUG</font></strong>';
|
||||
}
|
||||
return '<span style="text-decoration: line-through;">WP_DEBUG</span>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 CPU 使用率
|
||||
*/
|
||||
private function get_cpu_usage() {
|
||||
if (function_exists('sys_getloadavg') && is_callable('sys_getloadavg')) {
|
||||
$load = sys_getloadavg();
|
||||
return round($load[0] * 100 / 4, 2); // 假设是4核CPU
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 MySQL 版本
|
||||
*/
|
||||
private function get_mysql_version() {
|
||||
global $wpdb;
|
||||
return $wpdb->get_var("SELECT VERSION()");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 PHP 内存限制
|
||||
*/
|
||||
public function check_memory_limit() {
|
||||
$this->memory['limit'] = (int) ini_get('memory_limit');
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查内存使用情况
|
||||
*/
|
||||
private function check_memory_usage() {
|
||||
$this->memory['usage'] = function_exists('memory_get_peak_usage')
|
||||
? round(memory_get_peak_usage(true) / 1024 / 1024, 2)
|
||||
: 0;
|
||||
|
||||
if (!empty($this->memory['usage']) && !empty($this->memory['limit'])) {
|
||||
$this->memory['percent'] = round($this->memory['usage'] / $this->memory['limit'] * 100, 0);
|
||||
$this->memory['color'] = $this->get_memory_color($this->memory['percent']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取内存使用率的颜色
|
||||
*/
|
||||
private function get_memory_color($percent) {
|
||||
if ($percent > 90) {
|
||||
return 'font-weight:bold;color:red';
|
||||
} elseif ($percent > 75) {
|
||||
return 'font-weight:bold;color:#E66F00';
|
||||
}
|
||||
return 'font-weight:normal;';
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化 WordPress 内存限制
|
||||
*/
|
||||
private function format_wp_limit($size) {
|
||||
$unit = strtoupper(substr($size, -1));
|
||||
$value = (int) substr($size, 0, -1);
|
||||
|
||||
switch ($unit) {
|
||||
case 'P': $value *= 1024;
|
||||
case 'T': $value *= 1024;
|
||||
case 'G': $value *= 1024;
|
||||
case 'M': $value *= 1024;
|
||||
case 'K': $value *= 1024;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 WordPress 内存限制
|
||||
*/
|
||||
private function check_wp_limit() {
|
||||
$memory = $this->format_wp_limit(WP_MEMORY_LIMIT);
|
||||
return $memory ? size_format($memory) : 'N/A';
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加信息到管理界面页脚
|
||||
*/
|
||||
public function add_footer($content) {
|
||||
$settings = get_settings();
|
||||
|
||||
// 设置默认显示选项
|
||||
$default_options = [
|
||||
'memory_usage',
|
||||
'wp_limit',
|
||||
'server_ip',
|
||||
];
|
||||
|
||||
// 如果设置为空或不是数组,使用默认选项
|
||||
$display_options = isset($settings['memory_display']) && is_array($settings['memory_display'])
|
||||
? $settings['memory_display']
|
||||
: $default_options;
|
||||
|
||||
// 如果 memory 设置未启用,直接返回原始内容
|
||||
if (empty($settings['memory'])) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$this->check_memory_usage();
|
||||
$this->server_ip_address = $_SERVER['SERVER_ADDR'] ?? ($_SERVER['LOCAL_ADDR'] ?? '');
|
||||
$this->os_info = $this->get_os_info();
|
||||
|
||||
$footer_parts = [];
|
||||
|
||||
|
||||
// 内存使用量
|
||||
if (in_array('memory_usage', $display_options)) {
|
||||
$footer_parts[] = sprintf('%s: %s %s %s MB (<span style="%s">%s%%</span>)',
|
||||
'Memory',
|
||||
$this->memory['usage'],
|
||||
'of',
|
||||
$this->memory['limit'],
|
||||
$this->memory['color'],
|
||||
$this->memory['percent']
|
||||
);
|
||||
}
|
||||
|
||||
// WP内存限制
|
||||
if (in_array('wp_limit', $display_options)) {
|
||||
$footer_parts[] = sprintf('%s: %s',
|
||||
'WP LIMIT',
|
||||
$this->check_wp_limit()
|
||||
);
|
||||
}
|
||||
|
||||
// 服务器IP和主机名
|
||||
if (in_array('server_ip', $display_options)) {
|
||||
$hostname_part = in_array('hostname', $display_options) ? " (" . gethostname() . ")" : "";
|
||||
$footer_parts[] = sprintf('IP: %s%s',
|
||||
$this->server_ip_address,
|
||||
$hostname_part
|
||||
);
|
||||
}
|
||||
|
||||
// 操作系统信息
|
||||
if (in_array('os_info', $display_options)) {
|
||||
$footer_parts[] = sprintf('OS: %s', $this->os_info);
|
||||
}
|
||||
|
||||
// PHP信息
|
||||
if (in_array('php_info', $display_options)) {
|
||||
$footer_parts[] = sprintf('PHP: %s @%sBitOS',
|
||||
PHP_VERSION,
|
||||
PHP_INT_SIZE * 8
|
||||
);
|
||||
}
|
||||
|
||||
// Debug状态
|
||||
if (in_array('debug_status', $display_options)) {
|
||||
$footer_parts[] = $this->get_debug_status();
|
||||
}
|
||||
|
||||
// CPU使用率
|
||||
if (in_array('cpu_usage', $display_options)) {
|
||||
$cpu_usage = $this->get_cpu_usage();
|
||||
if ($cpu_usage !== false) {
|
||||
$footer_parts[] = sprintf('CPU: %s%%', $cpu_usage);
|
||||
}
|
||||
}
|
||||
|
||||
// MySQL版本
|
||||
if (in_array('mysql_version', $display_options)) {
|
||||
$footer_parts[] = sprintf('MySQL: %s', $this->get_mysql_version());
|
||||
}
|
||||
|
||||
if (!empty($footer_parts)) {
|
||||
$content .= ' | WPCY - ' . implode(' | ', $footer_parts);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查 PHP 版本
|
||||
*/
|
||||
public function check_php_version() {
|
||||
if (version_compare(PHP_VERSION, '7.0', '<')) {
|
||||
deactivate_plugins(plugin_basename(CHINA_YES_PLUGIN_FILE));
|
||||
wp_die(
|
||||
sprintf(
|
||||
'<h1>%s</h1><p>%s</p>',
|
||||
'插件无法激活:PHP 版本过低',
|
||||
'请升级 PHP 至 7.0 或更高版本。'
|
||||
),
|
||||
'PHP 版本错误',
|
||||
['back_link' => true]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新设置
|
||||
*/
|
||||
private function update_settings() {
|
||||
if ( is_multisite() ) {
|
||||
update_site_option( 'wp_china_yes', $this->settings );
|
||||
} else {
|
||||
update_option( 'wp_china_yes', $this->settings, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
110
Service/Migration.php
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class Migration {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
add_action( 'admin_init', [ $this, 'migrate_windfonts_settings' ] );
|
||||
}
|
||||
|
||||
public function migrate_windfonts_settings() {
|
||||
$current_settings = get_option( 'wp_china_yes', [] );
|
||||
$needs_migration = false;
|
||||
|
||||
if ( ! empty( $current_settings['windfonts_list'] ) ) {
|
||||
foreach ( $current_settings['windfonts_list'] as $index => $font ) {
|
||||
if ( isset( $font['css'] ) && ! isset( $font['subset'] ) ) {
|
||||
$migrated_font = $this->migrate_font_config( $font );
|
||||
$current_settings['windfonts_list'][$index] = $migrated_font;
|
||||
$needs_migration = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $needs_migration ) {
|
||||
update_option( 'wp_china_yes', $current_settings );
|
||||
}
|
||||
}
|
||||
|
||||
private function migrate_font_config( $old_font ) {
|
||||
$new_font = [
|
||||
'family' => $this->extract_family_from_old_config( $old_font ),
|
||||
'subset' => $this->extract_subset_from_old_config( $old_font ),
|
||||
'lang' => '',
|
||||
'weight' => $old_font['weight'] ?? 400,
|
||||
'style' => $old_font['style'] ?? 'normal',
|
||||
'selector' => $old_font['selector'] ?? '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])',
|
||||
'enable' => $old_font['enable'] ?? true,
|
||||
];
|
||||
|
||||
return $new_font;
|
||||
}
|
||||
|
||||
private function extract_family_from_old_config( $old_font ) {
|
||||
if ( isset( $old_font['family'] ) ) {
|
||||
return $old_font['family'];
|
||||
}
|
||||
|
||||
if ( isset( $old_font['css'] ) ) {
|
||||
$css_url = $old_font['css'];
|
||||
|
||||
if ( strpos( $css_url, 'syhtcjk' ) !== false ) {
|
||||
return 'cszt';
|
||||
}
|
||||
|
||||
if ( preg_match( '/fonts\/([^\/]+)\//', $css_url, $matches ) ) {
|
||||
return $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
return 'cszt';
|
||||
}
|
||||
|
||||
private function extract_subset_from_old_config( $old_font ) {
|
||||
if ( isset( $old_font['css'] ) ) {
|
||||
$css_url = $old_font['css'];
|
||||
|
||||
if ( strpos( $css_url, '/regular/' ) !== false ) {
|
||||
return 'regular';
|
||||
}
|
||||
if ( strpos( $css_url, '/bold/' ) !== false ) {
|
||||
return 'bold';
|
||||
}
|
||||
if ( strpos( $css_url, '/light/' ) !== false ) {
|
||||
return 'light';
|
||||
}
|
||||
if ( strpos( $css_url, '/medium/' ) !== false ) {
|
||||
return 'medium';
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $old_font['weight'] ) ) {
|
||||
$weight = intval( $old_font['weight'] );
|
||||
if ( $weight <= 200 ) {
|
||||
return 'thin';
|
||||
} elseif ( $weight <= 300 ) {
|
||||
return 'light';
|
||||
} elseif ( $weight <= 500 ) {
|
||||
return 'regular';
|
||||
} elseif ( $weight <= 600 ) {
|
||||
return 'medium';
|
||||
} elseif ( $weight <= 700 ) {
|
||||
return 'semibold';
|
||||
} elseif ( $weight <= 800 ) {
|
||||
return 'bold';
|
||||
} else {
|
||||
return 'black';
|
||||
}
|
||||
}
|
||||
|
||||
return 'regular';
|
||||
}
|
||||
}
|
||||
234
Service/ModernSetting.php
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
use WenPai\ChinaYes\Service\TranslationManager;
|
||||
use WenPai\ChinaYes\Service\LazyTranslation;
|
||||
use WP_CHINA_YES;
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class ModernSetting {
|
||||
|
||||
private $settings;
|
||||
private $prefix = 'wp_china_yes';
|
||||
|
||||
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' ] );
|
||||
|
||||
// 延迟到 init 动作后执行
|
||||
add_action( 'init', [ $this, 'admin_init' ], 20 );
|
||||
}
|
||||
|
||||
public function admin_init() {
|
||||
// 确保翻译已加载
|
||||
if (!TranslationManager::isLoaded()) {
|
||||
TranslationManager::getInstance()->loadTranslations();
|
||||
}
|
||||
|
||||
$this->setupFramework();
|
||||
}
|
||||
|
||||
private function setupFramework() {
|
||||
$enabled_sections = $this->settings['enable_sections'] ?? [];
|
||||
|
||||
if (in_array('store', $enabled_sections)) {
|
||||
WP_CHINA_YES::createSection( $this->prefix, [
|
||||
'title' => $this->t('应用市场'),
|
||||
'icon' => 'icon icon-shop',
|
||||
'fields' => [
|
||||
[
|
||||
'id' => 'store',
|
||||
'type' => 'radio',
|
||||
'title' => $this->t('应用市场'),
|
||||
'inline' => true,
|
||||
'options' => [
|
||||
'wenpai' => $this->t('文派开源'),
|
||||
'proxy' => $this->t('官方镜像'),
|
||||
'off' => $this->t('不启用')
|
||||
],
|
||||
'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' => $this->t('萌芽加速'),
|
||||
'icon' => 'icon icon-flash-1',
|
||||
'fields' => [
|
||||
[
|
||||
'id' => 'admincdn_public',
|
||||
'type' => 'checkbox',
|
||||
'title' => $this->t('萌芽加速'),
|
||||
'inline' => true,
|
||||
'options' => [
|
||||
'googlefonts' => 'Google 字体',
|
||||
'googleajax' => 'Google 前端库',
|
||||
'cdnjs' => 'CDNJS 前端库',
|
||||
'jsdelivr' => 'jsDelivr 前端库',
|
||||
'bootstrapcdn' => 'Bootstrap 前端库',
|
||||
],
|
||||
'default' => [
|
||||
'googlefonts' => 'googlefonts',
|
||||
'googleajax' => 'googleajax',
|
||||
'cdnjs' => 'cdnjs',
|
||||
'jsdelivr' => 'jsdelivr',
|
||||
'bootstrapcdn' => 'bootstrapcdn',
|
||||
],
|
||||
'subtitle' => '是否启用前端公共库加速',
|
||||
'desc' => '启用后,将自动替换前端页面中的 Google Fonts、Google Ajax、CDNJS、jsDelivr、Bootstrap 等公共库为国内加速节点。',
|
||||
],
|
||||
[
|
||||
'id' => 'admincdn_files',
|
||||
'type' => 'checkbox',
|
||||
'title' => $this->t('文件加速'),
|
||||
'inline' => true,
|
||||
'options' => [
|
||||
'gravatar' => 'Gravatar 头像',
|
||||
'emoji' => 'Emoji 表情',
|
||||
'googlefonts' => 'Google 字体',
|
||||
],
|
||||
'default' => [
|
||||
'gravatar' => 'gravatar',
|
||||
'emoji' => 'emoji',
|
||||
'googlefonts' => 'googlefonts',
|
||||
],
|
||||
'subtitle' => '是否启用文件资源加速',
|
||||
'desc' => '启用后,将自动替换 Gravatar 头像、Emoji 表情、Google 字体等文件资源为国内加速节点。',
|
||||
],
|
||||
[
|
||||
'id' => 'admincdn_dev',
|
||||
'type' => 'checkbox',
|
||||
'title' => $this->t('开发加速'),
|
||||
'inline' => true,
|
||||
'options' => [
|
||||
'wordpress' => 'WordPress 官方',
|
||||
'themes' => '主题仓库',
|
||||
'plugins' => '插件仓库',
|
||||
],
|
||||
'default' => [
|
||||
'wordpress' => 'wordpress',
|
||||
'themes' => 'themes',
|
||||
'plugins' => 'plugins',
|
||||
],
|
||||
'subtitle' => '是否启用开发资源加速',
|
||||
'desc' => '启用后,将自动替换 WordPress 官方、主题仓库、插件仓库等开发资源为国内加速节点。',
|
||||
],
|
||||
],
|
||||
] );
|
||||
}
|
||||
|
||||
// 通知管理部分
|
||||
if (in_array('notice', $enabled_sections)) {
|
||||
WP_CHINA_YES::createSection( $this->prefix, [
|
||||
'title' => $this->t('通知管理'),
|
||||
'icon' => 'icon icon-bell',
|
||||
'fields' => [
|
||||
[
|
||||
'id' => 'notice_block',
|
||||
'type' => 'radio',
|
||||
'title' => $this->t('通知管理'),
|
||||
'inline' => true,
|
||||
'options' => [
|
||||
'on' => '启用',
|
||||
'off' => '不启用',
|
||||
],
|
||||
'default' => 'off',
|
||||
'subtitle' => '是否启用后台通知管理',
|
||||
'desc' => $this->t('管理和控制 WordPress 后台各类通知的显示。'),
|
||||
],
|
||||
[
|
||||
'id' => 'disable_all_notices',
|
||||
'type' => 'switcher',
|
||||
'title' => $this->t('禁用所有通知'),
|
||||
'subtitle' => '一键禁用所有后台通知',
|
||||
'default' => false,
|
||||
'dependency' => ['notice_block', '==', 'on'],
|
||||
],
|
||||
[
|
||||
'id' => 'notice_control',
|
||||
'type' => 'checkbox',
|
||||
'title' => $this->t('选择性禁用'),
|
||||
'inline' => true,
|
||||
'subtitle' => '选择需要禁用的通知类型',
|
||||
'desc' => $this->t('可以按住 Ctrl/Command 键进行多选'),
|
||||
'chosen' => true,
|
||||
'multiple' => true,
|
||||
'options' => [
|
||||
'update_nag' => '更新提醒',
|
||||
'plugin_update' => '插件更新',
|
||||
'theme_update' => '主题更新',
|
||||
'core_update' => '核心更新',
|
||||
'admin_notices' => '管理员通知',
|
||||
'user_admin_notices' => '用户管理通知',
|
||||
'network_admin_notices'=> '网络管理通知',
|
||||
],
|
||||
'dependency' => ['notice_block', '==', 'on'],
|
||||
],
|
||||
[
|
||||
'id' => 'notice_method',
|
||||
'type' => 'radio',
|
||||
'title' => $this->t('禁用方式'),
|
||||
'inline' => true,
|
||||
'options' => [
|
||||
'hide' => '隐藏通知',
|
||||
'remove' => '移除通知',
|
||||
],
|
||||
'default' => 'hide',
|
||||
'subtitle' => '选择通知的禁用方式',
|
||||
'desc' => '隐藏通知:通过 CSS 隐藏通知元素;移除通知:通过 PHP 移除通知钩子。',
|
||||
'dependency' => ['notice_block', '==', 'on'],
|
||||
],
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
private function t($text) {
|
||||
return TranslationManager::translate($text);
|
||||
}
|
||||
|
||||
public function admin_menu() {
|
||||
add_options_page(
|
||||
'WP-China-Yes',
|
||||
'WP-China-Yes',
|
||||
'manage_options',
|
||||
'wp-china-yes',
|
||||
[ $this, 'admin_page' ]
|
||||
);
|
||||
}
|
||||
|
||||
public function admin_page() {
|
||||
echo '<div class="wrap">';
|
||||
echo '<h1>WP-China-Yes 设置</h1>';
|
||||
echo '<p>现代化翻译系统已启用</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function enqueue_admin_assets() {
|
||||
// 管理员资源加载
|
||||
}
|
||||
}
|
||||
172
Service/Monitor.php
Executable file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Monitor
|
||||
* 插件监控服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Monitor {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_store' ); // TODO 下个版本移除
|
||||
wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_cravatar' ); // TODO 下个版本移除
|
||||
wp_clear_scheduled_hook( 'wp_china_yes_maybe_check_admincdn' ); // TODO 下个版本移除
|
||||
if ( $this->settings['monitor'] ) {
|
||||
// 站点网络下只在主站运行
|
||||
if ( is_main_site() ) {
|
||||
add_action( 'init', [ $this, 'init' ] );
|
||||
add_action( 'wp_china_yes_monitor', [
|
||||
$this,
|
||||
'run_monitor'
|
||||
] );
|
||||
}
|
||||
} else {
|
||||
wp_clear_scheduled_hook( 'wp_china_yes_monitor' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public function init() {
|
||||
if ( ! wp_next_scheduled( 'wp_china_yes_monitor' ) ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_china_yes_monitor' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行监控
|
||||
*/
|
||||
public function run_monitor() {
|
||||
if ( $this->settings['store'] != 'off' ) {
|
||||
$this->maybe_check_store();
|
||||
}
|
||||
if ( $this->settings['cravatar'] != 'off' ) {
|
||||
$this->maybe_check_cravatar();
|
||||
}
|
||||
if ( ! empty( $this->settings['admincdn'] ) ) {
|
||||
$this->maybe_check_admincdn();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查应用市场可用性
|
||||
*/
|
||||
public function maybe_check_store() {
|
||||
$test_url = 'https://api.wenpai.net/china-yes/version-check';
|
||||
if ( $this->settings['store'] == 'proxy' ) {
|
||||
$test_url = 'https://api.wpmirror.com/core/version-check/1.7/';
|
||||
}
|
||||
$response = wp_remote_get( $test_url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
if ( $this->settings['store'] == 'wenpai' ) {
|
||||
$this->settings['store'] = 'proxy';
|
||||
} elseif ( $this->settings['store'] == 'proxy' ) {
|
||||
$this->settings['store'] = 'off';
|
||||
}
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查初认头像可用性
|
||||
*/
|
||||
public function maybe_check_cravatar() {
|
||||
$test_url = 'https://cn.cravatar.com/avatar/';
|
||||
switch ( $this->settings['cravatar'] ) {
|
||||
case 'global':
|
||||
$test_url = 'https://en.cravatar.com/avatar/';
|
||||
break;
|
||||
case 'weavatar':
|
||||
$test_url = 'https://weavatar.com/avatar/';
|
||||
break;
|
||||
}
|
||||
$response = wp_remote_get( $test_url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
if ( $this->settings['cravatar'] == 'cn' ) {
|
||||
$this->settings['cravatar'] = 'global';
|
||||
} elseif ( $this->settings['cravatar'] == 'global' ) {
|
||||
$this->settings['cravatar'] = 'weavatar';
|
||||
} elseif ( $this->settings['cravatar'] == 'weavatar' ) {
|
||||
$this->settings['cravatar'] = 'cn';
|
||||
}
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查萌芽加速可用性
|
||||
*/
|
||||
public function maybe_check_admincdn() {
|
||||
// 后台加速
|
||||
if ( in_array( 'admin', $this->settings['admincdn'] ) ) {
|
||||
$response = wp_remote_get( 'https://wpstatic.admincdn.com/6.7/wp-includes/js/wp-sanitize.min.js' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'admin' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// 前台加速
|
||||
if ( in_array( 'frontend', $this->settings['admincdn'] ) ) {
|
||||
$url = network_site_url( '/wp-includes/js/wp-sanitize.min.js' );
|
||||
$response = wp_remote_get( 'https://public.admincdn.com/' . $url );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'frontend' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// Google 字体
|
||||
if ( in_array( 'googlefonts', $this->settings['admincdn'] ) ) {
|
||||
$response = wp_remote_get( 'https://googlefonts.admincdn.com/css?family=Roboto:400,700' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googlefonts' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// Google 前端公共库
|
||||
if ( in_array( 'googleajax', $this->settings['admincdn'] ) ) {
|
||||
$response = wp_remote_get( 'https://googleajax.admincdn.com/ajax/libs/jquery/3.7.1/jquery.slim.min.js' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'googleajax' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// CDNJS 前端公共库
|
||||
if ( in_array( 'cdnjs', $this->settings['admincdn'] ) ) {
|
||||
$response = wp_remote_get( 'https://cdnjs.admincdn.com/jquery/3.7.1/jquery.slim.min.js' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'cdnjs' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
// jsDelivr 公共库
|
||||
if ( in_array( 'jsdelivr', $this->settings['admincdn'] ) ) {
|
||||
$response = wp_remote_get( 'https://jsd.admincdn.com/npm/jquery@3.7.1/dist/jquery.slim.min.js' );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
|
||||
$this->settings['admincdn'] = array_values( array_diff( $this->settings['admincdn'], [ 'jsdelivr' ] ) );
|
||||
$this->update_settings();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新设置
|
||||
*/
|
||||
private function update_settings() {
|
||||
if ( is_multisite() ) {
|
||||
update_site_option( 'wp_china_yes', $this->settings );
|
||||
} else {
|
||||
update_option( 'wp_china_yes', $this->settings, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
94
Service/Performance.php
Executable file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
class Performance {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
$this->init();
|
||||
}
|
||||
|
||||
private function init() {
|
||||
add_action('init', [$this, 'optimize_wordpress']);
|
||||
add_action('wp_enqueue_scripts', [$this, 'optimize_scripts'], 999);
|
||||
add_action('wp_head', [$this, 'add_performance_hints'], 1);
|
||||
|
||||
if (is_admin()) {
|
||||
add_action('admin_init', [$this, 'optimize_admin']);
|
||||
}
|
||||
}
|
||||
|
||||
public function optimize_wordpress() {
|
||||
remove_action('wp_head', 'wp_generator');
|
||||
remove_action('wp_head', 'wlwmanifest_link');
|
||||
remove_action('wp_head', 'rsd_link');
|
||||
remove_action('wp_head', 'wp_shortlink_wp_head');
|
||||
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
|
||||
|
||||
if (!is_admin()) {
|
||||
wp_deregister_script('jquery-migrate');
|
||||
}
|
||||
|
||||
add_filter('xmlrpc_enabled', '__return_false');
|
||||
|
||||
add_filter('wp_headers', function($headers) {
|
||||
if (isset($headers['X-Pingback'])) {
|
||||
unset($headers['X-Pingback']);
|
||||
}
|
||||
return $headers;
|
||||
});
|
||||
|
||||
add_filter('emoji_svg_url', '__return_false');
|
||||
|
||||
if (!empty($this->settings['disable_embeds'])) {
|
||||
wp_deregister_script('wp-embed');
|
||||
}
|
||||
}
|
||||
|
||||
public function optimize_scripts() {
|
||||
if (!is_admin() && !empty($this->settings['defer_scripts'])) {
|
||||
add_filter('script_loader_tag', function($tag, $handle) {
|
||||
if (is_admin() || strpos($tag, 'defer') !== false) {
|
||||
return $tag;
|
||||
}
|
||||
|
||||
$defer_scripts = ['jquery', 'wp-embed'];
|
||||
if (in_array($handle, $defer_scripts)) {
|
||||
return str_replace(' src', ' defer src', $tag);
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}, 10, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_performance_hints() {
|
||||
echo '<link rel="dns-prefetch" href="//admincdn.com">' . "\n";
|
||||
echo '<link rel="dns-prefetch" href="//cn.cravatar.com">' . "\n";
|
||||
echo '<link rel="dns-prefetch" href="//wenpai.org">' . "\n";
|
||||
echo '<link rel="preconnect" href="https://admincdn.com" crossorigin>' . "\n";
|
||||
}
|
||||
|
||||
public function optimize_admin() {
|
||||
add_filter('heartbeat_settings', function($settings) {
|
||||
$settings['interval'] = 60;
|
||||
return $settings;
|
||||
});
|
||||
|
||||
if (!empty($this->settings['disable_admin_bar']) && !current_user_can('manage_options')) {
|
||||
show_admin_bar(false);
|
||||
}
|
||||
|
||||
add_action('admin_enqueue_scripts', function() {
|
||||
wp_dequeue_script('thickbox');
|
||||
wp_dequeue_style('thickbox');
|
||||
});
|
||||
}
|
||||
}
|
||||
1592
Service/Setting.php
Executable file
169
Service/Super.php
Executable file
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use WP_Error;
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
use WenPai\ChinaYes\Service\Widget;
|
||||
use WenPai\ChinaYes\Service\Language;
|
||||
use WenPai\ChinaYes\Service\Migration;
|
||||
use WenPai\ChinaYes\Service\Fonts;
|
||||
use WenPai\ChinaYes\Service\Comments;
|
||||
|
||||
class Super {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
|
||||
if ( is_admin() || wp_doing_cron() ) {
|
||||
if ( $this->settings['store'] != 'off' ) {
|
||||
add_filter( 'pre_http_request', [ $this, 'filter_wordpress_org' ], 100, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
new Widget();
|
||||
new Language();
|
||||
new Migration();
|
||||
new Fonts();
|
||||
new Comments();
|
||||
|
||||
if ( ! empty( $this->settings['cravatar'] ) ) {
|
||||
add_filter( 'user_profile_picture_description', [ $this, 'set_user_profile_picture_for_cravatar' ], 1 );
|
||||
add_filter( 'avatar_defaults', [ $this, 'set_defaults_for_cravatar' ], 1 );
|
||||
add_filter( 'um_user_avatar_url_filter', [ $this, 'get_cravatar_url' ], 1 );
|
||||
add_filter( 'bp_gravatar_url', [ $this, 'get_cravatar_url' ], 1 );
|
||||
add_filter( 'get_avatar_url', [ $this, 'get_cravatar_url' ], 1 );
|
||||
}
|
||||
|
||||
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
if ( ! empty( $this->settings['adblock'] ) && $this->settings['adblock'] == 'on' ) {
|
||||
add_action( 'admin_head', [ $this, 'load_adblock' ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
||||
if ( ! empty( $this->settings['notice_block'] ) && $this->settings['notice_block'] == 'on' ) {
|
||||
add_action( 'admin_head', [ $this, 'load_notice_management' ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $this->settings['plane'] ) && $this->settings['plane'] == 'on' ) {
|
||||
$this->load_plane();
|
||||
}
|
||||
}
|
||||
|
||||
public function load_adblock() {
|
||||
if (empty($this->settings['adblock']) || $this->settings['adblock'] !== 'on') {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( (array) $this->settings['adblock_rule'] as $rule ) {
|
||||
if ( empty( $rule['enable'] ) || empty( $rule['selector'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo sprintf( '<style>%s { display: none !important; }</style>', esc_html( $rule['selector'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
public function load_notice_management() {
|
||||
echo '<style>
|
||||
.notice, .update-nag, .updated, .error, .is-dismissible {
|
||||
display: none !important;
|
||||
}
|
||||
</style>';
|
||||
}
|
||||
|
||||
public function load_plane() {
|
||||
foreach ( (array) $this->settings['plane_rule'] as $rule ) {
|
||||
if ( empty( $rule['enable'] ) || empty( $rule['domain'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_filter( 'pre_http_request', function ( $preempt, $parsed_args, $url ) use ( $rule ) {
|
||||
$host = wp_parse_url( $url, PHP_URL_HOST );
|
||||
if ( strpos( $host, $rule['domain'] ) !== false ) {
|
||||
return new WP_Error( 'http_request_failed', 'Blocked by plane mode' );
|
||||
}
|
||||
return $preempt;
|
||||
}, 10, 3 );
|
||||
}
|
||||
}
|
||||
|
||||
public function filter_wordpress_org( $preempt, $parsed_args, $url ) {
|
||||
$host = wp_parse_url( $url, PHP_URL_HOST );
|
||||
|
||||
if ( ! in_array( $host, [ 'api.wordpress.org', 'downloads.wordpress.org' ] ) ) {
|
||||
return $preempt;
|
||||
}
|
||||
|
||||
$path = wp_parse_url( $url, PHP_URL_PATH );
|
||||
$query = wp_parse_url( $url, PHP_URL_QUERY );
|
||||
|
||||
if ( $this->settings['store'] == 'cn' ) {
|
||||
$mirror_url = 'https://api.wenpai.net' . $path;
|
||||
} else {
|
||||
$mirror_url = 'https://api.wenpai.net' . $path;
|
||||
}
|
||||
|
||||
if ( $query ) {
|
||||
$mirror_url .= '?' . $query;
|
||||
}
|
||||
|
||||
$parsed_args['timeout'] = 30;
|
||||
return wp_remote_request( $mirror_url, $parsed_args );
|
||||
}
|
||||
|
||||
public function set_user_profile_picture_for_cravatar( $description ) {
|
||||
return str_replace( 'Gravatar', 'Cravatar', $description );
|
||||
}
|
||||
|
||||
public function set_defaults_for_cravatar( $avatar_defaults ) {
|
||||
$avatar_defaults['cravatar'] = 'Cravatar Logo (Generated)';
|
||||
return $avatar_defaults;
|
||||
}
|
||||
|
||||
public function get_cravatar_url( $url ) {
|
||||
$sources = [
|
||||
'www.gravatar.com' => 'cn.cravatar.com',
|
||||
'0.gravatar.com' => 'cn.cravatar.com',
|
||||
'1.gravatar.com' => 'cn.cravatar.com',
|
||||
'2.gravatar.com' => 'cn.cravatar.com',
|
||||
'secure.gravatar.com' => 'cn.cravatar.com',
|
||||
'cn.gravatar.com' => 'cn.cravatar.com',
|
||||
'gravatar.com' => 'cn.cravatar.com',
|
||||
];
|
||||
|
||||
if ( $this->settings['cravatar'] == 'global' ) {
|
||||
$sources = [
|
||||
'www.gravatar.com' => 'www.gravatar.com',
|
||||
'0.gravatar.com' => 'www.gravatar.com',
|
||||
'1.gravatar.com' => 'www.gravatar.com',
|
||||
'2.gravatar.com' => 'www.gravatar.com',
|
||||
'secure.gravatar.com' => 'www.gravatar.com',
|
||||
'cn.gravatar.com' => 'www.gravatar.com',
|
||||
'gravatar.com' => 'www.gravatar.com',
|
||||
];
|
||||
}
|
||||
|
||||
return str_replace( array_keys( $sources ), array_values( $sources ), $url );
|
||||
}
|
||||
|
||||
public function page_str_replace( $hook, $function, $args ) {
|
||||
add_action( $hook, function () use ( $function, $args ) {
|
||||
ob_start( function ( $buffer ) use ( $function, $args ) {
|
||||
return call_user_func_array( $function, array_merge( [ $args[0], $args[1], $buffer ] ) );
|
||||
} );
|
||||
}, 1 );
|
||||
|
||||
add_action( 'wp_footer', function () {
|
||||
if ( ob_get_level() ) {
|
||||
ob_end_flush();
|
||||
}
|
||||
}, 999 );
|
||||
}
|
||||
}
|
||||
140
Service/TranslationManager.php
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
class TranslationManager {
|
||||
|
||||
private static $instance = null;
|
||||
private static $loaded = false;
|
||||
private static $translations = [];
|
||||
private static $fallbacks = [];
|
||||
|
||||
public static function getInstance() {
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
add_action('init', [$this, 'loadTranslations'], 1);
|
||||
add_action('plugins_loaded', [$this, 'registerFallbacks'], 999);
|
||||
}
|
||||
|
||||
public function loadTranslations() {
|
||||
if (!self::$loaded) {
|
||||
$domain = 'wp-china-yes';
|
||||
$locale = determine_locale();
|
||||
$mofile = CHINA_YES_PLUGIN_PATH . 'languages/' . $domain . '-' . $locale . '.mo';
|
||||
|
||||
if (file_exists($mofile)) {
|
||||
load_textdomain($domain, $mofile);
|
||||
} else {
|
||||
load_plugin_textdomain($domain, false, dirname(plugin_basename(CHINA_YES_PLUGIN_FILE)) . '/languages');
|
||||
}
|
||||
|
||||
self::$loaded = true;
|
||||
do_action('wp_china_yes_translations_loaded');
|
||||
}
|
||||
}
|
||||
|
||||
public function registerFallbacks() {
|
||||
self::$fallbacks = [
|
||||
'应用市场' => '应用市场',
|
||||
'萌芽加速' => '萌芽加速',
|
||||
'文件加速' => '文件加速',
|
||||
'开发加速' => '开发加速',
|
||||
'初认头像' => '初认头像',
|
||||
'文风字体' => '文风字体',
|
||||
'字体家族' => '字体家族',
|
||||
'字体链接' => '字体链接',
|
||||
'字体字重' => '字体字重',
|
||||
'字体样式' => '字体样式',
|
||||
'字体应用' => '字体应用',
|
||||
'启用字体' => '启用字体',
|
||||
'排印优化' => '排印优化',
|
||||
'英文美化' => '英文美化',
|
||||
'墨图云集' => '墨图云集',
|
||||
'飞秒邮箱' => '飞秒邮箱',
|
||||
'无言会语' => '无言会语',
|
||||
'笔笙区块' => '笔笙区块',
|
||||
'灯鹿用户' => '灯鹿用户',
|
||||
'Woo电商' => 'Woo电商',
|
||||
'乐尔达思' => '乐尔达思',
|
||||
'瓦普文创' => '瓦普文创',
|
||||
'广告拦截' => '广告拦截',
|
||||
'规则名称' => '规则名称',
|
||||
'应用元素' => '应用元素',
|
||||
'启用规则' => '启用规则',
|
||||
'通知管理' => '通知管理',
|
||||
'管理和控制 WordPress 后台各类通知的显示。' => '管理和控制 WordPress 后台各类通知的显示。',
|
||||
'禁用所有通知' => '禁用所有通知',
|
||||
'选择性禁用' => '选择性禁用',
|
||||
'可以按住 Ctrl/Command 键进行多选' => '可以按住 Ctrl/Command 键进行多选',
|
||||
'禁用方式' => '禁用方式',
|
||||
'飞行模式' => '飞行模式',
|
||||
'URL' => 'URL',
|
||||
'显示参数' => '显示参数',
|
||||
'为网站维护人员提供参考依据,无需登录服务器即可查看相关信息参数' => '为网站维护人员提供参考依据,无需登录服务器即可查看相关信息参数',
|
||||
'为网站管理人员提供参考依据,进入后台仪表盘即可查看相关信息参数' => '为网站管理人员提供参考依据,进入后台仪表盘即可查看相关信息参数',
|
||||
'启用后,网站将显示维护页面,只有管理员可以访问。' => '启用后,网站将显示维护页面,只有管理员可以访问。',
|
||||
'雨滴安全' => '雨滴安全',
|
||||
'禁用文件编辑' => '禁用文件编辑',
|
||||
'启用后,用户无法通过 WordPress 后台编辑主题和插件文件。' => '启用后,用户无法通过 WordPress 后台编辑主题和插件文件。',
|
||||
'禁用文件修改' => '禁用文件修改',
|
||||
'启用后,用户无法通过 WordPress 后台安装、更新或删除主题和插件。' => '启用后,用户无法通过 WordPress 后台安装、更新或删除主题和插件。',
|
||||
'性能优化' => '性能优化',
|
||||
'性能优化设置可以帮助提升 WordPress 的运行效率,请根据服务器配置合理调整。' => '性能优化设置可以帮助提升 WordPress 的运行效率,请根据服务器配置合理调整。',
|
||||
'内存限制' => '内存限制',
|
||||
'设置 WordPress 的内存限制,例如 64M、128M、256M 等。' => '设置 WordPress 的内存限制,例如 64M、128M、256M 等。',
|
||||
'后台内存限制' => '后台内存限制',
|
||||
'设置 WordPress 后台的内存限制,例如 128M、256M、512M 等。' => '设置 WordPress 后台的内存限制,例如 128M、256M、512M 等。',
|
||||
'文章修订版本' => '文章修订版本',
|
||||
'设置为 0 禁用修订版本,或设置为一个固定值(如 5)限制修订版本数量。' => '设置为 0 禁用修订版本,或设置为一个固定值(如 5)限制修订版本数量。',
|
||||
'自动保存间隔' => '自动保存间隔',
|
||||
'设置文章自动保存的时间间隔,默认是 60 秒。' => '设置文章自动保存的时间间隔,默认是 60 秒。',
|
||||
'专为 WordPress 建站服务商和代理机构提供的自定义品牌 OEM 功能,输入您的品牌词启用后生效' => '专为 WordPress 建站服务商和代理机构提供的自定义品牌 OEM 功能,输入您的品牌词启用后生效',
|
||||
'注意:启用[隐藏菜单]前请务必保存或收藏当前设置页面 URL,否则将无法再次进入插件页面' => '注意:启用[隐藏菜单]前请务必保存或收藏当前设置页面 URL,否则将无法再次进入插件页面',
|
||||
'调试模式' => '调试模式',
|
||||
'启用后,WordPress 将显示 PHP 错误、警告和通知。临时使用完毕后,请保持禁用此选项。' => '启用后,WordPress 将显示 PHP 错误、警告和通知。临时使用完毕后,请保持禁用此选项。',
|
||||
'调试选项' => '调试选项',
|
||||
'注意:调试模式仅适用于开发和测试环境,不建议在生产环境中长时间启用。选择要启用的调试功能,适用于开发和测试环境。' => '注意:调试模式仅适用于开发和测试环境,不建议在生产环境中长时间启用。选择要启用的调试功能,适用于开发和测试环境。',
|
||||
'数据库工具' => '数据库工具',
|
||||
'启用后,您可以在下方访问数据库修复工具。定期使用完毕后,请保持禁用此选项。' => '启用后,您可以在下方访问数据库修复工具。定期使用完毕后,请保持禁用此选项。',
|
||||
'数据库修复工具' => '数据库修复工具',
|
||||
'打开数据库修复工具' => '打开数据库修复工具',
|
||||
'启用后,您可以在下方选用文派叶子功能,特别提醒:禁用对应功能后再次启用需重新设置。' => '启用后,您可以在下方选用文派叶子功能,特别提醒:禁用对应功能后再次启用需重新设置。',
|
||||
'帮助文档' => '帮助文档',
|
||||
'文派开源' => '文派开源',
|
||||
'官方镜像' => '官方镜像',
|
||||
'不启用' => '不启用'
|
||||
];
|
||||
}
|
||||
|
||||
public static function translate($text, $domain = 'wp-china-yes') {
|
||||
if (!self::$loaded) {
|
||||
return isset(self::$fallbacks[$text]) ? self::$fallbacks[$text] : $text;
|
||||
}
|
||||
|
||||
if (function_exists('__')) {
|
||||
$translated = __($text, $domain);
|
||||
return $translated !== $text ? $translated : (isset(self::$fallbacks[$text]) ? self::$fallbacks[$text] : $text);
|
||||
}
|
||||
|
||||
return isset(self::$fallbacks[$text]) ? self::$fallbacks[$text] : $text;
|
||||
}
|
||||
|
||||
public static function translateLazy($text, $domain = 'wp-china-yes') {
|
||||
return function() use ($text, $domain) {
|
||||
return self::translate($text, $domain);
|
||||
};
|
||||
}
|
||||
|
||||
public static function isLoaded() {
|
||||
return self::$loaded;
|
||||
}
|
||||
|
||||
public static function getFallback($text) {
|
||||
return isset(self::$fallbacks[$text]) ? self::$fallbacks[$text] : $text;
|
||||
}
|
||||
}
|
||||
23
Service/Update.php
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||
|
||||
/**
|
||||
* Class Update
|
||||
* 插件更新服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Update {
|
||||
|
||||
public function __construct() {
|
||||
PucFactory::buildUpdateChecker(
|
||||
'https://api.wenpai.net/china-yes/version-check',
|
||||
CHINA_YES_PLUGIN_FILE,
|
||||
'wp-china-yes'
|
||||
);
|
||||
}
|
||||
}
|
||||
181
Service/Widget.php
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
namespace WenPai\ChinaYes\Service;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use function WenPai\ChinaYes\get_settings;
|
||||
|
||||
/**
|
||||
* Class Widget
|
||||
* 小组件服务
|
||||
* @package WenPai\ChinaYes\Service
|
||||
*/
|
||||
class Widget {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct() {
|
||||
$this->settings = get_settings();
|
||||
|
||||
/**
|
||||
* 添加「文派茶馆」小组件
|
||||
*/
|
||||
if ( is_admin() ) {
|
||||
add_action( 'wp_dashboard_setup', [ $this, 'setup_wenpai_tea_widget' ] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置文派茶馆小组件
|
||||
*/
|
||||
public function setup_wenpai_tea_widget() {
|
||||
global $wp_meta_boxes;
|
||||
|
||||
unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] );
|
||||
wp_add_dashboard_widget( 'wenpai_tea', '文派茶馆', [ $this, 'render_wenpai_tea_widget' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染文派茶馆小组件
|
||||
*/
|
||||
public function render_wenpai_tea_widget() {
|
||||
$default_rss_url = 'https://wptea.com/feed/';
|
||||
$custom_rss_url = $this->settings['custom_rss_url'] ?? '';
|
||||
$refresh_interval = $this->settings['custom_rss_refresh'] ?? 14400;
|
||||
|
||||
$rss_display_options = $this->settings['rss_display_options'] ?? ['show_date', 'show_summary', 'show_footer'];
|
||||
if (!is_array($rss_display_options)) {
|
||||
$rss_display_options = explode(',', $rss_display_options);
|
||||
}
|
||||
|
||||
// 获取默认的 RSS 源内容
|
||||
$default_rss = fetch_feed($default_rss_url);
|
||||
$default_items = [];
|
||||
if (!is_wp_error($default_rss)) {
|
||||
$default_items = $default_rss->get_items(0, 5);
|
||||
}
|
||||
|
||||
$custom_items = [];
|
||||
$custom_rss = null;
|
||||
$custom_rss_latest_date = 0;
|
||||
|
||||
if (!empty($custom_rss_url)) {
|
||||
$transient_key = 'wenpai_tea_custom_rss_' . md5($custom_rss_url);
|
||||
$cached_custom_items = get_transient($transient_key);
|
||||
|
||||
if (false === $cached_custom_items) {
|
||||
$custom_rss = fetch_feed($custom_rss_url);
|
||||
if (!is_wp_error($custom_rss)) {
|
||||
$custom_items = $custom_rss->get_items(0, 2);
|
||||
if (!empty($custom_items)) {
|
||||
$custom_rss_latest_date = $custom_items[0]->get_date('U');
|
||||
}
|
||||
|
||||
set_transient($transient_key, $custom_items, $refresh_interval);
|
||||
}
|
||||
} else {
|
||||
$custom_items = $cached_custom_items;
|
||||
if (!empty($custom_items)) {
|
||||
$custom_rss_latest_date = $custom_items[0]->get_date('U');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$three_days_ago = time() - (3 * 24 * 60 * 60);
|
||||
if ($custom_rss_latest_date > $three_days_ago) {
|
||||
$items = array_merge(array_slice($default_items, 0, 3), $custom_items);
|
||||
} else {
|
||||
$items = array_slice($default_items, 0, 5);
|
||||
}
|
||||
|
||||
if (is_wp_error($custom_rss)) {
|
||||
$items = array_slice($default_items, 0, 5);
|
||||
}
|
||||
|
||||
echo <<<HTML
|
||||
<div class="wordpress-news hide-if-no-js">
|
||||
<div class="rss-widget">
|
||||
HTML;
|
||||
foreach ($items as $item) {
|
||||
echo '<div class="rss-item">';
|
||||
echo '<a href="' . esc_url($item->get_permalink()) . '" target="_blank">' . esc_html($item->get_title()) . '</a>';
|
||||
if (in_array('show_date', $rss_display_options)) {
|
||||
echo '<span class="rss-date">' . esc_html($item->get_date('Y.m.d')) . '</span>';
|
||||
}
|
||||
if (in_array('show_summary', $rss_display_options)) {
|
||||
echo '<div class="rss-summary">' . esc_html(wp_trim_words($item->get_description(), 45, '...')) . '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo <<<HTML
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
if (in_array('show_footer', $rss_display_options)) {
|
||||
echo <<<HTML
|
||||
<p class="community-events-footer">
|
||||
<a href="https://wenpai.org/" target="_blank">文派开源</a>
|
||||
|
|
||||
<a href="https://wenpai.org/support" target="_blank">支持论坛</a>
|
||||
|
|
||||
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
|
||||
|
|
||||
<a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a>
|
||||
</p>
|
||||
HTML;
|
||||
}
|
||||
echo <<<HTML
|
||||
<style>
|
||||
#wenpai_tea .rss-widget {
|
||||
padding: 0 12px;
|
||||
}
|
||||
#wenpai_tea .rss-widget:last-child {
|
||||
border-bottom: none;
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
#wenpai_tea .rss-item {
|
||||
margin-bottom: 10px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
#wenpai_tea .rss-item:last-child {
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
#wenpai_tea .rss-item a {
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#wenpai_tea .rss-date {
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
#wenpai_tea .rss-summary {
|
||||
color: #444;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
#wenpai_tea .community-events-footer {
|
||||
margin-top: 15px;
|
||||
padding-top: 15px;
|
||||
padding-bottom: 5px;
|
||||
border-top: 1px solid #eee;
|
||||
text-align: center;
|
||||
}
|
||||
#wenpai_tea .community-events-footer a {
|
||||
text-decoration: none;
|
||||
margin: 0 5px;
|
||||
}
|
||||
#wenpai_tea .community-events-footer a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
7
assets/css/fonts.css
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
html {
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
|
||||
font-family: -apple-system, "Noto Sans", "Helvetica Neue", Helvetica, "Nimbus Sans L", Arial, "Liberation Sans", "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Source Han Sans SC", "Source Han Sans CN", "Microsoft YaHei", "Wenquanyi Micro Hei", "WenQuanYi Zen Hei", "ST Heiti", SimHei, "WenQuanYi Zen Hei Sharp", sans-serif;
|
||||
}
|
||||
621
assets/css/setting.css
Executable file
|
|
@ -0,0 +1,621 @@
|
|||
#wpcontent {
|
||||
padding-left: 0px;
|
||||
}
|
||||
#wpbody-content {
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
#wpfooter {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
@media only screen and (max-width: 1200px) {
|
||||
.wp_china_yes-nav-normal {
|
||||
width: 200px;
|
||||
}
|
||||
.wp_china_yes-nav-normal+.wp_china_yes-content {
|
||||
margin-left: 200px;
|
||||
}
|
||||
.wp_china_yes-nav-background {
|
||||
width: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 960px) {
|
||||
.wp_china_yes-field .wp_china_yes-title {
|
||||
width: 30%;
|
||||
}
|
||||
.wp_china_yes-field .wp_china_yes-fieldset {
|
||||
width: calc(70% - 20px);
|
||||
}
|
||||
.wpcy-about__grid.columns-3 {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 782px) {
|
||||
.wp_china_yes-nav-normal+.wp_china_yes-content {
|
||||
margin-left: 0!important;
|
||||
}
|
||||
.wp_china_yes-nav-normal {
|
||||
position: fixed;
|
||||
top: 32px;
|
||||
left: -250px;
|
||||
height: 100vh;
|
||||
z-index: 9999;
|
||||
transition: left 0.3s ease;
|
||||
background: #fff;
|
||||
box-shadow: 2px 0 5px rgba(0,0,0,0.1);
|
||||
}
|
||||
.wp_china_yes-nav-normal.mobile-open {
|
||||
left: 0;
|
||||
}
|
||||
.wp_china_yes-header-inner {
|
||||
position: relative;
|
||||
padding: 15px 20px;
|
||||
}
|
||||
.wp_china_yes-header-inner h1 {
|
||||
margin-bottom: 10px;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
.auto-fold #wpcontent {
|
||||
padding-left: 0px;
|
||||
}
|
||||
.wp_china_yes-field-text input,
|
||||
.wp_china_yes-field-textarea textarea,
|
||||
.wp_china_yes-field-select select {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
.wp_china_yes-field .wp_china_yes-title {
|
||||
width: 100%;
|
||||
float: none;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.wp_china_yes-field .wp_china_yes-fieldset {
|
||||
width: 100%;
|
||||
float: none;
|
||||
}
|
||||
.wp_china_yes-field {
|
||||
padding: 20px;
|
||||
}
|
||||
.wp_china_yes-section {
|
||||
margin: 20px auto;
|
||||
}
|
||||
}
|
||||
|
||||
.wp-core-ui .button, .wp-core-ui .button-primary, .wp-core-ui .button-secondary {
|
||||
border-radius: 1px;
|
||||
}
|
||||
|
||||
.sponsor-logos {
|
||||
display: block;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
margin: 24px 0;
|
||||
grid-gap: 24px;
|
||||
grid-template-columns: repeat(7, minmax(0, 1fr));
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sponsor-logos img {
|
||||
flex-basis: calc(20% - 10px);
|
||||
max-width: 80px;
|
||||
margin: 13px;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.contributors-name {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
padding: 20px 0;
|
||||
color: #dcdcde;
|
||||
display: block;
|
||||
flex-wrap: wrap;
|
||||
display: flex;
|
||||
grid-gap: 22px;
|
||||
}
|
||||
|
||||
.wp_china_yes-content {
|
||||
position: relative;
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
.wp_china_yes-content a {
|
||||
color: #3858e9;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.wp_china_yes-content a:active, a:focus, a:hover {
|
||||
color: #2c3338;
|
||||
}
|
||||
|
||||
.wp_china_yes-options {
|
||||
background-color: #ffffff;
|
||||
border-radius: 10px;
|
||||
text-transform: none;
|
||||
line-height: 2;
|
||||
}
|
||||
|
||||
.wp_china_yes-options {
|
||||
margin-top: 0px;
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field {
|
||||
padding: 8%;
|
||||
background-color: #ffffff;
|
||||
margin: 5% 0;
|
||||
border-radius: 1px;
|
||||
box-shadow: 0 0 0 1px #ccd0d4, 0 1px 1px 1px rgba(0, 0, 0, .04);
|
||||
}
|
||||
|
||||
.wp_china_yes-field.wp_china_yes-field-content {
|
||||
padding: 0;
|
||||
background-color: rgba(255, 255, 255, 0);
|
||||
margin: 0;
|
||||
border-radius: 0;
|
||||
box-shadow: unset;
|
||||
}
|
||||
.wp_china_yes-field-checkbox .wp_china_yes--inline-list li, .wp_china_yes-field-radio .wp_china_yes--inline-list li {
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.wp_china_yes-copyright p {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
.wp_china_yes-copyright {
|
||||
float: left;
|
||||
margin-top: 25px;
|
||||
margin-bottom: 35px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
font-size: 12px;
|
||||
zoom: 90%;
|
||||
|
||||
}
|
||||
|
||||
.wp_china_yes-section {
|
||||
margin: 50px auto;
|
||||
max-width: 1000px;
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
.wp_china_yes-field {
|
||||
position: relative;
|
||||
border: 0px solid #ccd0d4;
|
||||
}
|
||||
|
||||
.wp_china_yes-field+.wp_china_yes-field {
|
||||
border-top: 0px solid #eee;
|
||||
}
|
||||
.wp_china_yes-field-fieldset .wp_china_yes-fieldset-content {
|
||||
border: 0px solid #ccd0d4;
|
||||
}
|
||||
|
||||
.wp_china_yes-section-title {
|
||||
padding: 20px 30px;
|
||||
background-color: #fff;
|
||||
border-top: 0 solid #f5f5f5;
|
||||
border-bottom: 0px solid #eee;
|
||||
box-shadow: 0 0 0 1px #ccd0d4, 0 1px 1px 1px rgba(0, 0, 0, .04);
|
||||
}
|
||||
|
||||
.wp_china_yes-section-title h3 {
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.wp_china_yes-section-title .wp_china_yes-section-icon {
|
||||
margin-right: 10px;
|
||||
width: 20px;
|
||||
height: 24px;
|
||||
line-height: 20px;
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-subheading {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.wp_china_yes-theme-light .wp_china_yes-container {
|
||||
border: 0 solid #ccd0d4;
|
||||
}
|
||||
|
||||
.wp_china_yes-theme-light .wp_china_yes-header-inner {
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
|
||||
.wp_china_yes-theme-light .wp_china_yes-nav-background {
|
||||
background-color: #ffffff;
|
||||
border-right: 1px solid #dddddd;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.wp_china_yes-theme-light .wp_china_yes-footer {
|
||||
border-top: 1px solid #fff;
|
||||
background: #ffffff;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-heading {
|
||||
font-size: 1.4em;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.wp_china_yes-nav-normal {
|
||||
width: 205px;
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.wp_china_yes-nav {
|
||||
padding: 20px;
|
||||
}
|
||||
.wp_china_yes-nav-background {
|
||||
width: 250px;
|
||||
}
|
||||
.wp_china_yes-nav ul li a {
|
||||
font-size: 13px;
|
||||
position: relative;
|
||||
display: block;
|
||||
padding: 10px 15px;
|
||||
margin: 5px;
|
||||
text-decoration: none;
|
||||
transition-property: color, background;
|
||||
transition-duration: .2s;
|
||||
transition-timing-function: ease;
|
||||
}
|
||||
|
||||
.wp_china_yes-nav .wp_china_yes-tab-icon {
|
||||
margin-right: 10px;
|
||||
width: 20px;
|
||||
height: 24px;
|
||||
line-height: 20px;
|
||||
font-size: 20px;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.wp_china_yes-theme-light .wp_china_yes-nav ul li a {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.wp_china_yes-theme-light .wp_china_yes-nav ul li a:hover {
|
||||
color: #3858e9;
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
.wp_china_yes-submessage-normal {
|
||||
border-color: #ffffff;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
|
||||
.wp_china_yes-nav-normal+.wp_china_yes-content {
|
||||
margin-left: 248px;
|
||||
}
|
||||
|
||||
.wp_china_yes-search-all .wp_china_yes-content, .wp_china_yes-show-all .wp_china_yes-content {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.wp_china_yes-theme-light .wp_china_yes-nav-normal > ul li a {
|
||||
border-bottom: 0px solid #f5f5f5;
|
||||
border-right: 0px solid #f5f5f5;
|
||||
}
|
||||
.wp_china_yes-theme-light .wp_china_yes-nav ul li .wp_china_yes-active {
|
||||
color: #111;
|
||||
background-color: #f5f5f7;
|
||||
background: #f5f5f7;
|
||||
}
|
||||
.wp_china_yes-field-group .wp_china_yes-cloneable-header-icon {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-group .wp_china_yes-cloneable-title {
|
||||
padding: 10px 65px 10px 10px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-group .ui-accordion .wp_china_yes-cloneable-item {
|
||||
padding: 2px 0;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-group .wp_china_yes-cloneable-helper {
|
||||
top: 15px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-group .wp_china_yes-cloneable-title {
|
||||
border: 1px solid #ccd0d4;
|
||||
background-color: #ffffff;
|
||||
border-radius: 1px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-group .wp_china_yes-cloneable-content {
|
||||
padding: 0;
|
||||
border-top: 1px solid #ffffff;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-group .wp_china_yes-cloneable-content>.wp_china_yes-field {
|
||||
padding: 15px;
|
||||
margin: 20px;
|
||||
}
|
||||
|
||||
.wp_china_yes-sticky .wp_china_yes-header-inner {
|
||||
border-bottom: 1px solid #dddddd;
|
||||
background: #ffffff;
|
||||
}
|
||||
.wp_china_yes-sticky .wp_china_yes-header-inner {
|
||||
position: fixed;
|
||||
box-shadow: unset;
|
||||
}
|
||||
|
||||
.wp_china_yes-warning-primary {
|
||||
color: #5e77ec !important;
|
||||
border-color: #5e77ec !important;
|
||||
background: #ffffff !important;
|
||||
}
|
||||
|
||||
.wp_china_yes-warning-primary:focus, .wp_china_yes-warning-primary:hover {
|
||||
border-color: #3858e9 !important;
|
||||
background: #ffffff !important;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-switcher .wp_china_yes--switcher:not(.wp_china_yes--active) {
|
||||
background-color: #9a9a9a;
|
||||
}
|
||||
|
||||
.wp_china_yes-theme-light .wp_china_yes-nav-normal > ul {
|
||||
margin-right: -2px;
|
||||
margin-bottom: -1px;
|
||||
}
|
||||
|
||||
|
||||
@media screen and (max-width: 600px) {
|
||||
.wpcy-about__grid {
|
||||
grid-template-columns: 1fr!important;
|
||||
}
|
||||
.wp_china_yes-buttons {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
.wp_china_yes-buttons .button {
|
||||
margin: 2px 0;
|
||||
text-align: center;
|
||||
}
|
||||
.sponsor-logos {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
.sponsor-logos img {
|
||||
max-width: 60px;
|
||||
margin: 8px;
|
||||
}
|
||||
.wpcy-buttons {
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.components-button {
|
||||
justify-content: center;
|
||||
padding: 8px 12px;
|
||||
min-height: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 480px) {
|
||||
.wp_china_yes-header-inner {
|
||||
padding: 10px 15px;
|
||||
}
|
||||
.wp_china_yes-header-inner h1 {
|
||||
font-size: 1.2em;
|
||||
line-height: 1.3;
|
||||
}
|
||||
.wp_china_yes-field {
|
||||
padding: 15px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.wp_china_yes-section {
|
||||
margin: 10px auto;
|
||||
max-width: 100%;
|
||||
}
|
||||
.wp_china_yes-section-title {
|
||||
padding: 15px 20px;
|
||||
}
|
||||
.sponsor-logos {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
.wpcy-about__grid .column {
|
||||
padding: 6%;
|
||||
}
|
||||
.column.wpcy-kit-banner {
|
||||
padding: 4% 4% 2%!important;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
span.wpcy-icon-inner {
|
||||
line-height: 1px;
|
||||
font-size: 28px;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
span.wpcy-icon-inner-list {
|
||||
line-height: 0px;
|
||||
font-size: 24px;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.wpcy-about__grid {
|
||||
margin: 24px auto;
|
||||
display: grid;
|
||||
grid-gap: 24px;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.wpcy-kit__grid {
|
||||
margin: 24px auto;
|
||||
display: grid;
|
||||
grid-gap: 24px;
|
||||
grid-template-columns: repeat(1, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.column.wpcy-kit-banner {
|
||||
padding: 6% 6% 3%!important;
|
||||
}
|
||||
|
||||
.wpcy-about__grid .column {
|
||||
padding: 10%;
|
||||
background-color: #ffffff;
|
||||
border-radius: 1px;
|
||||
box-shadow: 0 0 0 1px #ccd0d4, 0 1px 1px 1px rgba(0, 0, 0, .04);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.wpcy-about__grid.columns-1 {
|
||||
grid-template-columns: repeat(1, minmax(0, 1fr));
|
||||
}
|
||||
.wpcy-about__grid.columns-3 {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
.wpcy-about__grid .column > svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
margin-left: -3px;
|
||||
}
|
||||
|
||||
.wpcy-buttons {
|
||||
margin-top: 4px;
|
||||
margin-bottom: 32px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
.wpcy-banner img {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
margin-top: auto;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.components-button.has-icon {
|
||||
justify-content: center;
|
||||
min-width: 36px;
|
||||
padding: 6px;
|
||||
}
|
||||
.components-button.has-icon.has-text {
|
||||
gap: 4px;
|
||||
justify-content: start;
|
||||
padding-left: 8px;
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
.wpcy-about__list li a:not(:hover) {
|
||||
text-decoration: none;
|
||||
}
|
||||
.components-button {
|
||||
align-items: center;
|
||||
-webkit-appearance: none;
|
||||
background: none;
|
||||
border: 0;
|
||||
border-radius: 2px;
|
||||
box-sizing: border-box;
|
||||
color: var(--wp-components-color-foreground, #1e1e1e);
|
||||
cursor: pointer;
|
||||
display: inline-flex
|
||||
;
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
font-weight: 400;
|
||||
height: 36px;
|
||||
margin: 0;
|
||||
padding: 6px 12px;
|
||||
text-decoration: none;
|
||||
transition: box-shadow .1s linear;
|
||||
}
|
||||
.components-button.button-link {
|
||||
background: none;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9));
|
||||
height: auto;
|
||||
margin: 0;
|
||||
outline: none;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
text-decoration: underline;
|
||||
transition-duration: .05s;
|
||||
transition-property: border, background, color;
|
||||
transition-timing-function: ease-in-out;
|
||||
}
|
||||
.components-button.button-primary {
|
||||
display: inline-flex;
|
||||
padding: 6px 12px;
|
||||
}
|
||||
|
||||
.components-button.button-secondary {
|
||||
background: #0000;
|
||||
display: inline-flex;
|
||||
padding: 6px 12px;
|
||||
}
|
||||
|
||||
/* 移动端菜单按钮样式 */
|
||||
.wp_china_yes-mobile-menu-btn {
|
||||
color: #333;
|
||||
padding: 5px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.wp_china_yes-mobile-menu-btn:hover {
|
||||
background-color: rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
/* 表单元素响应式优化 */
|
||||
@media screen and (max-width: 782px) {
|
||||
.wp_china_yes-field-checkbox .wp_china_yes--inline-list li,
|
||||
.wp_china_yes-field-radio .wp_china_yes--inline-list li {
|
||||
display: block;
|
||||
margin-right: 0;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-button_set .wp_china_yes--buttons {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-button_set .wp_china_yes--button {
|
||||
flex: 1;
|
||||
min-width: 80px;
|
||||
text-align: center;
|
||||
border-radius: 4px !important;
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-color > input {
|
||||
width: 100%;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.wp_china_yes-field-upload .button {
|
||||
width: 100%;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
/* 平板设备优化 */
|
||||
@media screen and (min-width: 783px) and (max-width: 960px) {
|
||||
.wp_china_yes-field-checkbox .wp_china_yes--inline-list li,
|
||||
.wp_china_yes-field-radio .wp_china_yes--inline-list li {
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
assets/images/qr-banner.jpg
Executable file
|
After Width: | Height: | Size: 47 KiB |
BIN
assets/images/website-banner.jpg
Executable file
|
After Width: | Height: | Size: 47 KiB |
BIN
assets/images/wpcy-logo.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
72
assets/js/script.js
Executable file
|
|
@ -0,0 +1,72 @@
|
|||
jQuery(document).ready(function($) {
|
||||
// 移动端菜单切换功能
|
||||
function initMobileMenu() {
|
||||
// 添加菜单按钮
|
||||
if (!$('.wp_china_yes-mobile-menu-btn').length) {
|
||||
$('.wp_china_yes-header-inner').prepend(
|
||||
'<button class="wp_china_yes-mobile-menu-btn" style="display: none; position: absolute; left: 15px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 18px; cursor: pointer; z-index: 10000;">☰</button>'
|
||||
);
|
||||
}
|
||||
|
||||
// 检查屏幕尺寸
|
||||
function checkScreenSize() {
|
||||
if ($(window).width() <= 782) {
|
||||
$('.wp_china_yes-mobile-menu-btn').show();
|
||||
$('.wp_china_yes-nav-normal').removeClass('mobile-open');
|
||||
} else {
|
||||
$('.wp_china_yes-mobile-menu-btn').hide();
|
||||
$('.wp_china_yes-nav-normal').removeClass('mobile-open');
|
||||
}
|
||||
}
|
||||
|
||||
// 菜单按钮点击事件
|
||||
$(document).on('click', '.wp_china_yes-mobile-menu-btn', function() {
|
||||
$('.wp_china_yes-nav-normal').toggleClass('mobile-open');
|
||||
});
|
||||
|
||||
// 点击内容区域关闭菜单
|
||||
$(document).on('click', '.wp_china_yes-content', function() {
|
||||
if ($(window).width() <= 782) {
|
||||
$('.wp_china_yes-nav-normal').removeClass('mobile-open');
|
||||
}
|
||||
});
|
||||
|
||||
// 窗口大小改变时检查
|
||||
$(window).resize(checkScreenSize);
|
||||
checkScreenSize();
|
||||
}
|
||||
|
||||
initMobileMenu();
|
||||
|
||||
$("#test-rss-feed").click(function() {
|
||||
var button = $(this);
|
||||
var result = $("#rss-test-result");
|
||||
var feedUrl = $("#custom_rss_url").val();
|
||||
|
||||
if (!feedUrl) {
|
||||
result.html('<span style="color: red;">请先填写 RSS 源地址</span>');
|
||||
return;
|
||||
}
|
||||
|
||||
button.prop("disabled", true);
|
||||
result.html("测试中...");
|
||||
|
||||
$.post(ajaxurl, {
|
||||
action: "test_rss_feed",
|
||||
_ajax_nonce: '<?php echo wp_create_nonce("wp_china_yes_nonce"); ?>',
|
||||
feed_url: feedUrl
|
||||
})
|
||||
.done(function(response) {
|
||||
result.html(response.success ?
|
||||
'<span style="color: green;">' + response.data + '</span>' :
|
||||
'<span style="color: red;">' + response.data + '</span>'
|
||||
);
|
||||
})
|
||||
.fail(function() {
|
||||
result.html('<span style="color: red;">测试失败</span>');
|
||||
})
|
||||
.always(function() {
|
||||
button.prop("disabled", false);
|
||||
});
|
||||
});
|
||||
});
|
||||
330
changelog.txt
Executable file
|
|
@ -0,0 +1,330 @@
|
|||
IMPORTANT:
|
||||
-----------------------------------------------------------------------------------------
|
||||
Please be sure to read the Important Update Notes before you update:
|
||||
https://wpcy.com/document/important-update-information/
|
||||
We are always proactive in preventing security issues, however nobody can assume they will never come up.
|
||||
This is why we highly recommend to stay up to date with each new theme version and plugins.
|
||||
|
||||
重要提示:
|
||||
-----------------------------------------------------------------------------------------
|
||||
在更新之前,请务必阅读重要更新说明:
|
||||
https://wpcy.com/document/important-update-information/
|
||||
|
||||
我们始终致力于积极防范安全问题,但没有人能完全避免潜在风险。
|
||||
因此,我们强烈建议您密切关注每个主题和插件的新版本更新,以确保安全性和功能的最佳状态。
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.8.1 - 2025-07-29
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
* 小版本更新,修复和优化
|
||||
|
||||
1. 代码优化和性能提升
|
||||
2. 修复已知问题
|
||||
3. 兼容性改进
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.8 - 2025-02-05
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
* 文派叶子 v3.8 重大更新!全新UI 设计更接近 WordPress 原生体验。
|
||||
|
||||
1. 替换业务域名 WP-China-Yes.com 为新域名 WPCY.COM ;
|
||||
2. 修复 adminCDN 支持 jsDelivr 加速无效等问题;
|
||||
3. 新增 Bootstrap CDN 转接至 adminCDN 加速支持;
|
||||
4. 新增 Windfonts 中文排版优化:支持段首空格 2em;
|
||||
5. 新增 Windfonts 中文排版优化:支持文本内容对齐;
|
||||
6. 新增 [脉云维护] 菜单并支持WP系统状态监控,可在页脚位置显示内存、CPU用量等信息;
|
||||
7. 新增 [欢迎使用] 用户引导页面,更清晰的功能指导和简介。
|
||||
8. 新增 [建站工具] 文派·寻鹿建站套件展示页面,内容待完善。
|
||||
9. 优化 [萌芽加速] 设置,与 WordPress 程序端加速选项分离便于添加后续项目;
|
||||
10. 优化 [关于插件] 页面更简约的赞助商 Logo 和贡献者名单展示。
|
||||
11. 补充 changelog.txt 文本文件,跟随插件副本分发。
|
||||
12. 补充 copyright.txt 版权文件,跟随插件副本分发。
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.7.1 - 2024-11-19
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 性能优化
|
||||
2. 修复监控无法关闭的问题
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.6.5 - 2024-08-23
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 优化 CLI 判断
|
||||
2. 回退替换钩子修改
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.6.4 - 2024-08-23
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. WP-CLI 下不运行 adminCDN 部分,防止影响缓冲区。
|
||||
2. 部分文案调整支持多语言。
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.6.3 - 2024-08-23
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 为自动监控功能添加开关
|
||||
2. adminCDN 支持 jsDelivr 加速
|
||||
3. Windfonts 支持优化模式开关
|
||||
|
||||
**adminCDN 的 jsd 加速默认屏蔽 gh 端点,如有主题插件作者需要使用请联系加白。**
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.6.2 - 2024-03-09
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. UI 重构
|
||||
2. 修复市场加速导致 Beta 测试插件失效的问题
|
||||
3. 更新接口及测试 URL
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.6.1 - 2024-03-08
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 重构全部代码
|
||||
2. 应用市场调整为[文派开源](https://wenpai.org)
|
||||
3. 加速服务调整为[萌芽加速](https://admincdn.com)
|
||||
4. 头像调整为[初认头像](https://cravatar.com)
|
||||
5. 支持自动检测节点可用性
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
发展历史
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
- 2019 年 2022 年 @薇晓朵 为 WP 中文本地化项目提供各项赞助支持,期间陆续数十万的资金。
|
||||
- 2022 年起至 2023 年 3 月,原有 LitePress 及 WP 中文本土化社区项目进入维护状态,不再活跃;
|
||||
- 2023 年 3 月由 @薇晓朵(Weixiaoduo.com)联系原项目团队咨询相关发展情况,得知已无继续开发此项目的意向。
|
||||
- 此时文派开源(WenPai.org)项目也处于筹备启动基础设施建设阶段。
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
项目重启
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
- 了解到此项目实际情况并商议后,文派(广州)科技有限公司决定收购此项目并启动旗下————文派开源(WenPai.org)。
|
||||
- 2023 年 4 月 10 日文派科技公布收购 LitePress 社区声明 https://wpcy.com/news/acquisition-announcement
|
||||
- 2023 年 4 月 25 日 WP-China-Yes 发布中文品牌词——“文派叶子”,寓意生生不息。
|
||||
- 2023 年 5 月 LitePress 、Cravatar 、WP-China-Yes 等项目重启,进入正式交接重启开发阶段。
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
投资机构:汉中菲比斯网络技术有限公司
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
投资项目:文派(WordPress)中国生态基础设施建设、文派开源中国本土化 WordPress 发行版及社区建设。
|
||||
投资金额:一百万人民币(一期)
|
||||
基础资源:三百个 WP 行业属性稀缺域名资源,以及 “文派” 品牌、商标、软著、专利等知识产权。
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
委托机构:文派(广州)科技有限公司
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
技术支持:薇晓朵团队 - Weixiaoduo.com
|
||||
营销支持:莫蒂奇团队 - Modiqi.com
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooo&&B&oooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooo#B&oo&#B#ooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooBG&o#BBB&oooooooooooooooooooooooooooooooooooooooooo
|
||||
ooooooooooooooooooooooooooooooooo#BGGBG#&ooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooo#BGGGGGG&ooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooo&&#GGGGGB&oooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooBGGGGGGGB##&&&&&#####&&oooooooooooooooooooooooooooooo
|
||||
ooooooooooooooooooooooooooooooooo&GGGGGGGGGGGGGGGGGGGGGGBB#ooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooo#GGGGGGGGGGGGGGGGGGGGGG&#ooooooooooooooooooooooooooo
|
||||
ooooooooooooooooooooooooooooooooooo#GGGGGGGGGGGGGGGGGGGG#ooooooooooooooooooooooooooooo
|
||||
ooooooooooooooooooooooooooooooooooooo#BGGGGGGGBB##&BGGGGB&oooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooGGG&ooooooooo#GGBBGB&oooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooo#GBGooooooooooo&GBooG#oooooooooooooooooooooooooo
|
||||
ooooooooooooooooooooooooooooooooooooooooG#oooooooooooB#ooo##oooooooooooooooooooooooooo
|
||||
ooooooooooooooooooooooooooooooooooooooo#G#ooooooooooo&G&oo##oooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooB#&&oooooooooB#oooo##oooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooo#&oooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooo##———— www.feibisi.com ————##ooooooooooooooooooooooooooooooo
|
||||
ooooooooooooooooooooooooooo####菲比斯 · 品味简单生活####ooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
ooooooooooo(此项目于 2023 年 4 月重启,由菲比斯公司提供了初始一百万启动投资。)ooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
2022 年 ~ 2023 年 3 月
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
此项目及 LitePress 社区发展已停滞,前景不明。
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.5.5 - 2022-11-15 此为前团队发布最后一版。
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
修复
|
||||
1. 仓库源替换代码优先级过低被覆盖的问题
|
||||
|
||||
重构
|
||||
1. 去掉 CDNJS 功能;
|
||||
2. 修改 WP China 标志为 LitePress
|
||||
3. 替换各种加速节点链接为 LitePress 维护的地址
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.5.4 - 2024-03-08
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
特性
|
||||
1. CDNJS加速功能
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.5.3 - 2024-03-08
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
修复
|
||||
1. 核心功能无法在 Cron 环境中运行的问题
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.5.2 - 2024-03-08
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
修复
|
||||
1. 留下测试代码
|
||||
2. 当未拦截到 API 请求时直接返回 WordPress 到底是什么响应值,而不是 false,该问题会导致其他插件无法调用 pre_http_request 过滤器
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.5.1 - 2021-10-01
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
修复
|
||||
1. 不为 LitePress 替换后台资源
|
||||
2. 完善Cravatar头像夺取机制
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.5.0 - 2021-09-05
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
特性
|
||||
1. 将“本土应用市场”更改为“LitePress 应用市场”,进而对接 LitePress 翻译平台
|
||||
2. “参与翻译”按钮全局生效
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.4.1 - 2021-08-15
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
修复
|
||||
1. 不为处于RC版本的WordPress替换后台静态资源
|
||||
2. 替换默认头像处的Gravatar字样
|
||||
3. 替换个人资料卡中的头像设置说明
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.4.0 - 2021-07-27
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
特性
|
||||
1. 将 Gravatar 头像替换方案由反代更改为 Cravatar(任何开发者均可在自己的产品中集成 Cravatar 头像服务)
|
||||
|
||||
修复
|
||||
1. 修复了某些情况下无法替换 Gravatar 头像的问题
|
||||
2. 修复:管理后台加速功能因用户反馈问题较多,故暂时默认关闭
|
||||
3. 修复:后台加速功能误对处于测试状态的WordPress起作用的问题
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.3.1 - 2020-10-28
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 修复:管理后台加速功能因用户反馈问题较多,故暂时默认关闭
|
||||
2. 修复:后台加速功能误对处于测试状态的WordPress起作用的问题
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.3.0 - 2020-10-14
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 特性:当使用“本土应用市场”时为插件列表中的所有插件追加“翻译校准”链接
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.2.0 - 2020-10-07
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 特性:支持谷歌前端公共库加速
|
||||
2. 特性:细化管理界面设置的颗粒度
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.1.3 - 2020-09-18
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 修复:多站点模式下可以在子站点激活插件的BUG
|
||||
2. 修复:多站点模式下无法保存配置的BUG
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.1.2 - 2020-08-30
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 修复:兼容WordPress多站点模式(只在主控上显示设置项)
|
||||
2. 修复:插件更新后设置项被覆盖的问题
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.1.1 - 2020-08-27
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
特性
|
||||
1. 增加管理后台加速功能,原理是将WordPress核心依赖的静态文件切换为公共资源,这将极大的加快管理后台访问速度^_^
|
||||
2. 增加”不接管应用市场“选项
|
||||
|
||||
修复
|
||||
1. 对AJAX加载的场景做了较为详尽的适配,节约每一点服务器资源
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v3.0.0 - 2020-08-15
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 使用WordPress默认组件重写设置页面
|
||||
2. 增加Gravatar加速支持
|
||||
3. 增加谷歌字体加速支持
|
||||
4. 对接本土应用市场,这个应用市场与本土翻译平台深度整合,可以大家进行基于AI翻译+人工辅助调整的全量汉化支持(技术试验)
|
||||
5. “仓库源-主源”更名为“官方应用市场镜像”
|
||||
6. 移除“自定义源”功能
|
||||
7. 移除“资源”
|
||||
8. 删除仪表盘赞助商列表
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v2.1.0 - 2020-04-11
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 取消社区源选择功能,只保留主源和备源
|
||||
2. 禁止设置页的tab
|
||||
3. 在仪表盘上放置了赞助者名单展示小部件(可关闭)
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v2.0.3 - 2020-03-20
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 修复修改仓库源后刷新页面无法正确展示源信息的问题
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v2.0.2 - 2020-03-18
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. RepairAPI接口编写的不规范的问题#7
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v2.0.1 - 2020-03-18
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 修复插件无法在使用子目录部署的 WordPress 上运行的问题#6
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v2.0.0 - 2020-03-12
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
从这个版本开始WP-China-是第一次拥有了图形化设置界面
|
||||
|
||||
1. 社区资源
|
||||
2. 来源支持
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
v1.0.1 - 2020-03-12
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
1. 核心功能
|
||||
27
composer.json
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"name": "wenpai-org/wp-china-yes",
|
||||
"description": "WordPress Optimized Plugin for Mainland China",
|
||||
"type": "project",
|
||||
"require": {
|
||||
"yahnis-elsts/plugin-update-checker": "^5.2"
|
||||
},
|
||||
"license": "GPL-3.0-or-later",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"WenPai\\ChinaYes\\": "./"
|
||||
},
|
||||
"files": [
|
||||
"helpers.php",
|
||||
"framework/classes/setup.class.php"
|
||||
]
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "耗子",
|
||||
"email": "i@haozi.net"
|
||||
}
|
||||
],
|
||||
"config": {
|
||||
"optimize-autoloader": true
|
||||
}
|
||||
}
|
||||
69
composer.lock
generated
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "46cf14a68ffba471ee1e2f603a301a9c",
|
||||
"packages": [
|
||||
{
|
||||
"name": "yahnis-elsts/plugin-update-checker",
|
||||
"version": "v5.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/YahnisElsts/plugin-update-checker.git",
|
||||
"reference": "845d65da93bcff31649ede00d9d73b1beadbb7f0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/YahnisElsts/plugin-update-checker/zipball/845d65da93bcff31649ede00d9d73b1beadbb7f0",
|
||||
"reference": "845d65da93bcff31649ede00d9d73b1beadbb7f0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"php": ">=5.6.20"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"load-v5p5.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Yahnis Elsts",
|
||||
"email": "whiteshadow@w-shadow.com",
|
||||
"homepage": "https://w-shadow.com/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.",
|
||||
"homepage": "https://github.com/YahnisElsts/plugin-update-checker/",
|
||||
"keywords": [
|
||||
"automatic updates",
|
||||
"plugin updates",
|
||||
"theme updates",
|
||||
"wordpress"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/YahnisElsts/plugin-update-checker/issues",
|
||||
"source": "https://github.com/YahnisElsts/plugin-update-checker/tree/v5.5"
|
||||
},
|
||||
"time": "2024-10-16T14:25:00+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
54
copyright.txt
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
-----------------------------------------------------------------------------------------
|
||||
**Copyright © 2025 WenPai.cn (Guangzhou) Technology Co., Ltd.**
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
**Compliance Terms**
|
||||
Everyone is free to use WenPai open-source software. However, in China, when using WenPai software,
|
||||
you must adhere to the GPL v3 (or later) open-source license, respect the intellectual property rights of others,
|
||||
and prioritize compliance with Chinese laws in case of any conflicts.
|
||||
|
||||
**Fork Declaration**
|
||||
To ensure the long-term availability of various WenPai (WordPress) infrastructure components,
|
||||
individuals with the necessary capabilities are welcome to establish their own service sources
|
||||
or fork WenPai Leaf 🍃 (WPCY.COM) to create their own versions.
|
||||
|
||||
**The Only Requirement:**
|
||||
While strictly adhering to the GPL v3 (or later) license, you must respect all lawful rights of WenPai Technology,
|
||||
including (but not limited to) copyrights, trademarks, patents, intellectual property, goodwill, and more.
|
||||
|
||||
**Disclaimer:**
|
||||
This software is provided "as is" without warranty of any kind, express or implied.
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
**版权所有 © 2025 年 文派(广州)科技有限公司**
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
**合规条款**
|
||||
任何人都可以自由使用文派开源软件,但在中国境内使用文派软件时,您应在遵守 GPL v3(或更高版本)开源协议的同时,
|
||||
尊重他人的知识产权,如有与中国法律冲突的情况,以中国法律为准。
|
||||
|
||||
**分叉声明**
|
||||
为保障各项文派(WordPress)基础设施的长久可用性,
|
||||
欢迎有能力的人自建各类服务源以及分叉文派叶子🍃(WPCY.COM)来制作您自己的版本;
|
||||
|
||||
**唯一要求:**
|
||||
在严格遵守 GPL v3(或更高版本)协议的前提下,尊重文派科技的各项合法权益,
|
||||
包括(不限于)版权、商标、专利、知识产权、商誉等…
|
||||
|
||||
**免责声明:**
|
||||
本软件按"现状"提供,不提供任何明示或暗示的保证。
|
||||
|
||||
**许可证信息:**
|
||||
完整的 GPL v3 许可证文本请参见项目根目录下的 license 文件。
|
||||
许可证详情:https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
**联系方式:**
|
||||
官方网站:https://wpcy.com
|
||||
项目仓库:https://github.com/WenPai-org/wp-china-yes
|
||||
菲码源库:https://feicode.com/WenPai-org/wp-china-yes
|
||||
技术支持:https://wenpai.org
|
||||
|
||||
-----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
1
framework/assets/css/style-rtl.min.css
vendored
Executable file
1
framework/assets/css/style.min.css
vendored
Executable file
BIN
framework/assets/images/checkerboard.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
1
framework/assets/images/wp-logo.svg
Executable file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect x="0" fill="none" width="20" height="20"/><g><g fill="#fff"><path d="M20 10c0-5.52-4.48-10-10-10S0 4.48 0 10s4.48 10 10 10 10-4.48 10-10zM10 1.01c4.97 0 8.99 4.02 8.99 8.99s-4.02 8.99-8.99 8.99S1.01 14.97 1.01 10 5.03 1.01 10 1.01zM8.01 14.82L4.96 6.61c.49-.03 1.05-.08 1.05-.08.43-.05.38-1.01-.06-.99 0 0-1.29.1-2.13.1-.15 0-.33 0-.52-.01 1.44-2.17 3.9-3.6 6.7-3.6 2.09 0 3.99.79 5.41 2.09-.6-.08-1.45.35-1.45 1.42 0 .66.38 1.22.79 1.88.31.54.5 1.22.5 2.21 0 1.34-1.27 4.48-1.27 4.48l-2.71-7.5c.48-.03.75-.16.75-.16.43-.05.38-1.1-.05-1.08 0 0-1.3.11-2.14.11-.78 0-2.11-.11-2.11-.11-.43-.02-.48 1.06-.05 1.08l.84.08 1.12 3.04zm6.02 2.15L16.64 10s.67-1.69.39-3.81c.63 1.14.94 2.42.94 3.81 0 2.96-1.56 5.58-3.94 6.97zM2.68 6.77L6.5 17.25c-2.67-1.3-4.47-4.08-4.47-7.25 0-1.16.2-2.23.65-3.23zm7.45 4.53l2.29 6.25c-.75.27-1.57.42-2.42.42-.72 0-1.41-.11-2.06-.3z"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 940 B |
1
framework/assets/images/wp-plugin-logo.svg
Executable file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><rect x="0" fill="none" width="20" height="20"/><g><g fill="#fff"><path d="M13.11 4.36L9.87 7.6 8 5.73l3.24-3.24c.35-.34 1.05-.2 1.56.32.52.51.66 1.21.31 1.55zm-8 1.77l.91-1.12 9.01 9.01-1.19.84c-.71.71-2.63 1.16-3.82 1.16H6.14L4.9 17.26c-.59.59-1.54.59-2.12 0-.59-.58-.59-1.53 0-2.12l1.24-1.24v-3.88c0-1.13.4-3.19 1.09-3.89zm7.26 3.97l3.24-3.24c.34-.35 1.04-.21 1.55.31.52.51.66 1.21.31 1.55l-3.24 3.25z"/></g></g></svg>
|
||||
|
After Width: | Height: | Size: 482 B |
2
framework/assets/js/main.min.js
vendored
Executable file
2
framework/assets/js/plugins.min.js
vendored
Executable file
195
framework/classes/abstract.class.php
Executable file
|
|
@ -0,0 +1,195 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Abstract Class
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Abstract' ) ) {
|
||||
#[AllowDynamicProperties]
|
||||
abstract class WP_CHINA_YES_Abstract {
|
||||
|
||||
public $abstract = '';
|
||||
public $output_css = '';
|
||||
|
||||
public function __construct() {
|
||||
|
||||
// Collect output css and typography
|
||||
if ( ! empty( $this->args['output_css'] ) || ! empty( $this->args['enqueue_webfont'] ) ) {
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'collect_output_css_and_typography' ), 10 );
|
||||
WP_CHINA_YES::$css = apply_filters( "wp_china_yes_{$this->unique}_output_css", WP_CHINA_YES::$css, $this );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function collect_output_css_and_typography() {
|
||||
$this->recursive_output_css( $this->pre_fields );
|
||||
}
|
||||
|
||||
public function recursive_output_css( $fields = array(), $combine_field = array() ) {
|
||||
|
||||
if ( ! empty( $fields ) ) {
|
||||
|
||||
foreach ( $fields as $field ) {
|
||||
|
||||
$field_id = ( ! empty( $field['id'] ) ) ? $field['id'] : '';
|
||||
$field_type = ( ! empty( $field['type'] ) ) ? $field['type'] : '';
|
||||
$field_output = ( ! empty( $field['output'] ) ) ? $field['output'] : '';
|
||||
$field_check = ( $field_type === 'typography' || $field_output ) ? true : false;
|
||||
$field_class = 'WP_CHINA_YES_Field_' . $field_type;
|
||||
|
||||
if ( $field_type && $field_id ) {
|
||||
|
||||
|
||||
if( $field_type === 'fieldset' ) {
|
||||
if ( ! empty( $field['fields'] ) ) {
|
||||
$this->recursive_output_css( $field['fields'], $field );
|
||||
}
|
||||
}
|
||||
|
||||
if( $field_type === 'accordion' ) {
|
||||
if ( ! empty( $field['accordions'] ) ) {
|
||||
foreach ( $field['accordions'] as $accordion ) {
|
||||
$this->recursive_output_css( $accordion['fields'], $field );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( $field_type === 'tabbed' ) {
|
||||
if ( ! empty( $field['tabs'] ) ) {
|
||||
foreach ( $field['tabs'] as $accordion ) {
|
||||
$this->recursive_output_css( $accordion['fields'], $field );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( class_exists( $field_class ) ) {
|
||||
|
||||
if ( method_exists( $field_class, 'output' ) || method_exists( $field_class, 'enqueue_google_fonts' ) ) {
|
||||
|
||||
$field_value = '';
|
||||
|
||||
if ( $field_check && ( $this->abstract === 'options' || $this->abstract === 'customize' ) ) {
|
||||
|
||||
if( ! empty( $combine_field ) ) {
|
||||
|
||||
$field_value = ( isset( $this->options[$combine_field['id']][$field_id] ) ) ? $this->options[$combine_field['id']][$field_id] : '';
|
||||
|
||||
} else {
|
||||
|
||||
$field_value = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : '';
|
||||
|
||||
}
|
||||
|
||||
} else if ( $field_check && ( $this->abstract === 'metabox' && is_singular() || $this->abstract === 'taxonomy' && is_archive() ) ) {
|
||||
|
||||
if( ! empty( $combine_field ) ) {
|
||||
|
||||
$meta_value = $this->get_meta_value( $combine_field );
|
||||
$field_value = ( isset( $meta_value[$field_id] ) ) ? $meta_value[$field_id] : '';
|
||||
|
||||
} else {
|
||||
|
||||
$meta_value = $this->get_meta_value( $field );
|
||||
$field_value = ( isset( $meta_value ) ) ? $meta_value : '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$instance = new $field_class( $field, $field_value, $this->unique, 'wp/enqueue', $this );
|
||||
|
||||
// typography enqueue and embed google web fonts
|
||||
if ( $field_type === 'typography' && $this->args['enqueue_webfont'] && ! empty( $field_value['font-family'] ) ) {
|
||||
|
||||
$method = ( ! empty( $this->args['async_webfont'] ) ) ? 'async' : 'enqueue';
|
||||
|
||||
$instance->enqueue_google_fonts( $method );
|
||||
|
||||
}
|
||||
|
||||
// output css
|
||||
if ( $field_output && $this->args['output_css'] ) {
|
||||
WP_CHINA_YES::$css .= $instance->output();
|
||||
}
|
||||
|
||||
unset( $instance );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function pre_tabs( $sections ) {
|
||||
|
||||
$count = 100;
|
||||
$result = array();
|
||||
$parents = array();
|
||||
|
||||
foreach ( $sections as $key => $section ) {
|
||||
if ( ! empty( $section['parent'] ) ) {
|
||||
$section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count;
|
||||
$parents[$section['parent']][] = $section;
|
||||
unset( $sections[$key] );
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
|
||||
foreach ( $sections as $key => $section ) {
|
||||
$section['priority'] = ( isset( $section['priority'] ) ) ? $section['priority'] : $count;
|
||||
if ( ! empty( $section['id'] ) && ! empty( $parents[$section['id']] ) ) {
|
||||
$section['subs'] = wp_list_sort( $parents[$section['id']], array( 'priority' => 'ASC' ), 'ASC', true );
|
||||
}
|
||||
$result[] = $section;
|
||||
$count++;
|
||||
}
|
||||
|
||||
return wp_list_sort( $result, array( 'priority' => 'ASC' ), 'ASC', true );
|
||||
|
||||
}
|
||||
|
||||
public function pre_sections( $sections ) {
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ( $this->pre_tabs( $sections ) as $section ) {
|
||||
if ( ! empty( $section['subs'] ) ) {
|
||||
foreach ( $section['subs'] as $sub ) {
|
||||
$sub['ptitle'] = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
|
||||
$result[] = $sub;
|
||||
}
|
||||
}
|
||||
if ( empty( $section['subs'] ) ) {
|
||||
$result[] = $section;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function pre_fields( $sections ) {
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ( $sections as $key => $section ) {
|
||||
if ( ! empty( $section['fields'] ) ) {
|
||||
foreach ( $section['fields'] as $field ) {
|
||||
$result[] = $field;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
688
framework/classes/admin-options.class.php
Executable file
|
|
@ -0,0 +1,688 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Options Class
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Options' ) ) {
|
||||
class WP_CHINA_YES_Options extends WP_CHINA_YES_Abstract {
|
||||
|
||||
// constans
|
||||
public $unique = '';
|
||||
public $notice = '';
|
||||
public $abstract = 'options';
|
||||
public $sections = array();
|
||||
public $options = array();
|
||||
public $errors = array();
|
||||
public $pre_tabs = array();
|
||||
public $pre_fields = array();
|
||||
public $pre_sections = array();
|
||||
public $args = array(
|
||||
|
||||
// framework title
|
||||
'framework_title' => 'Wp_china_yes Framework <small>by Wp_china_yes</small>',
|
||||
'framework_class' => '',
|
||||
|
||||
// menu settings
|
||||
'menu_title' => '',
|
||||
'menu_slug' => '',
|
||||
'menu_type' => 'menu',
|
||||
'menu_capability' => 'manage_options',
|
||||
'menu_icon' => null,
|
||||
'menu_position' => null,
|
||||
'menu_hidden' => false,
|
||||
'menu_parent' => '',
|
||||
'sub_menu_title' => '',
|
||||
|
||||
// menu extras
|
||||
'show_bar_menu' => true,
|
||||
'show_sub_menu' => true,
|
||||
'show_in_network' => true,
|
||||
'show_in_customizer' => false,
|
||||
|
||||
'show_search' => true,
|
||||
'show_reset_all' => true,
|
||||
'show_reset_section' => true,
|
||||
'show_footer' => true,
|
||||
'show_all_options' => true,
|
||||
'show_form_warning' => true,
|
||||
'sticky_header' => true,
|
||||
'save_defaults' => true,
|
||||
'ajax_save' => true,
|
||||
'form_action' => '',
|
||||
|
||||
// admin bar menu settings
|
||||
'admin_bar_menu_icon' => '',
|
||||
'admin_bar_menu_priority' => 50,
|
||||
|
||||
// footer
|
||||
'footer_text' => 'Thank you for creating with Wp_china_yes Framework',
|
||||
'footer_after' => '',
|
||||
'footer_credit' => '',
|
||||
|
||||
// database model
|
||||
'database' => '', // options, transient, theme_mod, network
|
||||
'transient_time' => 0,
|
||||
|
||||
// contextual help
|
||||
'contextual_help' => array(),
|
||||
'contextual_help_sidebar' => '',
|
||||
|
||||
// typography options
|
||||
'enqueue_webfont' => true,
|
||||
'async_webfont' => false,
|
||||
|
||||
// others
|
||||
'output_css' => true,
|
||||
|
||||
// theme
|
||||
'nav' => 'normal',
|
||||
'theme' => 'dark',
|
||||
'class' => '',
|
||||
|
||||
// external default values
|
||||
'defaults' => array(),
|
||||
|
||||
);
|
||||
|
||||
// run framework construct
|
||||
public function __construct( $key, $params = array() ) {
|
||||
|
||||
$this->unique = $key;
|
||||
$this->args = apply_filters( "wp_china_yes_{$this->unique}_args", wp_parse_args( $params['args'], $this->args ), $this );
|
||||
$this->sections = apply_filters( "wp_china_yes_{$this->unique}_sections", $params['sections'], $this );
|
||||
|
||||
// run only is admin panel options, avoid performance loss
|
||||
$this->pre_tabs = $this->pre_tabs( $this->sections );
|
||||
$this->pre_fields = $this->pre_fields( $this->sections );
|
||||
$this->pre_sections = $this->pre_sections( $this->sections );
|
||||
|
||||
$this->get_options();
|
||||
$this->set_options();
|
||||
$this->save_defaults();
|
||||
|
||||
add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
|
||||
add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu' ), $this->args['admin_bar_menu_priority'] );
|
||||
add_action( 'wp_ajax_wp_china_yes_'. $this->unique .'_ajax_save', array( $this, 'ajax_save' ) );
|
||||
|
||||
if ( $this->args['database'] === 'network' && ! empty( $this->args['show_in_network'] ) ) {
|
||||
add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) );
|
||||
}
|
||||
|
||||
// wp enqeueu for typography and output css
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
// instance
|
||||
public static function instance( $key, $params = array() ) {
|
||||
return new self( $key, $params );
|
||||
}
|
||||
|
||||
// add admin bar menu
|
||||
public function add_admin_bar_menu( $wp_admin_bar ) {
|
||||
|
||||
if ( ! current_user_can( $this->args['menu_capability'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_network_admin() && ( $this->args['database'] !== 'network' || $this->args['show_in_network'] !== true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->args['show_bar_menu'] ) && empty( $this->args['menu_hidden'] ) ) {
|
||||
|
||||
global $submenu;
|
||||
|
||||
$menu_slug = $this->args['menu_slug'];
|
||||
$menu_icon = ( ! empty( $this->args['admin_bar_menu_icon'] ) ) ? '<span class="wp_china_yes-ab-icon ab-icon '. esc_attr( $this->args['admin_bar_menu_icon'] ) .'"></span>' : '';
|
||||
|
||||
$wp_admin_bar->add_node( array(
|
||||
'id' => $menu_slug,
|
||||
'title' => $menu_icon . esc_attr( $this->args['menu_title'] ),
|
||||
'href' => esc_url( ( is_network_admin() ) ? network_admin_url( 'admin.php?page='. $menu_slug ) : admin_url( 'admin.php?page='. $menu_slug ) ),
|
||||
) );
|
||||
|
||||
if ( ! empty( $submenu[$menu_slug] ) ) {
|
||||
foreach ( $submenu[$menu_slug] as $menu_key => $menu_value ) {
|
||||
$wp_admin_bar->add_node( array(
|
||||
'parent' => $menu_slug,
|
||||
'id' => $menu_slug .'-'. $menu_key,
|
||||
'title' => $menu_value[0],
|
||||
'href' => esc_url( ( is_network_admin() ) ? network_admin_url( 'admin.php?page='. $menu_value[2] ) : admin_url( 'admin.php?page='. $menu_value[2] ) ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function ajax_save() {
|
||||
|
||||
$result = $this->set_options( true );
|
||||
|
||||
if ( ! $result ) {
|
||||
wp_send_json_error( array( 'error' => esc_html__( 'Error while saving the changes.', 'wp_china_yes' ) ) );
|
||||
} else {
|
||||
wp_send_json_success( array( 'notice' => $this->notice, 'errors' => $this->errors ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// get default value
|
||||
public function get_default( $field ) {
|
||||
|
||||
$default = ( isset( $field['default'] ) ) ? $field['default'] : '';
|
||||
$default = ( isset( $this->args['defaults'][$field['id']] ) ) ? $this->args['defaults'][$field['id']] : $default;
|
||||
|
||||
return $default;
|
||||
|
||||
}
|
||||
|
||||
// save defaults and set new fields value to main options
|
||||
public function save_defaults() {
|
||||
|
||||
$tmp_options = $this->options;
|
||||
|
||||
foreach ( $this->pre_fields as $field ) {
|
||||
if ( ! empty( $field['id'] ) ) {
|
||||
$this->options[$field['id']] = ( isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : $this->get_default( $field );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->args['save_defaults'] && empty( $tmp_options ) ) {
|
||||
$this->save_options( $this->options );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// set options
|
||||
public function set_options( $ajax = false ) {
|
||||
|
||||
// XSS ok.
|
||||
// No worries, This "POST" requests is sanitizing in the below foreach. see #L337 - #L341
|
||||
$response = ( $ajax && ! empty( $_POST['data'] ) ) ? json_decode( wp_unslash( trim( $_POST['data'] ) ), true ) : $_POST;
|
||||
|
||||
// Set variables.
|
||||
$data = array();
|
||||
$noncekey = 'wp_china_yes_options_nonce'. $this->unique;
|
||||
$nonce = ( ! empty( $response[$noncekey] ) ) ? $response[$noncekey] : '';
|
||||
$options = ( ! empty( $response[$this->unique] ) ) ? $response[$this->unique] : array();
|
||||
$transient = ( ! empty( $response['wp_china_yes_transient'] ) ) ? $response['wp_china_yes_transient'] : array();
|
||||
|
||||
if ( wp_verify_nonce( $nonce, 'wp_china_yes_options_nonce' ) ) {
|
||||
|
||||
$importing = false;
|
||||
$section_id = ( ! empty( $transient['section'] ) ) ? $transient['section'] : '';
|
||||
|
||||
if ( ! $ajax && ! empty( $response[ 'wp_china_yes_import_data' ] ) ) {
|
||||
|
||||
// XSS ok.
|
||||
// No worries, This "POST" requests is sanitizing in the below foreach. see #L337 - #L341
|
||||
$import_data = json_decode( wp_unslash( trim( $response[ 'wp_china_yes_import_data' ] ) ), true );
|
||||
$options = ( is_array( $import_data ) && ! empty( $import_data ) ) ? $import_data : array();
|
||||
$importing = true;
|
||||
$this->notice = esc_html__( 'Settings successfully imported.', 'wp_china_yes' );
|
||||
|
||||
}
|
||||
|
||||
if ( ! empty( $transient['reset'] ) ) {
|
||||
|
||||
foreach ( $this->pre_fields as $field ) {
|
||||
if ( ! empty( $field['id'] ) ) {
|
||||
$data[$field['id']] = $this->get_default( $field );
|
||||
}
|
||||
}
|
||||
|
||||
$this->notice = esc_html__( 'Default settings restored.', 'wp_china_yes' );
|
||||
|
||||
} else if ( ! empty( $transient['reset_section'] ) && ! empty( $section_id ) ) {
|
||||
|
||||
if ( ! empty( $this->pre_sections[$section_id-1]['fields'] ) ) {
|
||||
|
||||
foreach ( $this->pre_sections[$section_id-1]['fields'] as $field ) {
|
||||
if ( ! empty( $field['id'] ) ) {
|
||||
$data[$field['id']] = $this->get_default( $field );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = wp_parse_args( $data, $this->options );
|
||||
|
||||
$this->notice = esc_html__( 'Default settings restored.', 'wp_china_yes' );
|
||||
|
||||
} else {
|
||||
|
||||
// sanitize and validate
|
||||
foreach ( $this->pre_fields as $field ) {
|
||||
|
||||
if ( ! empty( $field['id'] ) ) {
|
||||
|
||||
$field_id = $field['id'];
|
||||
$field_value = isset( $options[$field_id] ) ? $options[$field_id] : '';
|
||||
|
||||
// Ajax and Importing doing wp_unslash already.
|
||||
if ( ! $ajax && ! $importing ) {
|
||||
$field_value = wp_unslash( $field_value );
|
||||
}
|
||||
|
||||
// Sanitize "post" request of field.
|
||||
if ( ! isset( $field['sanitize'] ) ) {
|
||||
|
||||
if( is_array( $field_value ) ) {
|
||||
|
||||
$data[$field_id] = wp_kses_post_deep( $field_value );
|
||||
|
||||
} else {
|
||||
|
||||
$data[$field_id] = wp_kses_post( $field_value );
|
||||
|
||||
}
|
||||
|
||||
} else if( isset( $field['sanitize'] ) && is_callable( $field['sanitize'] ) ) {
|
||||
|
||||
$data[$field_id] = call_user_func( $field['sanitize'], $field_value );
|
||||
|
||||
} else {
|
||||
|
||||
$data[$field_id] = $field_value;
|
||||
|
||||
}
|
||||
|
||||
// Validate "post" request of field.
|
||||
if ( isset( $field['validate'] ) && is_callable( $field['validate'] ) ) {
|
||||
|
||||
$has_validated = call_user_func( $field['validate'], $field_value );
|
||||
|
||||
if ( ! empty( $has_validated ) ) {
|
||||
|
||||
$data[$field_id] = ( isset( $this->options[$field_id] ) ) ? $this->options[$field_id] : '';
|
||||
$this->errors[$field_id] = $has_validated;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$data = apply_filters( "wp_china_yes_{$this->unique}_save", $data, $this );
|
||||
|
||||
do_action( "wp_china_yes_{$this->unique}_save_before", $data, $this );
|
||||
|
||||
$this->options = $data;
|
||||
|
||||
$this->save_options( $data );
|
||||
|
||||
do_action( "wp_china_yes_{$this->unique}_save_after", $data, $this );
|
||||
|
||||
if ( empty( $this->notice ) ) {
|
||||
$this->notice = esc_html__( 'Settings saved.', 'wp_china_yes' );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// save options database
|
||||
public function save_options( $data ) {
|
||||
|
||||
if ( $this->args['database'] === 'transient' ) {
|
||||
set_transient( $this->unique, $data, $this->args['transient_time'] );
|
||||
} else if ( $this->args['database'] === 'theme_mod' ) {
|
||||
set_theme_mod( $this->unique, $data );
|
||||
} else if ( $this->args['database'] === 'network' ) {
|
||||
update_site_option( $this->unique, $data );
|
||||
} else {
|
||||
update_option( $this->unique, $data, true );
|
||||
}
|
||||
|
||||
do_action( "wp_china_yes_{$this->unique}_saved", $data, $this );
|
||||
|
||||
}
|
||||
|
||||
// get options from database
|
||||
public function get_options() {
|
||||
|
||||
if ( $this->args['database'] === 'transient' ) {
|
||||
$this->options = get_transient( $this->unique );
|
||||
} else if ( $this->args['database'] === 'theme_mod' ) {
|
||||
$this->options = get_theme_mod( $this->unique );
|
||||
} else if ( $this->args['database'] === 'network' ) {
|
||||
$this->options = get_site_option( $this->unique );
|
||||
} else {
|
||||
$this->options = get_option( $this->unique );
|
||||
}
|
||||
|
||||
if ( empty( $this->options ) ) {
|
||||
$this->options = array();
|
||||
}
|
||||
|
||||
return $this->options;
|
||||
|
||||
}
|
||||
|
||||
// admin menu
|
||||
public function add_admin_menu() {
|
||||
|
||||
extract( $this->args );
|
||||
|
||||
if ( $menu_type === 'submenu' ) {
|
||||
|
||||
$menu_page = call_user_func( 'add_submenu_page', $menu_parent, esc_attr( $menu_title ), esc_attr( $menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ) );
|
||||
|
||||
} else {
|
||||
|
||||
$menu_page = call_user_func( 'add_menu_page', esc_attr( $menu_title ), esc_attr( $menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ), $menu_icon, $menu_position );
|
||||
|
||||
if ( ! empty( $sub_menu_title ) ) {
|
||||
call_user_func( 'add_submenu_page', $menu_slug, esc_attr( $sub_menu_title ), esc_attr( $sub_menu_title ), $menu_capability, $menu_slug, array( $this, 'add_options_html' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->args['show_sub_menu'] ) && count( $this->pre_tabs ) > 1 ) {
|
||||
|
||||
// create submenus
|
||||
foreach ( $this->pre_tabs as $section ) {
|
||||
call_user_func( 'add_submenu_page', $menu_slug, esc_attr( $section['title'] ), esc_attr( $section['title'] ), $menu_capability, $menu_slug .'#tab='. sanitize_title( $section['title'] ), '__return_null' );
|
||||
}
|
||||
|
||||
remove_submenu_page( $menu_slug, $menu_slug );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO CHINA-YES 支持隐藏子菜单
|
||||
if ( ! empty( $menu_hidden ) ) {
|
||||
remove_menu_page( $menu_slug );
|
||||
remove_submenu_page( $menu_parent, $menu_slug );
|
||||
}
|
||||
|
||||
add_action( 'load-'. $menu_page, array( $this, 'add_page_on_load' ) );
|
||||
|
||||
}
|
||||
|
||||
public function add_page_on_load() {
|
||||
|
||||
if ( ! empty( $this->args['contextual_help'] ) ) {
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
foreach ( $this->args['contextual_help'] as $tab ) {
|
||||
$screen->add_help_tab( $tab );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->args['contextual_help_sidebar'] ) ) {
|
||||
$screen->set_help_sidebar( $this->args['contextual_help_sidebar'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! empty( $this->args['footer_credit'] ) ) {
|
||||
add_filter( 'admin_footer_text', array( $this, 'add_admin_footer_text' ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function add_admin_footer_text() {
|
||||
echo wp_kses_post( $this->args['footer_credit'] );
|
||||
}
|
||||
|
||||
public function error_check( $sections, $err = '' ) {
|
||||
|
||||
if ( ! $this->args['ajax_save'] ) {
|
||||
|
||||
if ( ! empty( $sections['fields'] ) ) {
|
||||
foreach ( $sections['fields'] as $field ) {
|
||||
if ( ! empty( $field['id'] ) ) {
|
||||
if ( array_key_exists( $field['id'], $this->errors ) ) {
|
||||
$err = '<span class="wp_china_yes-label-error">!</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $sections['subs'] ) ) {
|
||||
foreach ( $sections['subs'] as $sub ) {
|
||||
$err = $this->error_check( $sub, $err );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $sections['id'] ) && array_key_exists( $sections['id'], $this->errors ) ) {
|
||||
$err = $this->errors[$sections['id']];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $err;
|
||||
}
|
||||
|
||||
// option page html output
|
||||
public function add_options_html() {
|
||||
|
||||
$has_nav = ( count( $this->pre_tabs ) > 1 ) ? true : false;
|
||||
$show_all = ( ! $has_nav ) ? ' wp_china_yes-show-all' : '';
|
||||
$ajax_class = ( $this->args['ajax_save'] ) ? ' wp_china_yes-save-ajax' : '';
|
||||
$sticky_class = ( $this->args['sticky_header'] ) ? ' wp_china_yes-sticky-header' : '';
|
||||
$wrapper_class = ( $this->args['framework_class'] ) ? ' '. $this->args['framework_class'] : '';
|
||||
$theme = ( $this->args['theme'] ) ? ' wp_china_yes-theme-'. $this->args['theme'] : '';
|
||||
$class = ( $this->args['class'] ) ? ' '. $this->args['class'] : '';
|
||||
$nav_type = ( $this->args['nav'] === 'inline' ) ? 'inline' : 'normal';
|
||||
$form_action = ( $this->args['form_action'] ) ? $this->args['form_action'] : '';
|
||||
|
||||
do_action( 'wp_china_yes_options_before' );
|
||||
|
||||
echo '<div class="wp_china_yes wp_china_yes-options'. esc_attr( $theme . $class . $wrapper_class ) .'" data-slug="'. esc_attr( $this->args['menu_slug'] ) .'" data-unique="'. esc_attr( $this->unique ) .'">';
|
||||
|
||||
echo '<div class="wp_china_yes-container">';
|
||||
|
||||
echo '<form method="post" action="'. esc_attr( $form_action ) .'" enctype="multipart/form-data" id="wp_china_yes-form" autocomplete="off" novalidate="novalidate">';
|
||||
|
||||
echo '<input type="hidden" class="wp_china_yes-section-id" name="wp_china_yes_transient[section]" value="1">';
|
||||
|
||||
wp_nonce_field( 'wp_china_yes_options_nonce', 'wp_china_yes_options_nonce'. $this->unique );
|
||||
|
||||
echo '<div class="wp_china_yes-header'. esc_attr( $sticky_class ) .'">';
|
||||
echo '<div class="wp_china_yes-header-inner">';
|
||||
|
||||
echo '<div class="wp_china_yes-header-left">';
|
||||
$hide_elements = !empty($this->options['hide_elements']) ? $this->options['hide_elements'] : [];
|
||||
if (!in_array('hide_logo', $hide_elements)) {
|
||||
$logo_url = !empty($this->options['header_logo']['url']) ? $this->options['header_logo']['url'] : plugins_url('wp-china-yes/assets/images/wpcy-logo.png');
|
||||
echo '<img src="' . esc_url($logo_url) . '" alt="WPCY Logo" class="wp-china-yes-logo" style="float: left; height: 26px; vertical-align: middle; margin-right: 10px;" />';
|
||||
}
|
||||
if (!in_array('hide_title', $hide_elements)) {
|
||||
echo '<h1>'. $this->args['framework_title'] .'</h1>';
|
||||
}
|
||||
if (!in_array('hide_version', $hide_elements)) {
|
||||
echo '<small> v' . CHINA_YES_VERSION . '</small>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-header-right">';
|
||||
|
||||
$notice_class = ( ! empty( $this->notice ) ) ? 'wp_china_yes-form-show' : '';
|
||||
$notice_text = ( ! empty( $this->notice ) ) ? $this->notice : '';
|
||||
|
||||
echo '<div class="wp_china_yes-form-result wp_china_yes-form-success '. esc_attr( $notice_class ) .'">'. $notice_text .'</div>';
|
||||
|
||||
echo ( $this->args['show_form_warning'] ) ? '<div class="wp_china_yes-form-result wp_china_yes-form-warning">'. esc_html__( 'You have unsaved changes, save your changes!', 'wp_china_yes' ) .'</div>' : '';
|
||||
|
||||
echo ( $has_nav && $this->args['show_all_options'] ) ? '<div class="wp_china_yes-expand-all" title="'. esc_html__( 'show all settings', 'wp_china_yes' ) .'"><i class="fas fa-outdent"></i></div>' : '';
|
||||
|
||||
echo ( $this->args['show_search'] ) ? '<div class="wp_china_yes-search"><input type="text" name="wp_china_yes-search" placeholder="'. esc_html__( 'Search...', 'wp_china_yes' ) .'" autocomplete="off" /></div>' : '';
|
||||
|
||||
echo '<div class="wp_china_yes-buttons">';
|
||||
echo '<input type="submit" name="'. esc_attr( $this->unique ) .'[_nonce][save]" class="button button-primary wp_china_yes-top-save wp_china_yes-save'. esc_attr( $ajax_class ) .'" value="'. esc_html__( 'Save', 'wp_china_yes' ) .'" data-save="'. esc_html__( 'Saving...', 'wp_china_yes' ) .'">';
|
||||
echo ( $this->args['show_reset_section'] ) ? '<input type="submit" name="wp_china_yes_transient[reset_section]" class="button button-secondary wp_china_yes-reset-section wp_china_yes-confirm" value="'. esc_html__( 'Reset Section', 'wp_china_yes' ) .'" data-confirm="'. esc_html__( 'Are you sure to reset this section options?', 'wp_china_yes' ) .'">' : '';
|
||||
echo ( $this->args['show_reset_all'] ) ? '<input type="submit" name="wp_china_yes_transient[reset]" class="button wp_china_yes-warning-primary wp_china_yes-reset-all wp_china_yes-confirm" value="'. ( ( $this->args['show_reset_section'] ) ? esc_html__( 'Reset All', 'wp_china_yes' ) : esc_html__( 'Reset', 'wp_china_yes' ) ) .'" data-confirm="'. esc_html__( 'Are you sure you want to reset all settings to default values?', 'wp_china_yes' ) .'">' : '';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="clear"></div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-wrapper'. esc_attr( $show_all ) .'">';
|
||||
|
||||
if ( $has_nav ) {
|
||||
|
||||
echo '<div class="wp_china_yes-nav wp_china_yes-nav-'. esc_attr( $nav_type ) .' wp_china_yes-nav-options">';
|
||||
|
||||
echo '<ul>';
|
||||
|
||||
foreach ( $this->pre_tabs as $tab ) {
|
||||
|
||||
$tab_id = sanitize_title( $tab['title'] );
|
||||
$tab_error = $this->error_check( $tab );
|
||||
$tab_icon = ( ! empty( $tab['icon'] ) ) ? '<i class="wp_china_yes-tab-icon '. esc_attr( $tab['icon'] ) .'"></i>' : '';
|
||||
|
||||
if ( ! empty( $tab['subs'] ) ) {
|
||||
|
||||
echo '<li class="wp_china_yes-tab-item">';
|
||||
|
||||
echo '<a href="#tab='. esc_attr( $tab_id ) .'" data-tab-id="'. esc_attr( $tab_id ) .'" class="wp_china_yes-arrow">'. $tab_icon . $tab['title'] . $tab_error .'</a>';
|
||||
|
||||
echo '<ul>';
|
||||
|
||||
foreach ( $tab['subs'] as $sub ) {
|
||||
|
||||
$sub_id = $tab_id .'/'. sanitize_title( $sub['title'] );
|
||||
$sub_error = $this->error_check( $sub );
|
||||
$sub_icon = ( ! empty( $sub['icon'] ) ) ? '<i class="wp_china_yes-tab-icon '. esc_attr( $sub['icon'] ) .'"></i>' : '';
|
||||
|
||||
echo '<li><a href="#tab='. esc_attr( $sub_id ) .'" data-tab-id="'. esc_attr( $sub_id ) .'">'. $sub_icon . $sub['title'] . $sub_error .'</a></li>';
|
||||
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
echo '</li>';
|
||||
|
||||
} else {
|
||||
|
||||
echo '<li class="wp_china_yes-tab-item"><a href="#tab='. esc_attr( $tab_id ) .'" data-tab-id="'. esc_attr( $tab_id ) .'">'. $tab_icon . $tab['title'] . $tab_error .'</a></li>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
echo '<div class="wp_china_yes-copyright">';
|
||||
echo '<p>Copyright © 2025 · WPCY.COM</p>';
|
||||
echo '<p>文派叶子·生生不息</p>';
|
||||
echo '</div>';
|
||||
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '<div class="wp_china_yes-content">';
|
||||
|
||||
echo '<div class="wp_china_yes-sections">';
|
||||
|
||||
foreach ( $this->pre_sections as $section ) {
|
||||
|
||||
$section_onload = ( ! $has_nav ) ? ' wp_china_yes-onload' : '';
|
||||
$section_class = ( ! empty( $section['class'] ) ) ? ' '. $section['class'] : '';
|
||||
$section_icon = ( ! empty( $section['icon'] ) ) ? '<i class="wp_china_yes-section-icon '. esc_attr( $section['icon'] ) .'"></i>' : '';
|
||||
$section_title = ( ! empty( $section['title'] ) ) ? $section['title'] : '';
|
||||
$section_parent = ( ! empty( $section['ptitle'] ) ) ? sanitize_title( $section['ptitle'] ) .'/' : '';
|
||||
$section_slug = ( ! empty( $section['title'] ) ) ? sanitize_title( $section_title ) : '';
|
||||
|
||||
echo '<div class="wp_china_yes-section hidden'. esc_attr( $section_onload . $section_class ) .'" data-section-id="'. esc_attr( $section_parent . $section_slug ) .'">';
|
||||
echo ( $has_nav ) ? '<div class="wp_china_yes-section-title"><h3>'. $section_icon . $section_title .'</h3></div>' : '';
|
||||
echo ( ! empty( $section['description'] ) ) ? '<div class="wp_china_yes-field wp_china_yes-section-description">'. $section['description'] .'</div>' : '';
|
||||
|
||||
if ( ! empty( $section['fields'] ) ) {
|
||||
|
||||
foreach ( $section['fields'] as $field ) {
|
||||
|
||||
$is_field_error = $this->error_check( $field );
|
||||
|
||||
if ( ! empty( $is_field_error ) ) {
|
||||
$field['_error'] = $is_field_error;
|
||||
}
|
||||
|
||||
if ( ! empty( $field['id'] ) ) {
|
||||
$field['default'] = $this->get_default( $field );
|
||||
}
|
||||
|
||||
$value = ( ! empty( $field['id'] ) && isset( $this->options[$field['id']] ) ) ? $this->options[$field['id']] : '';
|
||||
|
||||
WP_CHINA_YES::field( $field, $value, $this->unique, 'options' );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
echo '<div class="wp_china_yes-no-option">'. esc_html__( 'No data available.', 'wp_china_yes' ) .'</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-copyright">';
|
||||
echo '<p>此服务由 文派开源(WenPai.org) 提供生态接入。</p>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="clear"></div>';
|
||||
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo ( $has_nav && $nav_type === 'normal' ) ? '<div class="wp_china_yes-nav-background"></div>' : '';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ( ! empty( $this->args['show_footer'] ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes-footer">';
|
||||
|
||||
echo '<div class="wp_china_yes-buttons">';
|
||||
echo '<input type="submit" name="wp_china_yes_transient[save]" class="button button-primary wp_china_yes-save'. esc_attr( $ajax_class ) .'" value="'. esc_html__( 'Save', 'wp_china_yes' ) .'" data-save="'. esc_html__( 'Saving...', 'wp_china_yes' ) .'">';
|
||||
echo ( $this->args['show_reset_section'] ) ? '<input type="submit" name="wp_china_yes_transient[reset_section]" class="button button-secondary wp_china_yes-reset-section wp_china_yes-confirm" value="'. esc_html__( 'Reset Section', 'wp_china_yes' ) .'" data-confirm="'. esc_html__( 'Are you sure to reset this section options?', 'wp_china_yes' ) .'">' : '';
|
||||
echo ( $this->args['show_reset_all'] ) ? '<input type="submit" name="wp_china_yes_transient[reset]" class="button wp_china_yes-warning-primary wp_china_yes-reset-all wp_china_yes-confirm" value="'. ( ( $this->args['show_reset_section'] ) ? esc_html__( 'Reset All', 'wp_china_yes' ) : esc_html__( 'Reset', 'wp_china_yes' ) ) .'" data-confirm="'. esc_html__( 'Are you sure you want to reset all settings to default values?', 'wp_china_yes' ) .'">' : '';
|
||||
echo '</div>';
|
||||
|
||||
echo ( ! empty( $this->args['footer_text'] ) ) ? '<div class="wp_china_yes-copyright">'. $this->args['footer_text'] .'</div>' : '';
|
||||
|
||||
echo '<div class="clear"></div>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</form>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="clear"></div>';
|
||||
|
||||
echo ( ! empty( $this->args['footer_after'] ) ) ? $this->args['footer_after'] : '';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
do_action( 'wp_china_yes_options_after' );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
405
framework/classes/fields.class.php
Executable file
|
|
@ -0,0 +1,405 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Fields Class
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Fields' ) ) {
|
||||
abstract class WP_CHINA_YES_Fields extends WP_CHINA_YES_Abstract {
|
||||
|
||||
public function __construct( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
$this->field = $field;
|
||||
$this->value = $value;
|
||||
$this->unique = $unique;
|
||||
$this->where = $where;
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
public function field_name( $nested_name = '' ) {
|
||||
|
||||
$field_id = ( ! empty( $this->field['id'] ) ) ? $this->field['id'] : '';
|
||||
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $field_id .']' : $field_id;
|
||||
$field_name = ( ! empty( $this->field['name'] ) ) ? $this->field['name'] : $unique_id;
|
||||
$tag_prefix = ( ! empty( $this->field['tag_prefix'] ) ) ? $this->field['tag_prefix'] : '';
|
||||
|
||||
if ( ! empty( $tag_prefix ) ) {
|
||||
$nested_name = str_replace( '[', '['. $tag_prefix, $nested_name );
|
||||
}
|
||||
|
||||
return $field_name . $nested_name;
|
||||
|
||||
}
|
||||
|
||||
public function field_attributes( $custom_atts = array() ) {
|
||||
|
||||
$field_id = ( ! empty( $this->field['id'] ) ) ? $this->field['id'] : '';
|
||||
$attributes = ( ! empty( $this->field['attributes'] ) ) ? $this->field['attributes'] : array();
|
||||
|
||||
if ( ! empty( $field_id ) && empty( $attributes['data-depend-id'] ) ) {
|
||||
$attributes['data-depend-id'] = $field_id;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->field['placeholder'] ) ) {
|
||||
$attributes['placeholder'] = $this->field['placeholder'];
|
||||
}
|
||||
|
||||
$attributes = wp_parse_args( $attributes, $custom_atts );
|
||||
|
||||
$atts = '';
|
||||
|
||||
if ( ! empty( $attributes ) ) {
|
||||
foreach ( $attributes as $key => $value ) {
|
||||
if ( $value === 'only-key' ) {
|
||||
$atts .= ' '. esc_attr( $key );
|
||||
} else {
|
||||
$atts .= ' '. esc_attr( $key ) . '="'. esc_attr( $value ) .'"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $atts;
|
||||
|
||||
}
|
||||
|
||||
public function field_before() {
|
||||
return ( ! empty( $this->field['before'] ) ) ? '<div class="wp_china_yes-before-text">'. $this->field['before'] .'</div>' : '';
|
||||
}
|
||||
|
||||
public function field_after() {
|
||||
|
||||
$output = ( ! empty( $this->field['after'] ) ) ? '<div class="wp_china_yes-after-text">'. $this->field['after'] .'</div>' : '';
|
||||
$output .= ( ! empty( $this->field['desc'] ) ) ? '<div class="clear"></div><div class="wp_china_yes-desc-text">'. $this->field['desc'] .'</div>' : '';
|
||||
$output .= ( ! empty( $this->field['help'] ) ) ? '<div class="wp_china_yes-help"><span class="wp_china_yes-help-text">'. $this->field['help'] .'</span><i class="fas fa-question-circle"></i></div>' : '';
|
||||
$output .= ( ! empty( $this->field['_error'] ) ) ? '<div class="wp_china_yes-error-text">'. $this->field['_error'] .'</div>' : '';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
public static function field_data( $type = '', $term = false, $query_args = array() ) {
|
||||
|
||||
$options = array();
|
||||
$array_search = false;
|
||||
|
||||
// sanitize type name
|
||||
if ( in_array( $type, array( 'page', 'pages' ) ) ) {
|
||||
$option = 'page';
|
||||
} else if ( in_array( $type, array( 'post', 'posts' ) ) ) {
|
||||
$option = 'post';
|
||||
} else if ( in_array( $type, array( 'category', 'categories' ) ) ) {
|
||||
$option = 'category';
|
||||
} else if ( in_array( $type, array( 'tag', 'tags' ) ) ) {
|
||||
$option = 'post_tag';
|
||||
} else if ( in_array( $type, array( 'menu', 'menus' ) ) ) {
|
||||
$option = 'nav_menu';
|
||||
} else {
|
||||
$option = '';
|
||||
}
|
||||
|
||||
// switch type
|
||||
switch( $type ) {
|
||||
|
||||
case 'page':
|
||||
case 'pages':
|
||||
case 'post':
|
||||
case 'posts':
|
||||
|
||||
// term query required for ajax select
|
||||
if ( ! empty( $term ) ) {
|
||||
|
||||
$query = new WP_Query( wp_parse_args( $query_args, array(
|
||||
's' => $term,
|
||||
'post_type' => $option,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 25,
|
||||
) ) );
|
||||
|
||||
} else {
|
||||
|
||||
$query = new WP_Query( wp_parse_args( $query_args, array(
|
||||
'post_type' => $option,
|
||||
'post_status' => 'publish',
|
||||
) ) );
|
||||
|
||||
}
|
||||
|
||||
if ( ! is_wp_error( $query ) && ! empty( $query->posts ) ) {
|
||||
foreach ( $query->posts as $item ) {
|
||||
$options[$item->ID] = $item->post_title;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
case 'categories':
|
||||
case 'tag':
|
||||
case 'tags':
|
||||
case 'menu':
|
||||
case 'menus':
|
||||
|
||||
if ( ! empty( $term ) ) {
|
||||
|
||||
$query = new WP_Term_Query( wp_parse_args( $query_args, array(
|
||||
'search' => $term,
|
||||
'taxonomy' => $option,
|
||||
'hide_empty' => false,
|
||||
'number' => 25,
|
||||
) ) );
|
||||
|
||||
} else {
|
||||
|
||||
$query = new WP_Term_Query( wp_parse_args( $query_args, array(
|
||||
'taxonomy' => $option,
|
||||
'hide_empty' => false,
|
||||
) ) );
|
||||
|
||||
}
|
||||
|
||||
if ( ! is_wp_error( $query ) && ! empty( $query->terms ) ) {
|
||||
foreach ( $query->terms as $item ) {
|
||||
$options[$item->term_id] = $item->name;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
case 'users':
|
||||
|
||||
if ( ! empty( $term ) ) {
|
||||
|
||||
$query = new WP_User_Query( array(
|
||||
'search' => '*'. $term .'*',
|
||||
'number' => 25,
|
||||
'orderby' => 'title',
|
||||
'order' => 'ASC',
|
||||
'fields' => array( 'display_name', 'ID' )
|
||||
) );
|
||||
|
||||
} else {
|
||||
|
||||
$query = new WP_User_Query( array( 'fields' => array( 'display_name', 'ID' ) ) );
|
||||
|
||||
}
|
||||
|
||||
if ( ! is_wp_error( $query ) && ! empty( $query->get_results() ) ) {
|
||||
foreach ( $query->get_results() as $item ) {
|
||||
$options[$item->ID] = $item->display_name;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'sidebar':
|
||||
case 'sidebars':
|
||||
|
||||
global $wp_registered_sidebars;
|
||||
|
||||
if ( ! empty( $wp_registered_sidebars ) ) {
|
||||
foreach ( $wp_registered_sidebars as $sidebar ) {
|
||||
$options[$sidebar['id']] = $sidebar['name'];
|
||||
}
|
||||
}
|
||||
|
||||
$array_search = true;
|
||||
|
||||
break;
|
||||
|
||||
case 'role':
|
||||
case 'roles':
|
||||
|
||||
global $wp_roles;
|
||||
|
||||
if ( ! empty( $wp_roles ) ) {
|
||||
if ( ! empty( $wp_roles->roles ) ) {
|
||||
foreach ( $wp_roles->roles as $role_key => $role_value ) {
|
||||
$options[$role_key] = $role_value['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$array_search = true;
|
||||
|
||||
break;
|
||||
|
||||
case 'post_type':
|
||||
case 'post_types':
|
||||
|
||||
$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
|
||||
|
||||
if ( ! is_wp_error( $post_types ) && ! empty( $post_types ) ) {
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$options[$post_type->name] = $post_type->labels->name;
|
||||
}
|
||||
}
|
||||
|
||||
$array_search = true;
|
||||
|
||||
break;
|
||||
|
||||
case 'location':
|
||||
case 'locations':
|
||||
|
||||
$nav_menus = get_registered_nav_menus();
|
||||
|
||||
if ( ! is_wp_error( $nav_menus ) && ! empty( $nav_menus ) ) {
|
||||
foreach ( $nav_menus as $nav_menu_key => $nav_menu_name ) {
|
||||
$options[$nav_menu_key] = $nav_menu_name;
|
||||
}
|
||||
}
|
||||
|
||||
$array_search = true;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
if ( is_callable( $type ) ) {
|
||||
if ( ! empty( $term ) ) {
|
||||
$options = call_user_func( $type, $query_args );
|
||||
} else {
|
||||
$options = call_user_func( $type, $term, $query_args );
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Array search by "term"
|
||||
if ( ! empty( $term ) && ! empty( $options ) && ! empty( $array_search ) ) {
|
||||
$options = preg_grep( '/'. $term .'/i', $options );
|
||||
}
|
||||
|
||||
// Make multidimensional array for ajax search
|
||||
if ( ! empty( $term ) && ! empty( $options ) ) {
|
||||
$arr = array();
|
||||
foreach ( $options as $option_key => $option_value ) {
|
||||
$arr[] = array( 'value' => $option_key, 'text' => $option_value );
|
||||
}
|
||||
$options = $arr;
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
||||
}
|
||||
|
||||
public function field_wp_query_data_title( $type, $values ) {
|
||||
|
||||
$options = array();
|
||||
|
||||
if ( ! empty( $values ) && is_array( $values ) ) {
|
||||
|
||||
foreach ( $values as $value ) {
|
||||
|
||||
$options[$value] = ucfirst( $value );
|
||||
|
||||
switch( $type ) {
|
||||
|
||||
case 'post':
|
||||
case 'posts':
|
||||
case 'page':
|
||||
case 'pages':
|
||||
|
||||
$title = get_the_title( $value );
|
||||
|
||||
if ( ! is_wp_error( $title ) && ! empty( $title ) ) {
|
||||
$options[$value] = $title;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
case 'categories':
|
||||
case 'tag':
|
||||
case 'tags':
|
||||
case 'menu':
|
||||
case 'menus':
|
||||
|
||||
$term = get_term( $value );
|
||||
|
||||
if ( ! is_wp_error( $term ) && ! empty( $term ) ) {
|
||||
$options[$value] = $term->name;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'user':
|
||||
case 'users':
|
||||
|
||||
$user = get_user_by( 'id', $value );
|
||||
|
||||
if ( ! is_wp_error( $user ) && ! empty( $user ) ) {
|
||||
$options[$value] = $user->display_name;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'sidebar':
|
||||
case 'sidebars':
|
||||
|
||||
global $wp_registered_sidebars;
|
||||
|
||||
if ( ! empty( $wp_registered_sidebars[$value] ) ) {
|
||||
$options[$value] = $wp_registered_sidebars[$value]['name'];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'role':
|
||||
case 'roles':
|
||||
|
||||
global $wp_roles;
|
||||
|
||||
if ( ! empty( $wp_roles ) && ! empty( $wp_roles->roles ) && ! empty( $wp_roles->roles[$value] ) ) {
|
||||
$options[$value] = $wp_roles->roles[$value]['name'];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'post_type':
|
||||
case 'post_types':
|
||||
|
||||
$post_types = get_post_types( array( 'show_in_nav_menus' => true ) );
|
||||
|
||||
if ( ! is_wp_error( $post_types ) && ! empty( $post_types ) && ! empty( $post_types[$value] ) ) {
|
||||
$options[$value] = ucfirst( $value );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'location':
|
||||
case 'locations':
|
||||
|
||||
$nav_menus = get_registered_nav_menus();
|
||||
|
||||
if ( ! is_wp_error( $nav_menus ) && ! empty( $nav_menus ) && ! empty( $nav_menus[$value] ) ) {
|
||||
$options[$value] = $nav_menus[$value];
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
if ( is_callable( $type .'_title' ) ) {
|
||||
$options[$value] = call_user_func( $type .'_title', $value );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
804
framework/classes/setup.class.php
Executable file
|
|
@ -0,0 +1,804 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Setup Class
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Setup' ) ) {
|
||||
class WP_CHINA_YES_Setup {
|
||||
|
||||
// Default constants
|
||||
public static $premium = false;
|
||||
public static $version = '2.3.1';
|
||||
public static $dir = '';
|
||||
public static $url = '';
|
||||
public static $css = '';
|
||||
public static $file = '';
|
||||
public static $enqueue = false;
|
||||
public static $webfonts = array();
|
||||
public static $subsets = array();
|
||||
public static $inited = array();
|
||||
public static $fields = array();
|
||||
public static $args = array(
|
||||
'admin_options' => array(),
|
||||
'customize_options' => array(),
|
||||
'metabox_options' => array(),
|
||||
'nav_menu_options' => array(),
|
||||
'profile_options' => array(),
|
||||
'taxonomy_options' => array(),
|
||||
'widget_options' => array(),
|
||||
'comment_options' => array(),
|
||||
'shortcode_options' => array(),
|
||||
);
|
||||
|
||||
// Shortcode instances
|
||||
public static $shortcode_instances = array();
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
public static function init( $file = __FILE__, $premium = false ) {
|
||||
|
||||
// Set file constant
|
||||
self::$file = $file;
|
||||
|
||||
// Set file constant
|
||||
self::$premium = $premium;
|
||||
|
||||
// Set constants
|
||||
self::constants();
|
||||
|
||||
// Include files
|
||||
self::includes();
|
||||
|
||||
if ( is_null( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
|
||||
}
|
||||
|
||||
// Initalize
|
||||
public function __construct() {
|
||||
|
||||
// Init action
|
||||
do_action( 'wp_china_yes_init' );
|
||||
|
||||
// Setup textdomain on init action
|
||||
add_action( 'init', array( 'WP_CHINA_YES_Setup', 'textdomain' ) );
|
||||
|
||||
add_action( 'after_setup_theme', array( 'WP_CHINA_YES', 'setup' ) );
|
||||
add_action( 'init', array( 'WP_CHINA_YES', 'setup' ) );
|
||||
add_action( 'switch_theme', array( 'WP_CHINA_YES', 'setup' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( 'WP_CHINA_YES', 'add_admin_enqueue_scripts' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( 'WP_CHINA_YES', 'add_typography_enqueue_styles' ), 80 );
|
||||
add_action( 'wp_head', array( 'WP_CHINA_YES', 'add_custom_css' ), 80 );
|
||||
add_filter( 'admin_body_class', array( 'WP_CHINA_YES', 'add_admin_body_class' ) );
|
||||
|
||||
}
|
||||
|
||||
// Setup frameworks
|
||||
public static function setup() {
|
||||
|
||||
// Setup admin option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Options' ) && ! empty( self::$args['admin_options'] ) ) {
|
||||
foreach ( self::$args['admin_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Options::instance( $key, $params );
|
||||
|
||||
if ( ! empty( $value['show_in_customizer'] ) ) {
|
||||
$value['output_css'] = false;
|
||||
$value['enqueue_webfont'] = false;
|
||||
self::$args['customize_options'][$key] = $value;
|
||||
self::$inited[$key] = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup customize option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Customize_Options' ) && ! empty( self::$args['customize_options'] ) ) {
|
||||
foreach ( self::$args['customize_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Customize_Options::instance( $key, $params );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup metabox option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Metabox' ) && ! empty( self::$args['metabox_options'] ) ) {
|
||||
foreach ( self::$args['metabox_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Metabox::instance( $key, $params );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup nav menu option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Nav_Menu_Options' ) && ! empty( self::$args['nav_menu_options'] ) ) {
|
||||
foreach ( self::$args['nav_menu_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Nav_Menu_Options::instance( $key, $params );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup profile option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Profile_Options' ) && ! empty( self::$args['profile_options'] ) ) {
|
||||
foreach ( self::$args['profile_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Profile_Options::instance( $key, $params );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup taxonomy option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Taxonomy_Options' ) && ! empty( self::$args['taxonomy_options'] ) ) {
|
||||
$taxonomy = ( isset( $_GET['taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ) : '';
|
||||
foreach ( self::$args['taxonomy_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Taxonomy_Options::instance( $key, $params );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup widget option framework
|
||||
if ( class_exists( 'WP_CHINA_YES_Widget' ) && class_exists( 'WP_Widget_Factory' ) && ! empty( self::$args['widget_options'] ) ) {
|
||||
$wp_widget_factory = new WP_Widget_Factory();
|
||||
global $wp_widget_factory;
|
||||
foreach ( self::$args['widget_options'] as $key => $value ) {
|
||||
if ( ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
self::$inited[$key] = true;
|
||||
$wp_widget_factory->register( WP_CHINA_YES_Widget::instance( $key, $value ) );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup comment option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Comment_Metabox' ) && ! empty( self::$args['comment_options'] ) ) {
|
||||
foreach ( self::$args['comment_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Comment_Metabox::instance( $key, $params );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup shortcode option framework
|
||||
$params = array();
|
||||
if ( class_exists( 'WP_CHINA_YES_Shortcoder' ) && ! empty( self::$args['shortcode_options'] ) ) {
|
||||
foreach ( self::$args['shortcode_options'] as $key => $value ) {
|
||||
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) {
|
||||
|
||||
$params['args'] = $value;
|
||||
$params['sections'] = self::$args['sections'][$key];
|
||||
self::$inited[$key] = true;
|
||||
|
||||
WP_CHINA_YES_Shortcoder::instance( $key, $params );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Once editor setup for gutenberg and media buttons
|
||||
if ( class_exists( 'WP_CHINA_YES_Shortcoder' ) && ! empty( self::$shortcode_instances ) ) {
|
||||
foreach ( self::$shortcode_instances as $instance ) {
|
||||
if ( ! empty( $instance['show_in_editor'] ) ) {
|
||||
WP_CHINA_YES_Shortcoder::once_editor_setup();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
do_action( 'wp_china_yes_loaded' );
|
||||
|
||||
}
|
||||
|
||||
// Create options
|
||||
public static function createOptions( $id, $args = array() ) {
|
||||
self::$args['admin_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create customize options
|
||||
public static function createCustomizeOptions( $id, $args = array() ) {
|
||||
self::$args['customize_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create metabox options
|
||||
public static function createMetabox( $id, $args = array() ) {
|
||||
self::$args['metabox_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create menu options
|
||||
public static function createNavMenuOptions( $id, $args = array() ) {
|
||||
self::$args['nav_menu_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create shortcoder options
|
||||
public static function createShortcoder( $id, $args = array() ) {
|
||||
self::$args['shortcode_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create taxonomy options
|
||||
public static function createTaxonomyOptions( $id, $args = array() ) {
|
||||
self::$args['taxonomy_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create profile options
|
||||
public static function createProfileOptions( $id, $args = array() ) {
|
||||
self::$args['profile_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create widget
|
||||
public static function createWidget( $id, $args = array() ) {
|
||||
self::$args['widget_options'][$id] = $args;
|
||||
self::set_used_fields( $args );
|
||||
}
|
||||
|
||||
// Create comment metabox
|
||||
public static function createCommentMetabox( $id, $args = array() ) {
|
||||
self::$args['comment_options'][$id] = $args;
|
||||
}
|
||||
|
||||
// Create section
|
||||
public static function createSection( $id, $sections ) {
|
||||
self::$args['sections'][$id][] = $sections;
|
||||
self::set_used_fields( $sections );
|
||||
}
|
||||
|
||||
// Set directory constants
|
||||
public static function constants() {
|
||||
|
||||
// We need this path-finder code for set URL of framework
|
||||
$dirname = str_replace( '//', '/', wp_normalize_path( dirname( dirname( self::$file ) ) ) );
|
||||
$theme_dir = str_replace( '//', '/', wp_normalize_path( get_parent_theme_file_path() ) );
|
||||
$plugin_dir = str_replace( '//', '/', wp_normalize_path( WP_PLUGIN_DIR ) );
|
||||
$plugin_dir = str_replace( '/opt/bitnami', '/bitnami', $plugin_dir );
|
||||
$located_plugin = ( preg_match( '#'. self::sanitize_dirname( $plugin_dir ) .'#', self::sanitize_dirname( $dirname ) ) ) ? true : false;
|
||||
$directory = ( $located_plugin ) ? $plugin_dir : $theme_dir;
|
||||
$directory_uri = ( $located_plugin ) ? WP_PLUGIN_URL : get_parent_theme_file_uri();
|
||||
$foldername = str_replace( $directory, '', $dirname );
|
||||
$protocol_uri = ( is_ssl() ) ? 'https' : 'http';
|
||||
$directory_uri = set_url_scheme( $directory_uri, $protocol_uri );
|
||||
|
||||
self::$dir = $dirname;
|
||||
self::$url = $directory_uri . $foldername;
|
||||
|
||||
}
|
||||
|
||||
// Include file helper
|
||||
public static function include_plugin_file( $file, $load = true ) {
|
||||
|
||||
$path = '';
|
||||
$file = ltrim( $file, '/' );
|
||||
$override = apply_filters( 'wp_china_yes_override', 'wp_china_yes-override' );
|
||||
|
||||
if ( file_exists( get_parent_theme_file_path( $override .'/'. $file ) ) ) {
|
||||
$path = get_parent_theme_file_path( $override .'/'. $file );
|
||||
} elseif ( file_exists( get_theme_file_path( $override .'/'. $file ) ) ) {
|
||||
$path = get_theme_file_path( $override .'/'. $file );
|
||||
} elseif ( file_exists( self::$dir .'/'. $override .'/'. $file ) ) {
|
||||
$path = self::$dir .'/'. $override .'/'. $file;
|
||||
} elseif ( file_exists( self::$dir .'/'. $file ) ) {
|
||||
$path = self::$dir .'/'. $file;
|
||||
}
|
||||
|
||||
if ( ! empty( $path ) && ! empty( $file ) && $load ) {
|
||||
|
||||
global $wp_query;
|
||||
|
||||
if ( is_object( $wp_query ) && function_exists( 'load_template' ) ) {
|
||||
|
||||
load_template( $path, true );
|
||||
|
||||
} else {
|
||||
|
||||
require_once( $path );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
return self::$dir .'/'. $file;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Is active plugin helper
|
||||
public static function is_active_plugin( $file = '' ) {
|
||||
return in_array( $file, (array) get_option( 'active_plugins', array() ) );
|
||||
}
|
||||
|
||||
// Sanitize dirname
|
||||
public static function sanitize_dirname( $dirname ) {
|
||||
return preg_replace( '/[^A-Za-z]/', '', $dirname );
|
||||
}
|
||||
|
||||
// Set url constant
|
||||
public static function include_plugin_url( $file ) {
|
||||
return esc_url( self::$url ) .'/'. ltrim( $file, '/' );
|
||||
}
|
||||
|
||||
// Include files
|
||||
public static function includes() {
|
||||
|
||||
// Include common functions
|
||||
self::include_plugin_file( 'functions/actions.php' );
|
||||
self::include_plugin_file( 'functions/helpers.php' );
|
||||
self::include_plugin_file( 'functions/sanitize.php' );
|
||||
self::include_plugin_file( 'functions/validate.php' );
|
||||
|
||||
// Include free version classes
|
||||
self::include_plugin_file( 'classes/abstract.class.php' );
|
||||
self::include_plugin_file( 'classes/fields.class.php' );
|
||||
self::include_plugin_file( 'classes/admin-options.class.php' );
|
||||
|
||||
// Include premium version classes
|
||||
if ( self::$premium ) {
|
||||
self::include_plugin_file( 'classes/customize-options.class.php' );
|
||||
self::include_plugin_file( 'classes/metabox-options.class.php' );
|
||||
self::include_plugin_file( 'classes/nav-menu-options.class.php' );
|
||||
self::include_plugin_file( 'classes/profile-options.class.php' );
|
||||
self::include_plugin_file( 'classes/shortcode-options.class.php' );
|
||||
self::include_plugin_file( 'classes/taxonomy-options.class.php' );
|
||||
self::include_plugin_file( 'classes/widget-options.class.php' );
|
||||
self::include_plugin_file( 'classes/comment-options.class.php' );
|
||||
}
|
||||
|
||||
// Include all framework fields
|
||||
$fields = apply_filters( 'wp_china_yes_fields', array(
|
||||
'accordion',
|
||||
'background',
|
||||
'backup',
|
||||
'border',
|
||||
'button_set',
|
||||
'callback',
|
||||
'checkbox',
|
||||
'code_editor',
|
||||
'color',
|
||||
'color_group',
|
||||
'content',
|
||||
'date',
|
||||
'datetime',
|
||||
'dimensions',
|
||||
'fieldset',
|
||||
'gallery',
|
||||
'group',
|
||||
'heading',
|
||||
'icon',
|
||||
'image_select',
|
||||
'link',
|
||||
'link_color',
|
||||
'map',
|
||||
'media',
|
||||
'notice',
|
||||
'number',
|
||||
'palette',
|
||||
'radio',
|
||||
'repeater',
|
||||
'select',
|
||||
'slider',
|
||||
'sortable',
|
||||
'sorter',
|
||||
'spacing',
|
||||
'spinner',
|
||||
'subheading',
|
||||
'submessage',
|
||||
'switcher',
|
||||
'tabbed',
|
||||
'text',
|
||||
'textarea',
|
||||
'typography',
|
||||
'upload',
|
||||
'wp_editor',
|
||||
) );
|
||||
|
||||
if ( ! empty( $fields ) ) {
|
||||
foreach ( $fields as $field ) {
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_'. $field ) && class_exists( 'WP_CHINA_YES_Fields' ) ) {
|
||||
self::include_plugin_file( 'fields/'. $field .'/'. $field .'.php' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Setup textdomain
|
||||
public static function textdomain() {
|
||||
load_textdomain( 'wp_china_yes', self::$dir .'/languages/'. get_locale() .'.mo' );
|
||||
}
|
||||
|
||||
// Set all of used fields
|
||||
public static function set_used_fields( $sections ) {
|
||||
|
||||
if ( ! empty( $sections['fields'] ) ) {
|
||||
|
||||
foreach ( $sections['fields'] as $field ) {
|
||||
|
||||
if ( ! empty( $field['fields'] ) ) {
|
||||
self::set_used_fields( $field );
|
||||
}
|
||||
|
||||
if ( ! empty( $field['tabs'] ) ) {
|
||||
self::set_used_fields( array( 'fields' => $field['tabs'] ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $field['accordions'] ) ) {
|
||||
self::set_used_fields( array( 'fields' => $field['accordions'] ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $field['elements'] ) ) {
|
||||
self::set_used_fields( array( 'fields' => $field['elements'] ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $field['type'] ) ) {
|
||||
self::$fields[$field['type']] = $field;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Enqueue admin and fields styles and scripts
|
||||
public static function add_admin_enqueue_scripts() {
|
||||
|
||||
if ( ! self::$enqueue ) {
|
||||
|
||||
// Loads scripts and styles only when needed
|
||||
$wpscreen = get_current_screen();
|
||||
|
||||
if ( ! empty( self::$args['admin_options'] ) ) {
|
||||
foreach ( self::$args['admin_options'] as $argument ) {
|
||||
if ( substr( $wpscreen->id, -strlen( $argument['menu_slug'] ) ) === $argument['menu_slug'] ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( self::$args['metabox_options'] ) ) {
|
||||
foreach ( self::$args['metabox_options'] as $argument ) {
|
||||
if ( in_array( $wpscreen->post_type, (array) $argument['post_type'] ) ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( self::$args['taxonomy_options'] ) ) {
|
||||
foreach ( self::$args['taxonomy_options'] as $argument ) {
|
||||
if ( in_array( $wpscreen->taxonomy, (array) $argument['taxonomy'] ) ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( self::$shortcode_instances ) ) {
|
||||
foreach ( self::$shortcode_instances as $argument ) {
|
||||
if ( ( $argument['show_in_editor'] && $wpscreen->base === 'post' ) || $argument['show_in_custom'] ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( self::$args['widget_options'] ) && ( $wpscreen->id === 'widgets' || $wpscreen->id === 'customize' ) ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
|
||||
if ( ! empty( self::$args['customize_options'] ) && $wpscreen->id === 'customize' ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
|
||||
if ( ! empty( self::$args['nav_menu_options'] ) && $wpscreen->id === 'nav-menus' ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
|
||||
if ( ! empty( self::$args['profile_options'] ) && ( $wpscreen->id === 'profile' || $wpscreen->id === 'user-edit' ) ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
|
||||
if ( ! empty( self::$args['comment_options'] ) && $wpscreen->id === 'comment' ) {
|
||||
self::$enqueue = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! apply_filters( 'wp_china_yes_enqueue_assets', self::$enqueue ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Admin utilities
|
||||
wp_enqueue_media();
|
||||
|
||||
// Wp color picker
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
wp_enqueue_script( 'wp-color-picker' );
|
||||
|
||||
// Font awesome 4 and 5 loader
|
||||
if ( apply_filters( 'wp_china_yes_fa4', false ) ) {
|
||||
wp_enqueue_style( 'wp_china_yes-fa', 'https://jsd.admincdn.com/npm/font-awesome@4.7.0/css/font-awesome.min.css', array(), '4.7.0', 'all' );
|
||||
} else {
|
||||
wp_enqueue_style( 'wp_china_yes-fa5', 'https://jsd.admincdn.com/npm/@fortawesome/fontawesome-free@5.15.4/css/all.min.css', array(), '5.15.5', 'all' );
|
||||
wp_enqueue_style( 'wp_china_yes-fa5-v4-shims', 'https://jsd.admincdn.com/npm/@fortawesome/fontawesome-free@5.15.4/css/v4-shims.min.css', array(), '5.15.5', 'all' );
|
||||
}
|
||||
|
||||
// Iconsax font icon loader
|
||||
wp_enqueue_style( 'wp_china_yes-iconsax', 'https://jsd.admincdn.com/npm/iconsax-font-icon@1.1.0/dist/icons.min.css', array(), '1.1.0', 'all' );
|
||||
|
||||
|
||||
// Check for developer mode
|
||||
$min = ( self::$premium && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
// Main style
|
||||
wp_enqueue_style( 'wp_china_yes', self::include_plugin_url( 'assets/css/style'. $min .'.css' ), array(), self::$version, 'all' );
|
||||
|
||||
// Main RTL styles
|
||||
if ( is_rtl() ) {
|
||||
wp_enqueue_style( 'wp_china_yes-rtl', self::include_plugin_url( 'assets/css/style-rtl'. $min .'.css' ), array(), self::$version, 'all' );
|
||||
}
|
||||
|
||||
// Main scripts
|
||||
wp_enqueue_script( 'wp_china_yes-plugins', self::include_plugin_url( 'assets/js/plugins'. $min .'.js' ), array(), self::$version, true );
|
||||
wp_enqueue_script( 'wp_china_yes', self::include_plugin_url( 'assets/js/main'. $min .'.js' ), array( 'wp_china_yes-plugins' ), self::$version, true );
|
||||
|
||||
// Main variables
|
||||
wp_localize_script( 'wp_china_yes', 'wp_china_yes_vars', array(
|
||||
'color_palette' => apply_filters( 'wp_china_yes_color_palette', array() ),
|
||||
'i18n' => array(
|
||||
'confirm' => esc_html__( 'Are you sure?', 'wp_china_yes' ),
|
||||
'typing_text' => esc_html__( 'Please enter %s or more characters', 'wp_china_yes' ),
|
||||
'searching_text' => esc_html__( 'Searching...', 'wp_china_yes' ),
|
||||
'no_results_text' => esc_html__( 'No results found.', 'wp_china_yes' ),
|
||||
),
|
||||
) );
|
||||
|
||||
// Enqueue fields scripts and styles
|
||||
$enqueued = array();
|
||||
|
||||
if ( ! empty( self::$fields ) ) {
|
||||
foreach ( self::$fields as $field ) {
|
||||
if ( ! empty( $field['type'] ) ) {
|
||||
$classname = 'WP_CHINA_YES_Field_' . $field['type'];
|
||||
if ( class_exists( $classname ) && method_exists( $classname, 'enqueue' ) ) {
|
||||
$instance = new $classname( $field );
|
||||
if ( method_exists( $classname, 'enqueue' ) ) {
|
||||
$instance->enqueue();
|
||||
}
|
||||
unset( $instance );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_action( 'wp_china_yes_enqueue' );
|
||||
|
||||
}
|
||||
|
||||
// Add typography enqueue styles to front page
|
||||
public static function add_typography_enqueue_styles() {
|
||||
|
||||
if ( ! empty( self::$webfonts ) ) {
|
||||
|
||||
if ( ! empty( self::$webfonts['enqueue'] ) ) {
|
||||
|
||||
$query = array();
|
||||
$fonts = array();
|
||||
|
||||
foreach ( self::$webfonts['enqueue'] as $family => $styles ) {
|
||||
$fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
|
||||
}
|
||||
|
||||
if ( ! empty( $fonts ) ) {
|
||||
$query['family'] = implode( '%7C', $fonts );
|
||||
}
|
||||
|
||||
if ( ! empty( self::$subsets ) ) {
|
||||
$query['subset'] = implode( ',', self::$subsets );
|
||||
}
|
||||
|
||||
$query['display'] = 'swap';
|
||||
|
||||
wp_enqueue_style( 'wp_china_yes-google-web-fonts', esc_url( add_query_arg( $query, '//fonts.googleapis.com/css' ) ), array(), null );
|
||||
|
||||
}
|
||||
|
||||
if ( ! empty( self::$webfonts['async'] ) ) {
|
||||
|
||||
$fonts = array();
|
||||
|
||||
foreach ( self::$webfonts['async'] as $family => $styles ) {
|
||||
$fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' );
|
||||
}
|
||||
|
||||
wp_enqueue_script( 'wp_china_yes-google-web-fonts', esc_url( '//ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js' ), array(), null );
|
||||
|
||||
wp_localize_script( 'wp_china_yes-google-web-fonts', 'WebFontConfig', array( 'google' => array( 'families' => $fonts ) ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add admin body class
|
||||
public static function add_admin_body_class( $classes ) {
|
||||
|
||||
if ( apply_filters( 'wp_china_yes_fa4', false ) ) {
|
||||
$classes .= 'wp_china_yes-fa5-shims';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
|
||||
}
|
||||
|
||||
// Add custom css to front page
|
||||
public static function add_custom_css() {
|
||||
|
||||
if ( ! empty( self::$css ) ) {
|
||||
echo '<style type="text/css">'. wp_strip_all_tags( self::$css ) .'</style>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Add a new framework field
|
||||
public static function field( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
|
||||
// Check for unallow fields
|
||||
if ( ! empty( $field['_notice'] ) ) {
|
||||
|
||||
$field_type = $field['type'];
|
||||
|
||||
$field = array();
|
||||
$field['content'] = esc_html__( 'Oops! Not allowed.', 'wp_china_yes' ) .' <strong>('. $field_type .')</strong>';
|
||||
$field['type'] = 'notice';
|
||||
$field['style'] = 'danger';
|
||||
|
||||
}
|
||||
|
||||
$depend = '';
|
||||
$visible = '';
|
||||
$unique = ( ! empty( $unique ) ) ? $unique : '';
|
||||
$class = ( ! empty( $field['class'] ) ) ? ' ' . esc_attr( $field['class'] ) : '';
|
||||
$is_pseudo = ( ! empty( $field['pseudo'] ) ) ? ' wp_china_yes-pseudo-field' : '';
|
||||
$field_type = ( ! empty( $field['type'] ) ) ? esc_attr( $field['type'] ) : '';
|
||||
|
||||
if ( ! empty( $field['dependency'] ) ) {
|
||||
|
||||
$dependency = $field['dependency'];
|
||||
$depend_visible = '';
|
||||
$data_controller = '';
|
||||
$data_condition = '';
|
||||
$data_value = '';
|
||||
$data_global = '';
|
||||
|
||||
if ( is_array( $dependency[0] ) ) {
|
||||
$data_controller = implode( '|', array_column( $dependency, 0 ) );
|
||||
$data_condition = implode( '|', array_column( $dependency, 1 ) );
|
||||
$data_value = implode( '|', array_column( $dependency, 2 ) );
|
||||
$data_global = implode( '|', array_column( $dependency, 3 ) );
|
||||
$depend_visible = implode( '|', array_column( $dependency, 4 ) );
|
||||
} else {
|
||||
$data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : '';
|
||||
$data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : '';
|
||||
$data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : '';
|
||||
$data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : '';
|
||||
$depend_visible = ( ! empty( $dependency[4] ) ) ? $dependency[4] : '';
|
||||
}
|
||||
|
||||
$depend .= ' data-controller="'. esc_attr( $data_controller ) .'"';
|
||||
$depend .= ' data-condition="'. esc_attr( $data_condition ) .'"';
|
||||
$depend .= ' data-value="'. esc_attr( $data_value ) .'"';
|
||||
$depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : '';
|
||||
|
||||
$visible = ( ! empty( $depend_visible ) ) ? ' wp_china_yes-depend-visible' : ' wp_china_yes-depend-hidden';
|
||||
|
||||
}
|
||||
|
||||
// These attributes has been sanitized above.
|
||||
echo '<div class="wp_china_yes-field wp_china_yes-field-'. $field_type . $is_pseudo . $class . $visible .'"'. $depend .'>';
|
||||
|
||||
if ( ! empty( $field_type ) ) {
|
||||
|
||||
if ( ! empty( $field['title'] ) ) {
|
||||
echo '<div class="wp_china_yes-title">';
|
||||
echo '<h4>'. $field['title'] .'</h4>';
|
||||
echo ( ! empty( $field['subtitle'] ) ) ? '<div class="wp_china_yes-subtitle-text">'. $field['subtitle'] .'</div>' : '';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo ( ! empty( $field['title'] ) ) ? '<div class="wp_china_yes-fieldset">' : '';
|
||||
|
||||
$value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value;
|
||||
$value = ( isset( $field['value'] ) ) ? $field['value'] : $value;
|
||||
|
||||
$classname = 'WP_CHINA_YES_Field_'. $field_type;
|
||||
|
||||
if ( class_exists( $classname ) ) {
|
||||
$instance = new $classname( $field, $value, $unique, $where, $parent );
|
||||
$instance->render();
|
||||
} else {
|
||||
echo '<p>'. esc_html__( 'Field not found!', 'wp_china_yes' ) .'</p>';
|
||||
}
|
||||
|
||||
} else {
|
||||
echo '<p>'. esc_html__( 'Field not found!', 'wp_china_yes' ) .'</p>';
|
||||
}
|
||||
|
||||
echo ( ! empty( $field['title'] ) ) ? '</div>' : '';
|
||||
echo '<div class="clear"></div>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WP_CHINA_YES_Setup::init( __FILE__, false );
|
||||
|
||||
/**
|
||||
*
|
||||
* Extended Setup Class for Shortland
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES' ) ) {
|
||||
class WP_CHINA_YES extends WP_CHINA_YES_Setup{}
|
||||
}
|
||||
64
framework/fields/accordion/accordion.php
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: accordion
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_accordion' ) ) {
|
||||
class WP_CHINA_YES_Field_accordion extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$unallows = array( 'accordion' );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes-accordion-items" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
|
||||
foreach ( $this->field['accordions'] as $key => $accordion ) {
|
||||
|
||||
echo '<div class="wp_china_yes-accordion-item">';
|
||||
|
||||
$icon = ( ! empty( $accordion['icon'] ) ) ? 'wp_china_yes--icon '. $accordion['icon'] : 'wp_china_yes-accordion-icon fas fa-angle-right';
|
||||
|
||||
echo '<h4 class="wp_china_yes-accordion-title">';
|
||||
echo '<i class="'. esc_attr( $icon ) .'"></i>';
|
||||
echo esc_html( $accordion['title'] );
|
||||
echo '</h4>';
|
||||
|
||||
echo '<div class="wp_china_yes-accordion-content">';
|
||||
|
||||
foreach ( $accordion['fields'] as $field ) {
|
||||
|
||||
if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
|
||||
|
||||
$field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
|
||||
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
|
||||
$field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
|
||||
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_value, $unique_id, 'field/accordion' );
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
340
framework/fields/background/background.php
Executable file
|
|
@ -0,0 +1,340 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: background
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_background' ) ) {
|
||||
class WP_CHINA_YES_Field_background extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'background_color' => true,
|
||||
'background_image' => true,
|
||||
'background_position' => true,
|
||||
'background_repeat' => true,
|
||||
'background_attachment' => true,
|
||||
'background_size' => true,
|
||||
'background_origin' => false,
|
||||
'background_clip' => false,
|
||||
'background_blend_mode' => false,
|
||||
'background_gradient' => false,
|
||||
'background_gradient_color' => true,
|
||||
'background_gradient_direction' => true,
|
||||
'background_image_preview' => true,
|
||||
'background_auto_attributes' => false,
|
||||
'compact' => false,
|
||||
'background_image_library' => 'image',
|
||||
'background_image_placeholder' => esc_html__( 'Not selected', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
if ( $args['compact'] ) {
|
||||
$args['background_color'] = false;
|
||||
$args['background_auto_attributes'] = true;
|
||||
}
|
||||
|
||||
$default_value = array(
|
||||
'background-color' => '',
|
||||
'background-image' => '',
|
||||
'background-position' => '',
|
||||
'background-repeat' => '',
|
||||
'background-attachment' => '',
|
||||
'background-size' => '',
|
||||
'background-origin' => '',
|
||||
'background-clip' => '',
|
||||
'background-blend-mode' => '',
|
||||
'background-gradient-color' => '',
|
||||
'background-gradient-direction' => '',
|
||||
);
|
||||
|
||||
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
|
||||
|
||||
$this->value = wp_parse_args( $this->value, $default_value );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes--background-colors">';
|
||||
|
||||
//
|
||||
// Background Color
|
||||
if ( ! empty( $args['background_color'] ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes--color">';
|
||||
|
||||
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="wp_china_yes--title">'. esc_html__( 'From', 'wp_china_yes' ) .'</div>' : '';
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-color',
|
||||
'type' => 'color',
|
||||
'default' => $default_value['background-color'],
|
||||
), $this->value['background-color'], $this->field_name(), 'field/background' );
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Gradient Color
|
||||
if ( ! empty( $args['background_gradient_color'] ) && ! empty( $args['background_gradient'] ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes--color">';
|
||||
|
||||
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="wp_china_yes--title">'. esc_html__( 'To', 'wp_china_yes' ) .'</div>' : '';
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-gradient-color',
|
||||
'type' => 'color',
|
||||
'default' => $default_value['background-gradient-color'],
|
||||
), $this->value['background-gradient-color'], $this->field_name(), 'field/background' );
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Gradient Direction
|
||||
if ( ! empty( $args['background_gradient_direction'] ) && ! empty( $args['background_gradient'] ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes--color">';
|
||||
|
||||
echo ( ! empty( $args['background_gradient'] ) ) ? '<div class="wp_china_yes---title">'. esc_html__( 'Direction', 'wp_china_yes' ) .'</div>' : '';
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-gradient-direction',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Gradient Direction', 'wp_china_yes' ),
|
||||
'to bottom' => esc_html__( '⇓ top to bottom', 'wp_china_yes' ),
|
||||
'to right' => esc_html__( '⇒ left to right', 'wp_china_yes' ),
|
||||
'135deg' => esc_html__( '⇘ corner top to right', 'wp_china_yes' ),
|
||||
'-135deg' => esc_html__( '⇙ corner top to left', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-gradient-direction'], $this->field_name(), 'field/background' );
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
//
|
||||
// Background Image
|
||||
if ( ! empty( $args['background_image'] ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes--background-image">';
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-image',
|
||||
'type' => 'media',
|
||||
'class' => 'wp_china_yes-assign-field-background',
|
||||
'library' => $args['background_image_library'],
|
||||
'preview' => $args['background_image_preview'],
|
||||
'placeholder' => $args['background_image_placeholder'],
|
||||
'attributes' => array( 'data-depend-id' => $this->field['id'] ),
|
||||
), $this->value['background-image'], $this->field_name(), 'field/background' );
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
$auto_class = ( ! empty( $args['background_auto_attributes'] ) ) ? ' wp_china_yes--auto-attributes' : '';
|
||||
$hidden_class = ( ! empty( $args['background_auto_attributes'] ) && empty( $this->value['background-image']['url'] ) ) ? ' wp_china_yes--attributes-hidden' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--background-attributes'. esc_attr( $auto_class . $hidden_class ) .'">';
|
||||
|
||||
//
|
||||
// Background Position
|
||||
if ( ! empty( $args['background_position'] ) ) {
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-position',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Background Position', 'wp_china_yes' ),
|
||||
'left top' => esc_html__( 'Left Top', 'wp_china_yes' ),
|
||||
'left center' => esc_html__( 'Left Center', 'wp_china_yes' ),
|
||||
'left bottom' => esc_html__( 'Left Bottom', 'wp_china_yes' ),
|
||||
'center top' => esc_html__( 'Center Top', 'wp_china_yes' ),
|
||||
'center center' => esc_html__( 'Center Center', 'wp_china_yes' ),
|
||||
'center bottom' => esc_html__( 'Center Bottom', 'wp_china_yes' ),
|
||||
'right top' => esc_html__( 'Right Top', 'wp_china_yes' ),
|
||||
'right center' => esc_html__( 'Right Center', 'wp_china_yes' ),
|
||||
'right bottom' => esc_html__( 'Right Bottom', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-position'], $this->field_name(), 'field/background' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Repeat
|
||||
if ( ! empty( $args['background_repeat'] ) ) {
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-repeat',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Background Repeat', 'wp_china_yes' ),
|
||||
'repeat' => esc_html__( 'Repeat', 'wp_china_yes' ),
|
||||
'no-repeat' => esc_html__( 'No Repeat', 'wp_china_yes' ),
|
||||
'repeat-x' => esc_html__( 'Repeat Horizontally', 'wp_china_yes' ),
|
||||
'repeat-y' => esc_html__( 'Repeat Vertically', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-repeat'], $this->field_name(), 'field/background' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Attachment
|
||||
if ( ! empty( $args['background_attachment'] ) ) {
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-attachment',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Background Attachment', 'wp_china_yes' ),
|
||||
'scroll' => esc_html__( 'Scroll', 'wp_china_yes' ),
|
||||
'fixed' => esc_html__( 'Fixed', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-attachment'], $this->field_name(), 'field/background' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Size
|
||||
if ( ! empty( $args['background_size'] ) ) {
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-size',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Background Size', 'wp_china_yes' ),
|
||||
'cover' => esc_html__( 'Cover', 'wp_china_yes' ),
|
||||
'contain' => esc_html__( 'Contain', 'wp_china_yes' ),
|
||||
'auto' => esc_html__( 'Auto', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-size'], $this->field_name(), 'field/background' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Origin
|
||||
if ( ! empty( $args['background_origin'] ) ) {
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-origin',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Background Origin', 'wp_china_yes' ),
|
||||
'padding-box' => esc_html__( 'Padding Box', 'wp_china_yes' ),
|
||||
'border-box' => esc_html__( 'Border Box', 'wp_china_yes' ),
|
||||
'content-box' => esc_html__( 'Content Box', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-origin'], $this->field_name(), 'field/background' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Clip
|
||||
if ( ! empty( $args['background_clip'] ) ) {
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-clip',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Background Clip', 'wp_china_yes' ),
|
||||
'border-box' => esc_html__( 'Border Box', 'wp_china_yes' ),
|
||||
'padding-box' => esc_html__( 'Padding Box', 'wp_china_yes' ),
|
||||
'content-box' => esc_html__( 'Content Box', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-clip'], $this->field_name(), 'field/background' );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Background Blend Mode
|
||||
if ( ! empty( $args['background_blend_mode'] ) ) {
|
||||
|
||||
WP_CHINA_YES::field( array(
|
||||
'id' => 'background-blend-mode',
|
||||
'type' => 'select',
|
||||
'options' => array(
|
||||
'' => esc_html__( 'Background Blend Mode', 'wp_china_yes' ),
|
||||
'normal' => esc_html__( 'Normal', 'wp_china_yes' ),
|
||||
'multiply' => esc_html__( 'Multiply', 'wp_china_yes' ),
|
||||
'screen' => esc_html__( 'Screen', 'wp_china_yes' ),
|
||||
'overlay' => esc_html__( 'Overlay', 'wp_china_yes' ),
|
||||
'darken' => esc_html__( 'Darken', 'wp_china_yes' ),
|
||||
'lighten' => esc_html__( 'Lighten', 'wp_china_yes' ),
|
||||
'color-dodge' => esc_html__( 'Color Dodge', 'wp_china_yes' ),
|
||||
'saturation' => esc_html__( 'Saturation', 'wp_china_yes' ),
|
||||
'color' => esc_html__( 'Color', 'wp_china_yes' ),
|
||||
'luminosity' => esc_html__( 'Luminosity', 'wp_china_yes' ),
|
||||
),
|
||||
), $this->value['background-blend-mode'], $this->field_name(), 'field/background' );
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$bg_image = array();
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
|
||||
|
||||
// Background image and gradient
|
||||
$background_color = ( ! empty( $this->value['background-color'] ) ) ? $this->value['background-color'] : '';
|
||||
$background_gd_color = ( ! empty( $this->value['background-gradient-color'] ) ) ? $this->value['background-gradient-color'] : '';
|
||||
$background_gd_direction = ( ! empty( $this->value['background-gradient-direction'] ) ) ? $this->value['background-gradient-direction'] : '';
|
||||
$background_image = ( ! empty( $this->value['background-image']['url'] ) ) ? $this->value['background-image']['url'] : '';
|
||||
|
||||
|
||||
if ( $background_color && $background_gd_color ) {
|
||||
$gd_direction = ( $background_gd_direction ) ? $background_gd_direction .',' : '';
|
||||
$bg_image[] = 'linear-gradient('. $gd_direction . $background_color .','. $background_gd_color .')';
|
||||
unset( $this->value['background-color'] );
|
||||
}
|
||||
|
||||
if ( $background_image ) {
|
||||
$bg_image[] = 'url('. $background_image .')';
|
||||
}
|
||||
|
||||
if ( ! empty( $bg_image ) ) {
|
||||
$output .= 'background-image:'. implode( ',', $bg_image ) . $important .';';
|
||||
}
|
||||
|
||||
// Common background properties
|
||||
$properties = array( 'color', 'position', 'repeat', 'attachment', 'size', 'origin', 'clip', 'blend-mode' );
|
||||
|
||||
foreach ( $properties as $property ) {
|
||||
$property = 'background-'. $property;
|
||||
if ( ! empty( $this->value[$property] ) ) {
|
||||
$output .= $property .':'. $this->value[$property] . $important .';';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $output ) {
|
||||
$output = $element .'{'. $output .'}';
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
38
framework/fields/backup/backup.php
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: backup
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_backup' ) ) {
|
||||
class WP_CHINA_YES_Field_backup extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$unique = $this->unique;
|
||||
$nonce = wp_create_nonce( 'wp_china_yes_backup_nonce' );
|
||||
$export = add_query_arg( array( 'action' => 'wp_china_yes-export', 'unique' => $unique, 'nonce' => $nonce ), admin_url( 'admin-ajax.php' ) );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<textarea name="wp_china_yes_import_data" class="wp_china_yes-import-data"></textarea>';
|
||||
echo '<button type="submit" class="button button-primary wp_china_yes-confirm wp_china_yes-import" data-unique="'. esc_attr( $unique ) .'" data-nonce="'. esc_attr( $nonce ) .'">'. esc_html__( 'Import', 'wp_china_yes' ) .'</button>';
|
||||
echo '<hr />';
|
||||
echo '<textarea readonly="readonly" class="wp_china_yes-export-data">'. esc_attr( json_encode( get_option( $unique ) ) ) .'</textarea>';
|
||||
echo '<a href="'. esc_url( $export ) .'" class="button button-primary wp_china_yes-export" target="_blank">'. esc_html__( 'Export & Download', 'wp_china_yes' ) .'</a>';
|
||||
echo '<hr />';
|
||||
echo '<button type="submit" name="wp_china_yes_transient[reset]" value="reset" class="button wp_china_yes-warning-primary wp_china_yes-confirm wp_china_yes-reset" data-unique="'. esc_attr( $unique ) .'" data-nonce="'. esc_attr( $nonce ) .'">'. esc_html__( 'Reset', 'wp_china_yes' ) .'</button>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
176
framework/fields/border/border.php
Executable file
|
|
@ -0,0 +1,176 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: border
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_border' ) ) {
|
||||
class WP_CHINA_YES_Field_border extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>',
|
||||
'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>',
|
||||
'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>',
|
||||
'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>',
|
||||
'all_icon' => '<i class="fas fa-arrows-alt"></i>',
|
||||
'top_placeholder' => esc_html__( 'top', 'wp_china_yes' ),
|
||||
'right_placeholder' => esc_html__( 'right', 'wp_china_yes' ),
|
||||
'bottom_placeholder' => esc_html__( 'bottom', 'wp_china_yes' ),
|
||||
'left_placeholder' => esc_html__( 'left', 'wp_china_yes' ),
|
||||
'all_placeholder' => esc_html__( 'all', 'wp_china_yes' ),
|
||||
'top' => true,
|
||||
'left' => true,
|
||||
'bottom' => true,
|
||||
'right' => true,
|
||||
'all' => false,
|
||||
'color' => true,
|
||||
'style' => true,
|
||||
'unit' => 'px',
|
||||
) );
|
||||
|
||||
$default_value = array(
|
||||
'top' => '',
|
||||
'right' => '',
|
||||
'bottom' => '',
|
||||
'left' => '',
|
||||
'color' => '',
|
||||
'style' => 'solid',
|
||||
'all' => '',
|
||||
);
|
||||
|
||||
$border_props = array(
|
||||
'solid' => esc_html__( 'Solid', 'wp_china_yes' ),
|
||||
'dashed' => esc_html__( 'Dashed', 'wp_china_yes' ),
|
||||
'dotted' => esc_html__( 'Dotted', 'wp_china_yes' ),
|
||||
'double' => esc_html__( 'Double', 'wp_china_yes' ),
|
||||
'inset' => esc_html__( 'Inset', 'wp_china_yes' ),
|
||||
'outset' => esc_html__( 'Outset', 'wp_china_yes' ),
|
||||
'groove' => esc_html__( 'Groove', 'wp_china_yes' ),
|
||||
'ridge' => esc_html__( 'ridge', 'wp_china_yes' ),
|
||||
'none' => esc_html__( 'None', 'wp_china_yes' )
|
||||
);
|
||||
|
||||
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
|
||||
|
||||
$value = wp_parse_args( $this->value, $default_value );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
|
||||
if ( ! empty( $args['all'] ) ) {
|
||||
|
||||
$placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo ( ! empty( $args['all_icon'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--icon">'. $args['all_icon'] .'</span>' : '';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="wp_china_yes-input-number wp_china_yes--is-unit" step="any" />';
|
||||
echo ( ! empty( $args['unit'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
|
||||
} else {
|
||||
|
||||
$properties = array();
|
||||
|
||||
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
|
||||
if ( ! empty( $args[$prop] ) ) {
|
||||
$properties[] = $prop;
|
||||
}
|
||||
}
|
||||
|
||||
$properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties;
|
||||
|
||||
foreach ( $properties as $property ) {
|
||||
|
||||
$placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--icon">'. $args[$property.'_icon'] .'</span>' : '';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="wp_china_yes-input-number wp_china_yes--is-unit" step="any" />';
|
||||
echo ( ! empty( $args['unit'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! empty( $args['style'] ) ) {
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo '<select name="'. esc_attr( $this->field_name( '[style]' ) ) .'">';
|
||||
foreach ( $border_props as $border_prop_key => $border_prop_value ) {
|
||||
$selected = ( $value['style'] === $border_prop_key ) ? ' selected' : '';
|
||||
echo '<option value="'. esc_attr( $border_prop_key ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $border_prop_value ) .'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ( ! empty( $args['color'] ) ) {
|
||||
$default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="'. esc_attr( $default_value['color'] ) .'"' : '';
|
||||
echo '<div class="wp_china_yes--color">';
|
||||
echo '<div class="wp_china_yes-field-color">';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '[color]' ) ) .'" value="'. esc_attr( $value['color'] ) .'" class="wp_china_yes-color"'. $default_color_attr .' />';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
|
||||
|
||||
// properties
|
||||
$top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $this->value['top'] : '';
|
||||
$right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $this->value['right'] : '';
|
||||
$bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $this->value['bottom'] : '';
|
||||
$left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $this->value['left'] : '';
|
||||
$style = ( isset( $this->value['style'] ) && $this->value['style'] !== '' ) ? $this->value['style'] : '';
|
||||
$color = ( isset( $this->value['color'] ) && $this->value['color'] !== '' ) ? $this->value['color'] : '';
|
||||
$all = ( isset( $this->value['all'] ) && $this->value['all'] !== '' ) ? $this->value['all'] : '';
|
||||
|
||||
if ( ! empty( $this->field['all'] ) && ( $all !== '' || $color !== '' ) ) {
|
||||
|
||||
$output = $element .'{';
|
||||
$output .= ( $all !== '' ) ? 'border-width:'. $all . $unit . $important .';' : '';
|
||||
$output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : '';
|
||||
$output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : '';
|
||||
$output .= '}';
|
||||
|
||||
} else if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' || $color !== '' ) {
|
||||
|
||||
$output = $element .'{';
|
||||
$output .= ( $top !== '' ) ? 'border-top-width:'. $top . $unit . $important .';' : '';
|
||||
$output .= ( $right !== '' ) ? 'border-right-width:'. $right . $unit . $important .';' : '';
|
||||
$output .= ( $bottom !== '' ) ? 'border-bottom-width:'. $bottom . $unit . $important .';' : '';
|
||||
$output .= ( $left !== '' ) ? 'border-left-width:'. $left . $unit . $important .';' : '';
|
||||
$output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : '';
|
||||
$output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : '';
|
||||
$output .= '}';
|
||||
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
67
framework/fields/button_set/button_set.php
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: button_set
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_button_set' ) ) {
|
||||
class WP_CHINA_YES_Field_button_set extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'multiple' => false,
|
||||
'options' => array(),
|
||||
'query_args' => array(),
|
||||
) );
|
||||
|
||||
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( isset( $this->field['options'] ) ) {
|
||||
|
||||
$options = $this->field['options'];
|
||||
$options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
|
||||
|
||||
if ( is_array( $options ) && ! empty( $options ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes-siblings wp_china_yes--button-group" data-multiple="'. esc_attr( $args['multiple'] ) .'">';
|
||||
|
||||
foreach ( $options as $key => $option ) {
|
||||
|
||||
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio';
|
||||
$extra = ( $args['multiple'] ) ? '[]' : '';
|
||||
$active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' wp_china_yes--active' : '';
|
||||
$checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--sibling wp_china_yes--button'. esc_attr( $active ) .'">';
|
||||
echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
|
||||
echo $option;
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
} else {
|
||||
|
||||
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'wp_china_yes' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
framework/fields/callback/callback.php
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: callback
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_callback' ) ) {
|
||||
class WP_CHINA_YES_Field_callback extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
if ( isset( $this->field['function'] ) && is_callable( $this->field['function'] ) ) {
|
||||
|
||||
$args = ( isset( $this->field['args'] ) ) ? $this->field['args'] : null;
|
||||
|
||||
call_user_func( $this->field['function'], $args );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
101
framework/fields/checkbox/checkbox.php
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: checkbox
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_checkbox' ) ) {
|
||||
class WP_CHINA_YES_Field_checkbox extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'inline' => false,
|
||||
'query_args' => array(),
|
||||
'check_all' => false,
|
||||
'check_all_text' => esc_html__( 'Check/Uncheck All' ),
|
||||
) );
|
||||
|
||||
$inline_class = ( $args['inline'] ) ? ' class="wp_china_yes--inline-list"' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( isset( $this->field['options'] ) ) {
|
||||
|
||||
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
|
||||
$options = $this->field['options'];
|
||||
$options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
|
||||
|
||||
if ( is_array( $options ) && ! empty( $options ) ) {
|
||||
|
||||
echo '<ul'. $inline_class .'>';
|
||||
|
||||
foreach ( $options as $option_key => $option_value ) {
|
||||
|
||||
if ( is_array( $option_value ) && ! empty( $option_value ) ) {
|
||||
|
||||
echo '<li>';
|
||||
echo '<ul>';
|
||||
echo '<li><strong>'. esc_attr( $option_key ) .'</strong></li>';
|
||||
foreach ( $option_value as $sub_key => $sub_value ) {
|
||||
$checked = ( in_array( $sub_key, $value ) ) ? ' checked' : '';
|
||||
echo '<li>';
|
||||
echo '<label>';
|
||||
echo '<input type="checkbox" name="'. esc_attr( $this->field_name( '[]' ) ) .'" value="'. esc_attr( $sub_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
|
||||
echo '<span class="wp_china_yes--text">'. esc_attr( $sub_value ) .'</span>';
|
||||
echo '</label>';
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '</li>';
|
||||
|
||||
} else {
|
||||
|
||||
$checked = ( in_array( $option_key, $value ) ) ? ' checked' : '';
|
||||
|
||||
echo '<li>';
|
||||
echo '<label>';
|
||||
echo '<input type="checkbox" name="'. esc_attr( $this->field_name( '[]' ) ) .'" value="'. esc_attr( $option_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
|
||||
echo '<span class="wp_china_yes--text">'. esc_attr( $option_value ) .'</span>';
|
||||
echo '</label>';
|
||||
echo '</li>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
if ( $args['check_all'] ) {
|
||||
echo '<div class="wp_china_yes-checkbox-all">'. esc_html( $args['check_all_text'] ) .'</div>';
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'wp_china_yes' );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
echo '<label class="wp_china_yes-checkbox">';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. $this->value .'" class="wp_china_yes--input"'. $this->field_attributes() .'/>';
|
||||
echo '<input type="checkbox" name="_pseudo" class="wp_china_yes--checkbox"'. esc_attr( checked( $this->value, 1, false ) ) . $this->field_attributes() .'/>';
|
||||
echo ( ! empty( $this->field['label'] ) ) ? '<span class="wp_china_yes--text">'. esc_attr( $this->field['label'] ) .'</span>' : '';
|
||||
echo '</label>';
|
||||
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
58
framework/fields/code_editor/code_editor.php
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: code_editor
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_code_editor' ) ) {
|
||||
class WP_CHINA_YES_Field_code_editor extends WP_CHINA_YES_Fields {
|
||||
|
||||
public $version = '6.65.7';
|
||||
public $cdn_url = 'https://jsd.admincdn.com/npm/codemirror@';
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$default_settings = array(
|
||||
'tabSize' => 2,
|
||||
'lineNumbers' => true,
|
||||
'theme' => 'default',
|
||||
'mode' => 'htmlmixed',
|
||||
'cdnURL' => $this->cdn_url . $this->version,
|
||||
);
|
||||
|
||||
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
|
||||
$settings = wp_parse_args( $settings, $default_settings );
|
||||
|
||||
echo $this->field_before();
|
||||
echo '<textarea name="'. esc_attr( $this->field_name() ) .'"'. $this->field_attributes() .' data-editor="'. esc_attr( json_encode( $settings ) ) .'">'. $this->value .'</textarea>';
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
$page = ( ! empty( $_GET[ 'page' ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ 'page' ] ) ) : '';
|
||||
|
||||
// Do not loads CodeMirror in revslider page.
|
||||
if ( in_array( $page, array( 'revslider' ) ) ) { return; }
|
||||
|
||||
if ( ! wp_script_is( 'wp_china_yes-codemirror' ) ) {
|
||||
wp_enqueue_script( 'wp_china_yes-codemirror', esc_url( $this->cdn_url . $this->version .'/lib/codemirror.min.js' ), array( 'wp_china_yes' ), $this->version, true );
|
||||
wp_enqueue_script( 'wp_china_yes-codemirror-loadmode', esc_url( $this->cdn_url . $this->version .'/addon/mode/loadmode.min.js' ), array( 'wp_china_yes-codemirror' ), $this->version, true );
|
||||
}
|
||||
|
||||
if ( ! wp_style_is( 'wp_china_yes-codemirror' ) ) {
|
||||
wp_enqueue_style( 'wp_china_yes-codemirror', esc_url( $this->cdn_url . $this->version .'/lib/codemirror.min.css' ), array(), $this->version );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
52
framework/fields/color/color.php
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: color
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_color' ) ) {
|
||||
class WP_CHINA_YES_Field_color extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$default_attr = ( ! empty( $this->field['default'] ) ) ? ' data-default-color="'. esc_attr( $this->field['default'] ) .'"' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'" class="wp_china_yes-color"'. $default_attr . $this->field_attributes() .'/>';
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'color';
|
||||
|
||||
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
|
||||
foreach ( $elements as $key_property => $element ) {
|
||||
if ( is_numeric( $key_property ) ) {
|
||||
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $important .';}';
|
||||
break;
|
||||
} else {
|
||||
$output .= $element .'{'. $key_property .':'. $this->value . $important .'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
42
framework/fields/color_group/color_group.php
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: color_group
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_color_group' ) ) {
|
||||
class WP_CHINA_YES_Field_color_group extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$options = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array();
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( ! empty( $options ) ) {
|
||||
foreach ( $options as $key => $option ) {
|
||||
|
||||
$color_value = ( ! empty( $this->value[$key] ) ) ? $this->value[$key] : '';
|
||||
$default_attr = ( ! empty( $this->field['default'][$key] ) ) ? ' data-default-color="'. esc_attr( $this->field['default'][$key] ) .'"' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--left wp_china_yes-field-color">';
|
||||
echo '<div class="wp_china_yes--title">'. $option .'</div>';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '['. $key .']' ) ) .'" value="'. esc_attr( $color_value ) .'" class="wp_china_yes-color"'. $default_attr . $this->field_attributes() .'/>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
28
framework/fields/content/content.php
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: content
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_content' ) ) {
|
||||
class WP_CHINA_YES_Field_content extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
if ( ! empty( $this->field['content'] ) ) {
|
||||
|
||||
echo $this->field['content'];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
64
framework/fields/date/date.php
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: date
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_date' ) ) {
|
||||
class WP_CHINA_YES_Field_date extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$default_settings = array(
|
||||
'dateFormat' => 'mm/dd/yy',
|
||||
);
|
||||
|
||||
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
|
||||
$settings = wp_parse_args( $settings, $default_settings );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( ! empty( $this->field['from_to'] ) ) {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'text_from' => esc_html__( 'From', 'wp_china_yes' ),
|
||||
'text_to' => esc_html__( 'To', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
$value = wp_parse_args( $this->value, array(
|
||||
'from' => '',
|
||||
'to' => '',
|
||||
) );
|
||||
|
||||
echo '<label class="wp_china_yes--from">'. esc_attr( $args['text_from'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[from]' ) ) .'" value="'. esc_attr( $value['from'] ) .'"'. $this->field_attributes() .'/></label>';
|
||||
echo '<label class="wp_china_yes--to">'. esc_attr( $args['text_to'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[to]' ) ) .'" value="'. esc_attr( $value['to'] ) .'"'. $this->field_attributes() .'/></label>';
|
||||
|
||||
} else {
|
||||
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
|
||||
|
||||
}
|
||||
|
||||
echo '<div class="wp_china_yes-date-settings" data-settings="'. esc_attr( json_encode( $settings ) ) .'"></div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-datepicker' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-datepicker' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
61
framework/fields/datetime/datetime.php
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: datetime
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_datetime' ) ) {
|
||||
class WP_CHINA_YES_Field_datetime extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$defaults = array(
|
||||
'allowInput' => true,
|
||||
);
|
||||
|
||||
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
|
||||
|
||||
if ( ! isset( $settings['noCalendar'] ) ) {
|
||||
$defaults['dateFormat'] = 'm/d/Y';
|
||||
}
|
||||
|
||||
$settings = wp_parse_args( $settings, $defaults );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( ! empty( $this->field['from_to'] ) ) {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'text_from' => esc_html__( 'From', 'wp_china_yes' ),
|
||||
'text_to' => esc_html__( 'To', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
$value = wp_parse_args( $this->value, array(
|
||||
'from' => '',
|
||||
'to' => '',
|
||||
) );
|
||||
|
||||
echo '<label class="wp_china_yes--from">'. esc_attr( $args['text_from'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[from]' ) ) .'" value="'. esc_attr( $value['from'] ) .'"'. $this->field_attributes() .' data-type="from" /></label>';
|
||||
echo '<label class="wp_china_yes--to">'. esc_attr( $args['text_to'] ) .' <input type="text" name="'. esc_attr( $this->field_name( '[to]' ) ) .'" value="'. esc_attr( $value['to'] ) .'"'. $this->field_attributes() .' data-type="to" /></label>';
|
||||
|
||||
} else {
|
||||
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
|
||||
|
||||
}
|
||||
|
||||
echo '<div class="wp_china_yes-datetime-settings" data-settings="'. esc_attr( json_encode( $settings ) ) .'"></div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
101
framework/fields/dimensions/dimensions.php
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: dimensions
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_dimensions' ) ) {
|
||||
class WP_CHINA_YES_Field_dimensions extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'width_icon' => '<i class="fas fa-arrows-alt-h"></i>',
|
||||
'height_icon' => '<i class="fas fa-arrows-alt-v"></i>',
|
||||
'width_placeholder' => esc_html__( 'width', 'wp_china_yes' ),
|
||||
'height_placeholder' => esc_html__( 'height', 'wp_china_yes' ),
|
||||
'width' => true,
|
||||
'height' => true,
|
||||
'unit' => true,
|
||||
'show_units' => true,
|
||||
'units' => array( 'px', '%', 'em' )
|
||||
) );
|
||||
|
||||
$default_values = array(
|
||||
'width' => '',
|
||||
'height' => '',
|
||||
'unit' => 'px',
|
||||
);
|
||||
|
||||
$value = wp_parse_args( $this->value, $default_values );
|
||||
$unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
|
||||
$is_unit = ( ! empty( $unit ) ) ? ' wp_china_yes--is-unit' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
|
||||
if ( ! empty( $args['width'] ) ) {
|
||||
$placeholder = ( ! empty( $args['width_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['width_placeholder'] ) .'"' : '';
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo ( ! empty( $args['width_icon'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--icon">'. $args['width_icon'] .'</span>' : '';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $value['width'] ) .'"'. $placeholder .' class="wp_china_yes-input-number'. esc_attr( $is_unit ) .'" step="any" />';
|
||||
echo ( ! empty( $unit ) ) ? '<span class="wp_china_yes--label wp_china_yes--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if ( ! empty( $args['height'] ) ) {
|
||||
$placeholder = ( ! empty( $args['height_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['height_placeholder'] ) .'"' : '';
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo ( ! empty( $args['height_icon'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--icon">'. $args['height_icon'] .'</span>' : '';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $value['height'] ) .'"'. $placeholder .' class="wp_china_yes-input-number'. esc_attr( $is_unit ) .'" step="any" />';
|
||||
echo ( ! empty( $unit ) ) ? '<span class="wp_china_yes--label wp_china_yes--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo '<select name="'. esc_attr( $this->field_name( '[unit]' ) ) .'">';
|
||||
foreach ( $args['units'] as $unit ) {
|
||||
$selected = ( $value['unit'] === $unit ) ? ' selected' : '';
|
||||
echo '<option value="'. esc_attr( $unit ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $unit ) .'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
|
||||
$prefix = ( ! empty( $this->field['output_prefix'] ) ) ? $this->field['output_prefix'] .'-' : '';
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
|
||||
$width = ( isset( $this->value['width'] ) && $this->value['width'] !== '' ) ? $prefix .'width:'. $this->value['width'] . $unit . $important .';' : '';
|
||||
$height = ( isset( $this->value['height'] ) && $this->value['height'] !== '' ) ? $prefix .'height:'. $this->value['height'] . $unit . $important .';' : '';
|
||||
|
||||
if ( $width !== '' || $height !== '' ) {
|
||||
$output = $element .'{'. $width . $height .'}';
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
41
framework/fields/fieldset/fieldset.php
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: fieldset
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_fieldset' ) ) {
|
||||
class WP_CHINA_YES_Field_fieldset extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes-fieldset-content" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
|
||||
foreach ( $this->field['fields'] as $field ) {
|
||||
|
||||
$field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
|
||||
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
|
||||
$field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
|
||||
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_value, $unique_id, 'field/fieldset' );
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
52
framework/fields/gallery/gallery.php
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: gallery
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_gallery' ) ) {
|
||||
class WP_CHINA_YES_Field_gallery extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'add_title' => esc_html__( 'Add Gallery', 'wp_china_yes' ),
|
||||
'edit_title' => esc_html__( 'Edit Gallery', 'wp_china_yes' ),
|
||||
'clear_title' => esc_html__( 'Clear', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
$hidden = ( empty( $this->value ) ) ? ' hidden' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<ul>';
|
||||
if ( ! empty( $this->value ) ) {
|
||||
|
||||
$values = explode( ',', $this->value );
|
||||
|
||||
foreach ( $values as $id ) {
|
||||
$attachment = wp_get_attachment_image_src( $id, 'thumbnail' );
|
||||
echo '<li><img src="'. esc_url( $attachment[0] ) .'" /></li>';
|
||||
}
|
||||
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
echo '<a href="#" class="button button-primary wp_china_yes-button">'. $args['add_title'] .'</a>';
|
||||
echo '<a href="#" class="button wp_china_yes-edit-gallery'. esc_attr( $hidden ) .'">'. $args['edit_title'] .'</a>';
|
||||
echo '<a href="#" class="button wp_china_yes-warning-primary wp_china_yes-clear-gallery'. esc_attr( $hidden ) .'">'. $args['clear_title'] .'</a>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
164
framework/fields/group/group.php
Executable file
|
|
@ -0,0 +1,164 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: group
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_group' ) ) {
|
||||
class WP_CHINA_YES_Field_group extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'max' => 0,
|
||||
'min' => 0,
|
||||
'fields' => array(),
|
||||
'button_title' => esc_html__( 'Add New', 'wp_china_yes' ),
|
||||
'accordion_title_prefix' => '',
|
||||
'accordion_title_number' => false,
|
||||
'accordion_title_auto' => true,
|
||||
'accordion_title_by' => array(),
|
||||
'accordion_title_by_prefix' => ' ',
|
||||
) );
|
||||
|
||||
$title_prefix = ( ! empty( $args['accordion_title_prefix'] ) ) ? $args['accordion_title_prefix'] : '';
|
||||
$title_number = ( ! empty( $args['accordion_title_number'] ) ) ? true : false;
|
||||
$title_auto = ( ! empty( $args['accordion_title_auto'] ) ) ? true : false;
|
||||
$title_first = ( isset( $this->field['fields'][0]['id'] ) ) ? $this->field['fields'][0]['id'] : $this->field['fields'][1]['id'];
|
||||
$title_by = ( is_array( $args['accordion_title_by'] ) ) ? $args['accordion_title_by'] : (array) $args['accordion_title_by'];
|
||||
$title_by = ( empty( $title_by ) ) ? array( $title_first ) : $title_by;
|
||||
$title_by_prefix = ( ! empty( $args['accordion_title_by_prefix'] ) ) ? $args['accordion_title_by_prefix'] : '';
|
||||
|
||||
if ( preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->unique ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes-notice wp_china_yes-notice-danger">'. esc_html__( 'Error: Field ID conflict.', 'wp_china_yes' ) .'</div>';
|
||||
|
||||
} else {
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-item wp_china_yes-cloneable-hidden" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-helper">';
|
||||
echo '<i class="wp_china_yes-cloneable-sort fas fa-arrows-alt"></i>';
|
||||
echo '<i class="wp_china_yes-cloneable-clone far fa-clone"></i>';
|
||||
echo '<i class="wp_china_yes-cloneable-remove wp_china_yes-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'wp_china_yes' ) .'"></i>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<h4 class="wp_china_yes-cloneable-title">';
|
||||
echo '<span class="wp_china_yes-cloneable-text">';
|
||||
echo ( $title_number ) ? '<span class="wp_china_yes-cloneable-title-number"></span>' : '';
|
||||
echo ( $title_prefix ) ? '<span class="wp_china_yes-cloneable-title-prefix">'. esc_attr( $title_prefix ) .'</span>' : '';
|
||||
echo ( $title_auto ) ? '<span class="wp_china_yes-cloneable-value"><span class="wp_china_yes-cloneable-placeholder"></span></span>' : '';
|
||||
echo '</span>';
|
||||
echo '</h4>';
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-content">';
|
||||
foreach ( $this->field['fields'] as $field ) {
|
||||
|
||||
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
|
||||
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .'][0]' : $this->field['id'] .'[0]';
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_default, '___'. $field_unique, 'field/group' );
|
||||
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-wrapper wp_china_yes-data-wrapper" data-title-by="'. esc_attr( json_encode( $title_by ) ) .'" data-title-by-prefix="'. esc_attr( $title_by_prefix ) .'" data-title-number="'. esc_attr( $title_number ) .'" data-field-id="['. esc_attr( $this->field['id'] ) .']" data-max="'. esc_attr( $args['max'] ) .'" data-min="'. esc_attr( $args['min'] ) .'">';
|
||||
|
||||
if ( ! empty( $this->value ) ) {
|
||||
|
||||
$num = 0;
|
||||
|
||||
foreach ( $this->value as $value ) {
|
||||
|
||||
$title = '';
|
||||
|
||||
if ( ! empty( $title_by ) ) {
|
||||
|
||||
$titles = array();
|
||||
|
||||
foreach ( $title_by as $title_key ) {
|
||||
if ( isset( $value[ $title_key ] ) ) {
|
||||
$titles[] = $value[ $title_key ];
|
||||
}
|
||||
}
|
||||
|
||||
$title = join( $title_by_prefix, $titles );
|
||||
|
||||
}
|
||||
|
||||
$title = ( is_array( $title ) ) ? reset( $title ) : $title;
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-item">';
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-helper">';
|
||||
echo '<i class="wp_china_yes-cloneable-sort fas fa-arrows-alt"></i>';
|
||||
echo '<i class="wp_china_yes-cloneable-clone far fa-clone"></i>';
|
||||
echo '<i class="wp_china_yes-cloneable-remove wp_china_yes-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'wp_china_yes' ) .'"></i>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<h4 class="wp_china_yes-cloneable-title">';
|
||||
echo '<span class="wp_china_yes-cloneable-text">';
|
||||
echo ( $title_number ) ? '<span class="wp_china_yes-cloneable-title-number">'. esc_attr( $num+1 ) .'.</span>' : '';
|
||||
echo ( $title_prefix ) ? '<span class="wp_china_yes-cloneable-title-prefix">'. esc_attr( $title_prefix ) .'</span>' : '';
|
||||
echo ( $title_auto ) ? '<span class="wp_china_yes-cloneable-value">' . esc_attr( $title ) .'</span>' : '';
|
||||
echo '</span>';
|
||||
echo '</h4>';
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-content">';
|
||||
|
||||
foreach ( $this->field['fields'] as $field ) {
|
||||
|
||||
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']';
|
||||
$field_value = ( isset( $field['id'] ) && isset( $value[$field['id']] ) ) ? $value[$field['id']] : '';
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_value, $field_unique, 'field/group' );
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
$num++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-cloneable-alert wp_china_yes-cloneable-max">'. esc_html__( 'You cannot add more.', 'wp_china_yes' ) .'</div>';
|
||||
echo '<div class="wp_china_yes-cloneable-alert wp_china_yes-cloneable-min">'. esc_html__( 'You cannot remove more.', 'wp_china_yes' ) .'</div>';
|
||||
echo '<a href="#" class="button button-primary wp_china_yes-cloneable-add">'. $args['button_title'] .'</a>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-accordion' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-accordion' );
|
||||
}
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-sortable' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
24
framework/fields/heading/heading.php
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: heading
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_heading' ) ) {
|
||||
class WP_CHINA_YES_Field_heading extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
echo ( ! empty( $this->field['content'] ) ) ? $this->field['content'] : '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
framework/fields/icon/fa4-icons.php
Executable file
12
framework/fields/icon/fa5-icons.php
Executable file
71
framework/fields/icon/icon.php
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: icon
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_icon' ) ) {
|
||||
class WP_CHINA_YES_Field_icon extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'button_title' => esc_html__( 'Add Icon', 'wp_china_yes' ),
|
||||
'remove_title' => esc_html__( 'Remove Icon', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
$nonce = wp_create_nonce( 'wp_china_yes_icon_nonce' );
|
||||
$hidden = ( empty( $this->value ) ) ? ' hidden' : '';
|
||||
|
||||
echo '<div class="wp_china_yes-icon-select">';
|
||||
echo '<span class="wp_china_yes-icon-preview'. esc_attr( $hidden ) .'"><i class="'. esc_attr( $this->value ) .'"></i></span>';
|
||||
echo '<a href="#" class="button button-primary wp_china_yes-icon-add" data-nonce="'. esc_attr( $nonce ) .'">'. $args['button_title'] .'</a>';
|
||||
echo '<a href="#" class="button wp_china_yes-warning-primary wp_china_yes-icon-remove'. esc_attr( $hidden ) .'">'. $args['remove_title'] .'</a>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'" class="wp_china_yes-icon-value"'. $this->field_attributes() .' />';
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
add_action( 'admin_footer', array( 'WP_CHINA_YES_Field_icon', 'add_footer_modal_icon' ) );
|
||||
add_action( 'customize_controls_print_footer_scripts', array( 'WP_CHINA_YES_Field_icon', 'add_footer_modal_icon' ) );
|
||||
}
|
||||
|
||||
public static function add_footer_modal_icon() {
|
||||
?>
|
||||
<div id="wp_china_yes-modal-icon" class="wp_china_yes-modal wp_china_yes-modal-icon hidden">
|
||||
<div class="wp_china_yes-modal-table">
|
||||
<div class="wp_china_yes-modal-table-cell">
|
||||
<div class="wp_china_yes-modal-overlay"></div>
|
||||
<div class="wp_china_yes-modal-inner">
|
||||
<div class="wp_china_yes-modal-title">
|
||||
<?php esc_html_e( 'Add Icon', 'wp_china_yes' ); ?>
|
||||
<div class="wp_china_yes-modal-close wp_china_yes-icon-close"></div>
|
||||
</div>
|
||||
<div class="wp_china_yes-modal-header">
|
||||
<input type="text" placeholder="<?php esc_html_e( 'Search...', 'wp_china_yes' ); ?>" class="wp_china_yes-icon-search" />
|
||||
</div>
|
||||
<div class="wp_china_yes-modal-content">
|
||||
<div class="wp_china_yes-modal-loading"><div class="wp_china_yes-loading"></div></div>
|
||||
<div class="wp_china_yes-modal-load"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
framework/fields/icon/iconsax-icons.php
Executable file
79
framework/fields/image_select/image_select.php
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: image_select
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_image_select' ) ) {
|
||||
class WP_CHINA_YES_Field_image_select extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'multiple' => false,
|
||||
'inline' => false,
|
||||
'options' => array(),
|
||||
) );
|
||||
|
||||
$inline = ( $args['inline'] ) ? ' wp_china_yes--inline-list' : '';
|
||||
|
||||
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( ! empty( $args['options'] ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes-siblings wp_china_yes--image-group'. esc_attr( $inline ) .'" data-multiple="'. esc_attr( $args['multiple'] ) .'">';
|
||||
|
||||
$num = 1;
|
||||
|
||||
foreach ( $args['options'] as $key => $option ) {
|
||||
|
||||
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio';
|
||||
$extra = ( $args['multiple'] ) ? '[]' : '';
|
||||
$active = ( in_array( $key, $value ) ) ? ' wp_china_yes--active' : '';
|
||||
$checked = ( in_array( $key, $value ) ) ? ' checked' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--sibling wp_china_yes--image'. esc_attr( $active ) .'">';
|
||||
echo '<figure>';
|
||||
echo '<img src="'. esc_url( $option ) .'" alt="img-'. esc_attr( $num++ ) .'" />';
|
||||
echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
|
||||
echo '</figure>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$bg_image = array();
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
|
||||
|
||||
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
|
||||
$output = $elements .'{background-image:url('. $this->value .')'. $important .';}';
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
1
framework/fields/index.php
Executable file
|
|
@ -0,0 +1 @@
|
|||
<?php // Silence is golden.
|
||||
82
framework/fields/link/link.php
Executable file
|
|
@ -0,0 +1,82 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: link
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_link' ) ) {
|
||||
class WP_CHINA_YES_Field_link extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'add_title' => esc_html__( 'Add Link', 'wp_china_yes' ),
|
||||
'edit_title' => esc_html__( 'Edit Link', 'wp_china_yes' ),
|
||||
'remove_title' => esc_html__( 'Remove Link', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
$default_values = array(
|
||||
'url' => '',
|
||||
'text' => '',
|
||||
'target' => '',
|
||||
);
|
||||
|
||||
$value = wp_parse_args( $this->value, $default_values );
|
||||
|
||||
$hidden = ( ! empty( $value['url'] ) || ! empty( $value['url'] ) || ! empty( $value['url'] ) ) ? ' hidden' : '';
|
||||
|
||||
$maybe_hidden = ( empty( $hidden ) ) ? ' hidden' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<textarea readonly="readonly" class="wp_china_yes--link hidden"></textarea>';
|
||||
|
||||
echo '<div class="'. esc_attr( $maybe_hidden ) .'"><div class="wp_china_yes--result">'. sprintf( '{url:"%s", text:"%s", target:"%s"}', $value['url'], $value['text'], $value['target'] ) .'</div></div>';
|
||||
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[url]' ) ) .'" value="'. esc_attr( $value['url'] ) .'"'. $this->field_attributes( array( 'class' => 'wp_china_yes--url' ) ) .' />';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[text]' ) ) .'" value="'. esc_attr( $value['text'] ) .'" class="wp_china_yes--text" />';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[target]' ) ) .'" value="'. esc_attr( $value['target'] ) .'" class="wp_china_yes--target" />';
|
||||
|
||||
echo '<a href="#" class="button button-primary wp_china_yes--add'. esc_attr( $hidden ) .'">'. $args['add_title'] .'</a> ';
|
||||
echo '<a href="#" class="button wp_china_yes--edit'. esc_attr( $maybe_hidden ) .'">'. $args['edit_title'] .'</a> ';
|
||||
echo '<a href="#" class="button wp_china_yes-warning-primary wp_china_yes--remove'. esc_attr( $maybe_hidden ) .'">'. $args['remove_title'] .'</a>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'wplink' ) ) {
|
||||
wp_enqueue_script( 'wplink' );
|
||||
}
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-autocomplete' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-autocomplete' );
|
||||
}
|
||||
|
||||
add_action( 'admin_print_footer_scripts', array( $this, 'add_wp_link_dialog' ) );
|
||||
|
||||
}
|
||||
|
||||
public function add_wp_link_dialog() {
|
||||
|
||||
if ( ! class_exists( '_WP_Editors' ) ) {
|
||||
require_once ABSPATH . WPINC .'/class-wp-editor.php';
|
||||
}
|
||||
|
||||
wp_print_styles( 'editor-buttons' );
|
||||
|
||||
_WP_Editors::wp_link_dialog();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
91
framework/fields/link_color/link_color.php
Executable file
|
|
@ -0,0 +1,91 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: link_color
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_link_color' ) ) {
|
||||
class WP_CHINA_YES_Field_link_color extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'color' => true,
|
||||
'hover' => true,
|
||||
'active' => false,
|
||||
'visited' => false,
|
||||
'focus' => false,
|
||||
) );
|
||||
|
||||
$default_values = array(
|
||||
'color' => '',
|
||||
'hover' => '',
|
||||
'active' => '',
|
||||
'visited' => '',
|
||||
'focus' => '',
|
||||
);
|
||||
|
||||
$color_props = array(
|
||||
'color' => esc_html__( 'Normal', 'wp_china_yes' ),
|
||||
'hover' => esc_html__( 'Hover', 'wp_china_yes' ),
|
||||
'active' => esc_html__( 'Active', 'wp_china_yes' ),
|
||||
'visited' => esc_html__( 'Visited', 'wp_china_yes' ),
|
||||
'focus' => esc_html__( 'Focus', 'wp_china_yes' )
|
||||
);
|
||||
|
||||
$value = wp_parse_args( $this->value, $default_values );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
foreach ( $color_props as $color_prop_key => $color_prop_value ) {
|
||||
|
||||
if ( ! empty( $args[$color_prop_key] ) ) {
|
||||
|
||||
$default_attr = ( ! empty( $this->field['default'][$color_prop_key] ) ) ? ' data-default-color="'. esc_attr( $this->field['default'][$color_prop_key] ) .'"' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--left wp_china_yes-field-color">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_attr( $color_prop_value ) .'</div>';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '['. $color_prop_key .']' ) ) .'" value="'. esc_attr( $value[$color_prop_key] ) .'" class="wp_china_yes-color"'. $default_attr . $this->field_attributes() .'/>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
|
||||
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
|
||||
foreach ( $elements as $element ) {
|
||||
|
||||
if ( isset( $this->value['color'] ) && $this->value['color'] !== '' ) { $output .= $element .'{color:'. $this->value['color'] . $important .';}'; }
|
||||
if ( isset( $this->value['hover'] ) && $this->value['hover'] !== '' ) { $output .= $element .':hover{color:'. $this->value['hover'] . $important .';}'; }
|
||||
if ( isset( $this->value['active'] ) && $this->value['active'] !== '' ) { $output .= $element .':active{color:'. $this->value['active'] . $important .';}'; }
|
||||
if ( isset( $this->value['visited'] ) && $this->value['visited'] !== '' ) { $output .= $element .':visited{color:'. $this->value['visited'] . $important .';}'; }
|
||||
if ( isset( $this->value['focus'] ) && $this->value['focus'] !== '' ) { $output .= $element .':focus{color:'. $this->value['focus'] . $important .';}'; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
98
framework/fields/map/map.php
Executable file
|
|
@ -0,0 +1,98 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: map
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_map' ) ) {
|
||||
class WP_CHINA_YES_Field_map extends WP_CHINA_YES_Fields {
|
||||
|
||||
public $version = '1.9.4';
|
||||
public $cdn_url = 'https://jsd.admincdn.com/npm/leaflet@';
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'placeholder' => esc_html__( 'Search...', 'wp_china_yes' ),
|
||||
'latitude_text' => esc_html__( 'Latitude', 'wp_china_yes' ),
|
||||
'longitude_text' => esc_html__( 'Longitude', 'wp_china_yes' ),
|
||||
'address_field' => '',
|
||||
'height' => '',
|
||||
) );
|
||||
|
||||
$value = wp_parse_args( $this->value, array(
|
||||
'address' => '',
|
||||
'latitude' => '20',
|
||||
'longitude' => '0',
|
||||
'zoom' => '2',
|
||||
) );
|
||||
|
||||
$default_settings = array(
|
||||
'center' => array( $value['latitude'], $value['longitude'] ),
|
||||
'zoom' => $value['zoom'],
|
||||
'scrollWheelZoom' => false,
|
||||
);
|
||||
|
||||
$settings = ( ! empty( $this->field['settings'] ) ) ? $this->field['settings'] : array();
|
||||
$settings = wp_parse_args( $settings, $default_settings );
|
||||
|
||||
$style_attr = ( ! empty( $args['height'] ) ) ? ' style="min-height:'. esc_attr( $args['height'] ) .';"' : '';
|
||||
$placeholder = ( ! empty( $args['placeholder'] ) ) ? array( 'placeholder' => $args['placeholder'] ) : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( empty( $args['address_field'] ) ) {
|
||||
echo '<div class="wp_china_yes--map-search">';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '[address]' ) ) .'" value="'. esc_attr( $value['address'] ) .'"'. $this->field_attributes( $placeholder ) .' />';
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<div class="wp_china_yes--address-field" data-address-field="'. esc_attr( $args['address_field'] ) .'"></div>';
|
||||
}
|
||||
|
||||
echo '<div class="wp_china_yes--map-osm-wrap"><div class="wp_china_yes--map-osm" data-map="'. esc_attr( json_encode( $settings ) ) .'"'. $style_attr .'></div></div>';
|
||||
|
||||
echo '<div class="wp_china_yes--map-inputs">';
|
||||
|
||||
echo '<div class="wp_china_yes--map-input">';
|
||||
echo '<label>'. esc_attr( $args['latitude_text'] ) .'</label>';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '[latitude]' ) ) .'" value="'. esc_attr( $value['latitude'] ) .'" class="wp_china_yes--latitude" />';
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes--map-input">';
|
||||
echo '<label>'. esc_attr( $args['longitude_text'] ) .'</label>';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '[longitude]' ) ) .'" value="'. esc_attr( $value['longitude'] ) .'" class="wp_china_yes--longitude" />';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[zoom]' ) ) .'" value="'. esc_attr( $value['zoom'] ) .'" class="wp_china_yes--zoom" />';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'wp_china_yes-leaflet' ) ) {
|
||||
wp_enqueue_script( 'wp_china_yes-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.js' ), array( 'wp_china_yes' ), $this->version, true );
|
||||
}
|
||||
|
||||
if ( ! wp_style_is( 'wp_china_yes-leaflet' ) ) {
|
||||
wp_enqueue_style( 'wp_china_yes-leaflet', esc_url( $this->cdn_url . $this->version .'/dist/leaflet.css' ), array(), $this->version );
|
||||
}
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-autocomplete' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-autocomplete' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
96
framework/fields/media/media.php
Executable file
|
|
@ -0,0 +1,96 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: media
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_media' ) ) {
|
||||
class WP_CHINA_YES_Field_media extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'url' => true,
|
||||
'preview' => true,
|
||||
'preview_width' => '',
|
||||
'preview_height' => '',
|
||||
'library' => array(),
|
||||
'button_title' => esc_html__( 'Upload', 'wp_china_yes' ),
|
||||
'remove_title' => esc_html__( 'Remove', 'wp_china_yes' ),
|
||||
'preview_size' => 'thumbnail',
|
||||
) );
|
||||
|
||||
$default_values = array(
|
||||
'url' => '',
|
||||
'id' => '',
|
||||
'width' => '',
|
||||
'height' => '',
|
||||
'thumbnail' => '',
|
||||
'alt' => '',
|
||||
'title' => '',
|
||||
'description' => ''
|
||||
);
|
||||
|
||||
// fallback
|
||||
if ( is_numeric( $this->value ) ) {
|
||||
|
||||
$this->value = array(
|
||||
'id' => $this->value,
|
||||
'url' => wp_get_attachment_url( $this->value ),
|
||||
'thumbnail' => wp_get_attachment_image_src( $this->value, 'thumbnail', true )[0],
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->value = wp_parse_args( $this->value, $default_values );
|
||||
|
||||
$library = ( is_array( $args['library'] ) ) ? $args['library'] : array_filter( (array) $args['library'] );
|
||||
$library = ( ! empty( $library ) ) ? implode(',', $library ) : '';
|
||||
$preview_src = ( $args['preview_size'] !== 'thumbnail' ) ? $this->value['url'] : $this->value['thumbnail'];
|
||||
$hidden_url = ( empty( $args['url'] ) ) ? ' hidden' : '';
|
||||
$hidden_auto = ( empty( $this->value['url'] ) ) ? ' hidden' : '';
|
||||
$placeholder = ( empty( $this->field['placeholder'] ) ) ? ' placeholder="'. esc_html__( 'Not selected', 'wp_china_yes' ) .'"' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( ! empty( $args['preview'] ) ) {
|
||||
|
||||
$preview_width = ( ! empty( $args['preview_width'] ) ) ? 'max-width:'. esc_attr( $args['preview_width'] ) .'px;' : '';
|
||||
$preview_height = ( ! empty( $args['preview_height'] ) ) ? 'max-height:'. esc_attr( $args['preview_height'] ) .'px;' : '';
|
||||
$preview_style = ( ! empty( $preview_width ) || ! empty( $preview_height ) ) ? ' style="'. esc_attr( $preview_width . $preview_height ) .'"': '';
|
||||
|
||||
echo '<div class="wp_china_yes--preview'. esc_attr( $hidden_auto ) .'">';
|
||||
echo '<div class="wp_china_yes-image-preview"'. $preview_style .'>';
|
||||
echo '<i class="wp_china_yes--remove fas fa-times"></i><span><img src="'. esc_url( $preview_src ) .'" class="wp_china_yes--src" /></span>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '<div class="wp_china_yes--placeholder">';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '[url]' ) ) .'" value="'. esc_attr( $this->value['url'] ) .'" class="wp_china_yes--url'. esc_attr( $hidden_url ) .'" readonly="readonly"'. $this->field_attributes() . $placeholder .' />';
|
||||
echo '<a href="#" class="button button-primary wp_china_yes--button" data-library="'. esc_attr( $library ) .'" data-preview-size="'. esc_attr( $args['preview_size'] ) .'">'. $args['button_title'] .'</a>';
|
||||
echo ( empty( $args['preview'] ) ) ? '<a href="#" class="button button-secondary wp_china_yes-warning-primary wp_china_yes--remove'. esc_attr( $hidden_auto ) .'">'. $args['remove_title'] .'</a>' : '';
|
||||
echo '</div>';
|
||||
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[id]' ) ) .'" value="'. esc_attr( $this->value['id'] ) .'" class="wp_china_yes--id"/>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[width]' ) ) .'" value="'. esc_attr( $this->value['width'] ) .'" class="wp_china_yes--width"/>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[height]' ) ) .'" value="'. esc_attr( $this->value['height'] ) .'" class="wp_china_yes--height"/>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[thumbnail]' ) ) .'" value="'. esc_attr( $this->value['thumbnail'] ) .'" class="wp_china_yes--thumbnail"/>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[alt]' ) ) .'" value="'. esc_attr( $this->value['alt'] ) .'" class="wp_china_yes--alt"/>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[title]' ) ) .'" value="'. esc_attr( $this->value['title'] ) .'" class="wp_china_yes--title"/>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[description]' ) ) .'" value="'. esc_attr( $this->value['description'] ) .'" class="wp_china_yes--description"/>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
26
framework/fields/notice/notice.php
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: notice
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_notice' ) ) {
|
||||
class WP_CHINA_YES_Field_notice extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$style = ( ! empty( $this->field['style'] ) ) ? $this->field['style'] : 'normal';
|
||||
|
||||
echo ( ! empty( $this->field['content'] ) ) ? '<div class="wp_china_yes-notice wp_china_yes-notice-'. esc_attr( $style ) .'">'. $this->field['content'] .'</div>' : '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
63
framework/fields/number/number.php
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: number
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_number' ) ) {
|
||||
class WP_CHINA_YES_Field_number extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'min' => 'any',
|
||||
'max' => 'any',
|
||||
'step' => 'any',
|
||||
'unit' => '',
|
||||
) );
|
||||
|
||||
echo $this->field_before();
|
||||
echo '<div class="wp_china_yes--wrap">';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' min="'. esc_attr( $args['min'] ) .'" max="'. esc_attr( $args['max'] ) .'" step="'. esc_attr( $args['step'] ) .'"/>';
|
||||
echo ( ! empty( $args['unit'] ) ) ? '<span class="wp_china_yes--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width';
|
||||
$unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px';
|
||||
|
||||
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
|
||||
foreach ( $elements as $key_property => $element ) {
|
||||
if ( is_numeric( $key_property ) ) {
|
||||
if ( $mode ) {
|
||||
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}';
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
$output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
58
framework/fields/palette/palette.php
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: palette
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_palette' ) ) {
|
||||
class WP_CHINA_YES_Field_palette extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$palette = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array();
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( ! empty( $palette ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes-siblings wp_china_yes--palettes">';
|
||||
|
||||
foreach ( $palette as $key => $colors ) {
|
||||
|
||||
$active = ( $key === $this->value ) ? ' wp_china_yes--active' : '';
|
||||
$checked = ( $key === $this->value ) ? ' checked' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--sibling wp_china_yes--palette'. esc_attr( $active ) .'">';
|
||||
|
||||
if ( ! empty( $colors ) ) {
|
||||
|
||||
foreach ( $colors as $color ) {
|
||||
|
||||
echo '<span style="background-color: '. esc_attr( $color ) .';"></span>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
93
framework/fields/radio/radio.php
Executable file
|
|
@ -0,0 +1,93 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: radio
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_radio' ) ) {
|
||||
class WP_CHINA_YES_Field_radio extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'inline' => false,
|
||||
'query_args' => array(),
|
||||
) );
|
||||
|
||||
$inline_class = ( $args['inline'] ) ? ' class="wp_china_yes--inline-list"' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( isset( $this->field['options'] ) ) {
|
||||
|
||||
$options = $this->field['options'];
|
||||
$options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
|
||||
|
||||
if ( is_array( $options ) && ! empty( $options ) ) {
|
||||
|
||||
echo '<ul'. $inline_class .'>';
|
||||
|
||||
foreach ( $options as $option_key => $option_value ) {
|
||||
|
||||
if ( is_array( $option_value ) && ! empty( $option_value ) ) {
|
||||
|
||||
echo '<li>';
|
||||
echo '<ul>';
|
||||
echo '<li><strong>'. esc_attr( $option_key ) .'</strong></li>';
|
||||
foreach ( $option_value as $sub_key => $sub_value ) {
|
||||
$checked = ( $sub_key == $this->value ) ? ' checked' : '';
|
||||
echo '<li>';
|
||||
echo '<label>';
|
||||
echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $sub_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
|
||||
echo '<span class="wp_china_yes--text">'. esc_attr( $sub_value ) .'</span>';
|
||||
echo '</label>';
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '</li>';
|
||||
|
||||
} else {
|
||||
|
||||
$checked = ( $option_key == $this->value ) ? ' checked' : '';
|
||||
|
||||
echo '<li>';
|
||||
echo '<label>';
|
||||
echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $option_key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
|
||||
echo '<span class="wp_china_yes--text">'. esc_attr( $option_value ) .'</span>';
|
||||
echo '</label>';
|
||||
echo '</li>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
} else {
|
||||
|
||||
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'wp_china_yes' );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$label = ( isset( $this->field['label'] ) ) ? $this->field['label'] : '';
|
||||
echo '<label><input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="1"'. $this->field_attributes() . esc_attr( checked( $this->value, 1, false ) ) .'/>';
|
||||
echo ( ! empty( $this->field['label'] ) ) ? '<span class="wp_china_yes--text">'. esc_attr( $this->field['label'] ) .'</span>' : '';
|
||||
echo '</label>';
|
||||
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
108
framework/fields/repeater/repeater.php
Executable file
|
|
@ -0,0 +1,108 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: repeater
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_repeater' ) ) {
|
||||
class WP_CHINA_YES_Field_repeater extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'max' => 0,
|
||||
'min' => 0,
|
||||
'button_title' => '<i class="fas fa-plus-circle"></i>',
|
||||
) );
|
||||
|
||||
if ( preg_match( '/'. preg_quote( '['. $this->field['id'] .']' ) .'/', $this->unique ) ) {
|
||||
|
||||
echo '<div class="wp_china_yes-notice wp_china_yes-notice-danger">'. esc_html__( 'Error: Field ID conflict.', 'wp_china_yes' ) .'</div>';
|
||||
|
||||
} else {
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes-repeater-item wp_china_yes-repeater-hidden" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
echo '<div class="wp_china_yes-repeater-content">';
|
||||
foreach ( $this->field['fields'] as $field ) {
|
||||
|
||||
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
|
||||
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .'][0]' : $this->field['id'] .'[0]';
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_default, '___'. $field_unique, 'field/repeater' );
|
||||
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<div class="wp_china_yes-repeater-helper">';
|
||||
echo '<div class="wp_china_yes-repeater-helper-inner">';
|
||||
echo '<i class="wp_china_yes-repeater-sort fas fa-arrows-alt"></i>';
|
||||
echo '<i class="wp_china_yes-repeater-clone far fa-clone"></i>';
|
||||
echo '<i class="wp_china_yes-repeater-remove wp_china_yes-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'wp_china_yes' ) .'"></i>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-repeater-wrapper wp_china_yes-data-wrapper" data-field-id="['. esc_attr( $this->field['id'] ) .']" data-max="'. esc_attr( $args['max'] ) .'" data-min="'. esc_attr( $args['min'] ) .'">';
|
||||
|
||||
if ( ! empty( $this->value ) && is_array( $this->value ) ) {
|
||||
|
||||
$num = 0;
|
||||
|
||||
foreach ( $this->value as $key => $value ) {
|
||||
|
||||
echo '<div class="wp_china_yes-repeater-item">';
|
||||
echo '<div class="wp_china_yes-repeater-content">';
|
||||
foreach ( $this->field['fields'] as $field ) {
|
||||
|
||||
$field_unique = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']['. $num .']' : $this->field['id'] .'['. $num .']';
|
||||
$field_value = ( isset( $field['id'] ) && isset( $this->value[$key][$field['id']] ) ) ? $this->value[$key][$field['id']] : '';
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_value, $field_unique, 'field/repeater' );
|
||||
|
||||
}
|
||||
echo '</div>';
|
||||
echo '<div class="wp_china_yes-repeater-helper">';
|
||||
echo '<div class="wp_china_yes-repeater-helper-inner">';
|
||||
echo '<i class="wp_china_yes-repeater-sort fas fa-arrows-alt"></i>';
|
||||
echo '<i class="wp_china_yes-repeater-clone far fa-clone"></i>';
|
||||
echo '<i class="wp_china_yes-repeater-remove wp_china_yes-confirm fas fa-times" data-confirm="'. esc_html__( 'Are you sure to delete this item?', 'wp_china_yes' ) .'"></i>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
$num++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-repeater-alert wp_china_yes-repeater-max">'. esc_html__( 'You cannot add more.', 'wp_china_yes' ) .'</div>';
|
||||
echo '<div class="wp_china_yes-repeater-alert wp_china_yes-repeater-min">'. esc_html__( 'You cannot remove more.', 'wp_china_yes' ) .'</div>';
|
||||
echo '<a href="#" class="button button-primary wp_china_yes-repeater-add">'. $args['button_title'] .'</a>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-sortable' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
132
framework/fields/select/select.php
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: select
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_select' ) ) {
|
||||
class WP_CHINA_YES_Field_select extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'placeholder' => '',
|
||||
'chosen' => false,
|
||||
'multiple' => false,
|
||||
'sortable' => false,
|
||||
'ajax' => false,
|
||||
'settings' => array(),
|
||||
'query_args' => array(),
|
||||
) );
|
||||
|
||||
$this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
if ( isset( $this->field['options'] ) ) {
|
||||
|
||||
if ( ! empty( $args['ajax'] ) ) {
|
||||
$args['settings']['data']['type'] = $args['options'];
|
||||
$args['settings']['data']['nonce'] = wp_create_nonce( 'wp_china_yes_chosen_ajax_nonce' );
|
||||
if ( ! empty( $args['query_args'] ) ) {
|
||||
$args['settings']['data']['query_args'] = $args['query_args'];
|
||||
}
|
||||
}
|
||||
|
||||
$chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
|
||||
$multiple_name = ( $args['multiple'] ) ? '[]' : '';
|
||||
$multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
|
||||
$chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' wp_china_yes-chosen-sortable' : '';
|
||||
$chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' wp_china_yes-chosen-ajax' : '';
|
||||
$placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="'. esc_attr( $args['placeholder'] ) .'"' : '';
|
||||
$field_class = ( $args['chosen'] ) ? ' class="wp_china_yes-chosen'. esc_attr( $chosen_rtl . $chosen_sortable . $chosen_ajax ) .'"' : '';
|
||||
$field_name = $this->field_name( $multiple_name );
|
||||
$field_attr = $this->field_attributes();
|
||||
$maybe_options = $this->field['options'];
|
||||
$chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="'. esc_attr( json_encode( $args['settings'] ) ) .'"' : '';
|
||||
|
||||
if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
|
||||
$options = $this->field_wp_query_data_title( $maybe_options, $this->value );
|
||||
} else if ( is_string( $maybe_options ) ) {
|
||||
$options = $this->field_data( $maybe_options, false, $args['query_args'] );
|
||||
} else {
|
||||
$options = $maybe_options;
|
||||
}
|
||||
|
||||
if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
|
||||
|
||||
if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
|
||||
|
||||
echo '<select name="'. $field_name .'" class="wp_china_yes-hide-select hidden"'. $multiple_attr . $field_attr .'>';
|
||||
foreach ( $this->value as $option_key ) {
|
||||
echo '<option value="'. esc_attr( $option_key ) .'" selected>'. esc_attr( $option_key ) .'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
|
||||
$field_name = '_pseudo';
|
||||
$field_attr = '';
|
||||
|
||||
}
|
||||
|
||||
// These attributes has been serialized above.
|
||||
echo '<select name="'. esc_attr( $field_name ) .'"'. $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr .'>';
|
||||
|
||||
if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
|
||||
if ( ! empty( $args['chosen'] ) ) {
|
||||
echo '<option value=""></option>';
|
||||
} else {
|
||||
echo '<option value="">'. esc_attr( $args['placeholder'] ) .'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $options as $option_key => $option ) {
|
||||
|
||||
if ( is_array( $option ) && ! empty( $option ) ) {
|
||||
|
||||
echo '<optgroup label="'. esc_attr( $option_key ) .'">';
|
||||
|
||||
foreach ( $option as $sub_key => $sub_value ) {
|
||||
$selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
|
||||
echo '<option value="'. esc_attr( $sub_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $sub_value ) .'</option>';
|
||||
}
|
||||
|
||||
echo '</optgroup>';
|
||||
|
||||
} else {
|
||||
$selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
|
||||
echo '<option value="'. esc_attr( $option_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $option ) .'</option>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo '</select>';
|
||||
|
||||
} else {
|
||||
|
||||
echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'wp_china_yes' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-sortable' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
78
framework/fields/slider/slider.php
Executable file
|
|
@ -0,0 +1,78 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: slider
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_slider' ) ) {
|
||||
class WP_CHINA_YES_Field_slider extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'max' => 100,
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
'unit' => '',
|
||||
) );
|
||||
|
||||
$is_unit = ( ! empty( $args['unit'] ) ) ? ' wp_china_yes--is-unit' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes--wrap">';
|
||||
echo '<div class="wp_china_yes-slider-ui"></div>';
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes( array( 'class' => 'wp_china_yes-input-number'. esc_attr( $is_unit ) ) ) .' data-min="'. esc_attr( $args['min'] ) .'" data-max="'. esc_attr( $args['max'] ) .'" data-step="'. esc_attr( $args['step'] ) .'" step="any" />';
|
||||
echo ( ! empty( $args['unit'] ) ) ? '<span class="wp_china_yes--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-slider' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-slider' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width';
|
||||
$unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px';
|
||||
|
||||
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
|
||||
foreach ( $elements as $key_property => $element ) {
|
||||
if ( is_numeric( $key_property ) ) {
|
||||
if ( $mode ) {
|
||||
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}';
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
$output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
87
framework/fields/sortable/sortable.php
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: sortable
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_sortable' ) ) {
|
||||
class WP_CHINA_YES_Field_sortable extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes-sortable" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
|
||||
$pre_sortby = array();
|
||||
$pre_fields = array();
|
||||
|
||||
// Add array-keys to defined fields for sort by
|
||||
foreach ( $this->field['fields'] as $key => $field ) {
|
||||
$pre_fields[$field['id']] = $field;
|
||||
}
|
||||
|
||||
// Set sort by by saved-value or default-value
|
||||
if ( ! empty( $this->value ) ) {
|
||||
|
||||
foreach ( $this->value as $key => $value ) {
|
||||
$pre_sortby[$key] = $pre_fields[$key];
|
||||
}
|
||||
|
||||
$diff = array_diff_key( $pre_fields, $this->value );
|
||||
|
||||
if( ! empty( $diff ) ) {
|
||||
$pre_sortby = array_merge( $pre_sortby, $diff );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
foreach ( $pre_fields as $key => $value ) {
|
||||
$pre_sortby[$key] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach ( $pre_sortby as $key => $field ) {
|
||||
|
||||
echo '<div class="wp_china_yes-sortable-item">';
|
||||
|
||||
echo '<div class="wp_china_yes-sortable-content">';
|
||||
|
||||
$field_default = ( isset( $this->field['default'][$key] ) ) ? $this->field['default'][$key] : '';
|
||||
$field_value = ( isset( $this->value[$key] ) ) ? $this->value[$key] : $field_default;
|
||||
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_value, $unique_id, 'field/sortable' );
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-sortable-helper"><i class="fas fa-arrows-alt"></i></div>';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-sortable' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
76
framework/fields/sorter/sorter.php
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: sorter
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_sorter' ) ) {
|
||||
class WP_CHINA_YES_Field_sorter extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'disabled' => true,
|
||||
'enabled_title' => esc_html__( 'Enabled', 'wp_china_yes' ),
|
||||
'disabled_title' => esc_html__( 'Disabled', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
$this->value = ( ! empty( $this->value ) ) ? $this->value : $this->field['default'];
|
||||
$enabled_options = ( ! empty( $this->value['enabled'] ) ) ? $this->value['enabled'] : array();
|
||||
$disabled_options = ( ! empty( $this->value['disabled'] ) ) ? $this->value['disabled'] : array();
|
||||
|
||||
echo '<div class="wp_china_yes-sorter" data-depend-id="'. esc_attr( $this->field['id'] ) .'"></div>';
|
||||
|
||||
echo ( $args['disabled'] ) ? '<div class="wp_china_yes-modules">' : '';
|
||||
|
||||
echo ( ! empty( $args['enabled_title'] ) ) ? '<div class="wp_china_yes-sorter-title">'. esc_attr( $args['enabled_title'] ) .'</div>' : '';
|
||||
echo '<ul class="wp_china_yes-enabled">';
|
||||
if ( ! empty( $enabled_options ) ) {
|
||||
foreach ( $enabled_options as $key => $value ) {
|
||||
echo '<li><input type="hidden" name="'. esc_attr( $this->field_name( '[enabled]['. $key .']' ) ) .'" value="'. esc_attr( $value ) .'"/><label>'. esc_attr( $value ) .'</label></li>';
|
||||
}
|
||||
}
|
||||
echo '</ul>';
|
||||
|
||||
// Check for hide/show disabled section
|
||||
if ( $args['disabled'] ) {
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-modules">';
|
||||
echo ( ! empty( $args['disabled_title'] ) ) ? '<div class="wp_china_yes-sorter-title">'. esc_attr( $args['disabled_title'] ) .'</div>' : '';
|
||||
echo '<ul class="wp_china_yes-disabled">';
|
||||
if ( ! empty( $disabled_options ) ) {
|
||||
foreach ( $disabled_options as $key => $value ) {
|
||||
echo '<li><input type="hidden" name="'. esc_attr( $this->field_name( '[disabled]['. $key .']' ) ) .'" value="'. esc_attr( $value ) .'"/><label>'. esc_attr( $value ) .'</label></li>';
|
||||
}
|
||||
}
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-sortable' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
171
framework/fields/spacing/spacing.php
Executable file
|
|
@ -0,0 +1,171 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: spacing
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_spacing' ) ) {
|
||||
class WP_CHINA_YES_Field_spacing extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>',
|
||||
'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>',
|
||||
'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>',
|
||||
'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>',
|
||||
'all_icon' => '<i class="fas fa-arrows-alt"></i>',
|
||||
'top_placeholder' => esc_html__( 'top', 'wp_china_yes' ),
|
||||
'right_placeholder' => esc_html__( 'right', 'wp_china_yes' ),
|
||||
'bottom_placeholder' => esc_html__( 'bottom', 'wp_china_yes' ),
|
||||
'left_placeholder' => esc_html__( 'left', 'wp_china_yes' ),
|
||||
'all_placeholder' => esc_html__( 'all', 'wp_china_yes' ),
|
||||
'top' => true,
|
||||
'left' => true,
|
||||
'bottom' => true,
|
||||
'right' => true,
|
||||
'unit' => true,
|
||||
'show_units' => true,
|
||||
'all' => false,
|
||||
'units' => array( 'px', '%', 'em' )
|
||||
) );
|
||||
|
||||
$default_values = array(
|
||||
'top' => '',
|
||||
'right' => '',
|
||||
'bottom' => '',
|
||||
'left' => '',
|
||||
'all' => '',
|
||||
'unit' => 'px',
|
||||
);
|
||||
|
||||
$value = wp_parse_args( $this->value, $default_values );
|
||||
$unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
|
||||
$is_unit = ( ! empty( $unit ) ) ? ' wp_china_yes--is-unit' : '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
|
||||
if ( ! empty( $args['all'] ) ) {
|
||||
|
||||
$placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo ( ! empty( $args['all_icon'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--icon">'. $args['all_icon'] .'</span>' : '';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="wp_china_yes-input-number'. esc_attr( $is_unit ) .'" step="any" />';
|
||||
echo ( $unit ) ? '<span class="wp_china_yes--label wp_china_yes--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
|
||||
} else {
|
||||
|
||||
$properties = array();
|
||||
|
||||
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
|
||||
if ( ! empty( $args[$prop] ) ) {
|
||||
$properties[] = $prop;
|
||||
}
|
||||
}
|
||||
|
||||
$properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties;
|
||||
|
||||
foreach ( $properties as $property ) {
|
||||
|
||||
$placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="wp_china_yes--label wp_china_yes--icon">'. $args[$property.'_icon'] .'</span>' : '';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="wp_china_yes-input-number'. esc_attr( $is_unit ) .'" step="any" />';
|
||||
echo ( $unit ) ? '<span class="wp_china_yes--label wp_china_yes--unit">'. esc_attr( $args['units'][0] ) .'</span>' : '';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
|
||||
echo '<div class="wp_china_yes--input">';
|
||||
echo '<select name="'. esc_attr( $this->field_name( '[unit]' ) ) .'">';
|
||||
foreach ( $args['units'] as $unit ) {
|
||||
$selected = ( $value['unit'] === $unit ) ? ' selected' : '';
|
||||
echo '<option value="'. esc_attr( $unit ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $unit ) .'</option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
|
||||
|
||||
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'padding';
|
||||
|
||||
if ( $mode === 'border-radius' || $mode === 'radius' ) {
|
||||
|
||||
$top = 'border-top-left-radius';
|
||||
$right = 'border-top-right-radius';
|
||||
$bottom = 'border-bottom-right-radius';
|
||||
$left = 'border-bottom-left-radius';
|
||||
|
||||
} else if ( $mode === 'relative' || $mode === 'absolute' || $mode === 'none' ) {
|
||||
|
||||
$top = 'top';
|
||||
$right = 'right';
|
||||
$bottom = 'bottom';
|
||||
$left = 'left';
|
||||
|
||||
} else {
|
||||
|
||||
$top = $mode .'-top';
|
||||
$right = $mode .'-right';
|
||||
$bottom = $mode .'-bottom';
|
||||
$left = $mode .'-left';
|
||||
|
||||
}
|
||||
|
||||
if ( ! empty( $this->field['all'] ) && isset( $this->value['all'] ) && $this->value['all'] !== '' ) {
|
||||
|
||||
$output = $element .'{';
|
||||
$output .= $top .':'. $this->value['all'] . $unit . $important .';';
|
||||
$output .= $right .':'. $this->value['all'] . $unit . $important .';';
|
||||
$output .= $bottom .':'. $this->value['all'] . $unit . $important .';';
|
||||
$output .= $left .':'. $this->value['all'] . $unit . $important .';';
|
||||
$output .= '}';
|
||||
|
||||
} else {
|
||||
|
||||
$top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $top .':'. $this->value['top'] . $unit . $important .';' : '';
|
||||
$right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $right .':'. $this->value['right'] . $unit . $important .';' : '';
|
||||
$bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $bottom .':'. $this->value['bottom'] . $unit . $important .';' : '';
|
||||
$left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $left .':'. $this->value['left'] . $unit . $important .';' : '';
|
||||
|
||||
if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' ) {
|
||||
$output = $element .'{'. $top . $right . $bottom . $left .'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
70
framework/fields/spinner/spinner.php
Executable file
|
|
@ -0,0 +1,70 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: spinner
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_spinner' ) ) {
|
||||
class WP_CHINA_YES_Field_spinner extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'max' => 100,
|
||||
'min' => 0,
|
||||
'step' => 1,
|
||||
'unit' => '',
|
||||
) );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes--spin"><input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes( array( 'class' => 'wp_china_yes-input-number' ) ) .' data-min="'. esc_attr( $args['min'] ) .'" data-max="'. esc_attr( $args['max'] ) .'" data-step="'. esc_attr( $args['step'] ) .'" data-unit="'. esc_attr( $args['unit'] ) .'" step="any" /></div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'jquery-ui-spinner' ) ) {
|
||||
wp_enqueue_script( 'jquery-ui-spinner' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width';
|
||||
$unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px';
|
||||
|
||||
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
|
||||
foreach ( $elements as $key_property => $element ) {
|
||||
if ( is_numeric( $key_property ) ) {
|
||||
if ( $mode ) {
|
||||
$output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}';
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
$output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
24
framework/fields/subheading/subheading.php
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: subheading
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_subheading' ) ) {
|
||||
class WP_CHINA_YES_Field_subheading extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
echo ( ! empty( $this->field['content'] ) ) ? $this->field['content'] : '';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
26
framework/fields/submessage/submessage.php
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: submessage
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_submessage' ) ) {
|
||||
class WP_CHINA_YES_Field_submessage extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$style = ( ! empty( $this->field['style'] ) ) ? $this->field['style'] : 'normal';
|
||||
|
||||
echo '<div class="wp_china_yes-submessage wp_china_yes-submessage-'. esc_attr( $style ) .'">'. $this->field['content'] .'</div>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
40
framework/fields/switcher/switcher.php
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: switcher
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_switcher' ) ) {
|
||||
class WP_CHINA_YES_Field_switcher extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$active = ( ! empty( $this->value ) ) ? ' wp_china_yes--active' : '';
|
||||
$text_on = ( ! empty( $this->field['text_on'] ) ) ? $this->field['text_on'] : esc_html__( 'On', 'wp_china_yes' );
|
||||
$text_off = ( ! empty( $this->field['text_off'] ) ) ? $this->field['text_off'] : esc_html__( 'Off', 'wp_china_yes' );
|
||||
$text_width = ( ! empty( $this->field['text_width'] ) ) ? ' style="width: '. esc_attr( $this->field['text_width'] ) .'px;"': '';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes--switcher'. esc_attr( $active ) .'"'. $text_width .'>';
|
||||
echo '<span class="wp_china_yes--on">'. esc_attr( $text_on ) .'</span>';
|
||||
echo '<span class="wp_china_yes--off">'. esc_attr( $text_off ) .'</span>';
|
||||
echo '<span class="wp_china_yes--ball"></span>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' />';
|
||||
echo '</div>';
|
||||
|
||||
echo ( ! empty( $this->field['label'] ) ) ? '<span class="wp_china_yes--label">'. esc_attr( $this->field['label'] ) . '</span>' : '';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
64
framework/fields/tabbed/tabbed.php
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: tabbed
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_tabbed' ) ) {
|
||||
class WP_CHINA_YES_Field_tabbed extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$unallows = array( 'tabbed' );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<div class="wp_china_yes-tabbed-nav" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
|
||||
foreach ( $this->field['tabs'] as $key => $tab ) {
|
||||
|
||||
$tabbed_icon = ( ! empty( $tab['icon'] ) ) ? '<i class="wp_china_yes--icon '. esc_attr( $tab['icon'] ) .'"></i>' : '';
|
||||
$tabbed_active = ( empty( $key ) ) ? 'wp_china_yes-tabbed-active' : '';
|
||||
|
||||
echo '<a href="#" class="'. esc_attr( $tabbed_active ) .'"">'. $tabbed_icon . esc_attr( $tab['title'] ) .'</a>';
|
||||
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes-tabbed-contents">';
|
||||
foreach ( $this->field['tabs'] as $key => $tab ) {
|
||||
|
||||
$tabbed_hidden = ( ! empty( $key ) ) ? ' hidden' : '';
|
||||
|
||||
echo '<div class="wp_china_yes-tabbed-content'. esc_attr( $tabbed_hidden ) .'">';
|
||||
|
||||
foreach ( $tab['fields'] as $field ) {
|
||||
|
||||
if ( in_array( $field['type'], $unallows ) ) { $field['_notice'] = true; }
|
||||
|
||||
$field_id = ( isset( $field['id'] ) ) ? $field['id'] : '';
|
||||
$field_default = ( isset( $field['default'] ) ) ? $field['default'] : '';
|
||||
$field_value = ( isset( $this->value[$field_id] ) ) ? $this->value[$field_id] : $field_default;
|
||||
$unique_id = ( ! empty( $this->unique ) ) ? $this->unique .'['. $this->field['id'] .']' : $this->field['id'];
|
||||
|
||||
WP_CHINA_YES::field( $field, $field_value, $unique_id, 'field/tabbed' );
|
||||
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
30
framework/fields/text/text.php
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: text
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_text' ) ) {
|
||||
class WP_CHINA_YES_Field_text extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$type = ( ! empty( $this->field['attributes']['type'] ) ) ? $this->field['attributes']['type'] : 'text';
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' />';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
58
framework/fields/textarea/textarea.php
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: textarea
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_textarea' ) ) {
|
||||
class WP_CHINA_YES_Field_textarea extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
echo $this->field_before();
|
||||
echo $this->shortcoder();
|
||||
echo '<textarea name="'. esc_attr( $this->field_name() ) .'"'. $this->field_attributes() .'>'. $this->value .'</textarea>';
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function shortcoder() {
|
||||
|
||||
if ( ! empty( $this->field['shortcoder'] ) ) {
|
||||
|
||||
$shortcodes = ( is_array( $this->field['shortcoder'] ) ) ? $this->field['shortcoder'] : array_filter( (array) $this->field['shortcoder'] );
|
||||
$instances = ( ! empty( WP_CHINA_YES::$shortcode_instances ) ) ? WP_CHINA_YES::$shortcode_instances : array();
|
||||
|
||||
if ( ! empty( $shortcodes ) && ! empty( $instances ) ) {
|
||||
|
||||
foreach ( $shortcodes as $shortcode ) {
|
||||
|
||||
foreach ( $instances as $instance ) {
|
||||
|
||||
if ( $instance['modal_id'] === $shortcode ) {
|
||||
|
||||
$id = $instance['modal_id'];
|
||||
$title = $instance['button_title'];
|
||||
|
||||
echo '<a href="#" class="button button-primary wp_china_yes-shortcode-button" data-modal-id="'. esc_attr( $id ) .'">'. esc_html( $title ) .'</a>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
1607
framework/fields/typography/google-fonts.php
Executable file
544
framework/fields/typography/typography.php
Executable file
|
|
@ -0,0 +1,544 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: typography
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_typography' ) ) {
|
||||
class WP_CHINA_YES_Field_typography extends WP_CHINA_YES_Fields {
|
||||
|
||||
public $chosen = false;
|
||||
|
||||
public $value = array();
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'font_family' => true,
|
||||
'font_weight' => true,
|
||||
'font_style' => true,
|
||||
'font_size' => true,
|
||||
'line_height' => true,
|
||||
'letter_spacing' => true,
|
||||
'text_align' => true,
|
||||
'text_transform' => true,
|
||||
'color' => true,
|
||||
'chosen' => true,
|
||||
'preview' => true,
|
||||
'subset' => true,
|
||||
'multi_subset' => false,
|
||||
'extra_styles' => false,
|
||||
'backup_font_family' => false,
|
||||
'font_variant' => false,
|
||||
'word_spacing' => false,
|
||||
'text_decoration' => false,
|
||||
'custom_style' => false,
|
||||
'compact' => false,
|
||||
'exclude' => '',
|
||||
'unit' => 'px',
|
||||
'line_height_unit' => '',
|
||||
'preview_text' => 'The quick brown fox jumps over the lazy dog',
|
||||
) );
|
||||
|
||||
if ( $args['compact'] ) {
|
||||
$args['text_transform'] = false;
|
||||
$args['text_align'] = false;
|
||||
$args['font_size'] = false;
|
||||
$args['line_height'] = false;
|
||||
$args['letter_spacing'] = false;
|
||||
$args['preview'] = false;
|
||||
$args['color'] = false;
|
||||
}
|
||||
|
||||
$default_value = array(
|
||||
'font-family' => '',
|
||||
'font-weight' => '',
|
||||
'font-style' => '',
|
||||
'font-variant' => '',
|
||||
'font-size' => '',
|
||||
'line-height' => '',
|
||||
'letter-spacing' => '',
|
||||
'word-spacing' => '',
|
||||
'text-align' => '',
|
||||
'text-transform' => '',
|
||||
'text-decoration' => '',
|
||||
'backup-font-family' => '',
|
||||
'color' => '',
|
||||
'custom-style' => '',
|
||||
'type' => '',
|
||||
'subset' => '',
|
||||
'extra-styles' => array(),
|
||||
);
|
||||
|
||||
$default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
|
||||
$this->value = wp_parse_args( $this->value, $default_value );
|
||||
$this->chosen = $args['chosen'];
|
||||
$chosen_class = ( $this->chosen ) ? ' wp_china_yes--chosen' : '';
|
||||
$line_height_unit = ( ! empty( $args['line_height_unit'] ) ) ? $args['line_height_unit'] : $args['unit'];
|
||||
|
||||
echo '<div class="wp_china_yes--typography'. esc_attr( $chosen_class ) .'" data-depend-id="'. esc_attr( $this->field['id'] ) .'" data-unit="'. esc_attr( $args['unit'] ) .'" data-line-height-unit="'. esc_attr( $line_height_unit ) .'" data-exclude="'. esc_attr( $args['exclude'] ) .'">';
|
||||
|
||||
echo '<div class="wp_china_yes--blocks wp_china_yes--blocks-selects">';
|
||||
|
||||
//
|
||||
// Font Family
|
||||
if ( ! empty( $args['font_family'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Font Family', 'wp_china_yes' ) .'</div>';
|
||||
echo $this->create_select( array( $this->value['font-family'] => $this->value['font-family'] ), 'font-family', esc_html__( 'Select a font', 'wp_china_yes' ) );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Backup Font Family
|
||||
if ( ! empty( $args['backup_font_family'] ) ) {
|
||||
echo '<div class="wp_china_yes--block wp_china_yes--block-backup-font-family hidden">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Backup Font Family', 'wp_china_yes' ) .'</div>';
|
||||
echo $this->create_select( apply_filters( 'wp_china_yes_field_typography_backup_font_family', array(
|
||||
'Arial, Helvetica, sans-serif',
|
||||
"'Arial Black', Gadget, sans-serif",
|
||||
"'Comic Sans MS', cursive, sans-serif",
|
||||
'Impact, Charcoal, sans-serif',
|
||||
"'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
|
||||
'Tahoma, Geneva, sans-serif',
|
||||
"'Trebuchet MS', Helvetica, sans-serif",
|
||||
'Verdana, Geneva, sans-serif',
|
||||
"'Courier New', Courier, monospace",
|
||||
"'Lucida Console', Monaco, monospace",
|
||||
'Georgia, serif',
|
||||
'Palatino Linotype'
|
||||
) ), 'backup-font-family', esc_html__( 'Default', 'wp_china_yes' ) );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Font Style and Extra Style Select
|
||||
if ( ! empty( $args['font_weight'] ) || ! empty( $args['font_style'] ) ) {
|
||||
|
||||
//
|
||||
// Font Style Select
|
||||
echo '<div class="wp_china_yes--block wp_china_yes--block-font-style hidden">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Font Style', 'wp_china_yes') .'</div>';
|
||||
echo '<select class="wp_china_yes--font-style-select" data-placeholder="Default">';
|
||||
echo '<option value="">'. ( ! $this->chosen ? esc_html__( 'Default', 'wp_china_yes' ) : '' ) .'</option>';
|
||||
if ( ! empty( $this->value['font-weight'] ) || ! empty( $this->value['font-style'] ) ) {
|
||||
echo '<option value="'. esc_attr( strtolower( $this->value['font-weight'] . $this->value['font-style'] ) ) .'" selected></option>';
|
||||
}
|
||||
echo '</select>';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[font-weight]' ) ) .'" class="wp_china_yes--font-weight" value="'. esc_attr( $this->value['font-weight'] ) .'" />';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[font-style]' ) ) .'" class="wp_china_yes--font-style" value="'. esc_attr( $this->value['font-style'] ) .'" />';
|
||||
|
||||
//
|
||||
// Extra Font Style Select
|
||||
if ( ! empty( $args['extra_styles'] ) ) {
|
||||
echo '<div class="wp_china_yes--block-extra-styles hidden">';
|
||||
echo ( ! $this->chosen ) ? '<div class="wp_china_yes--title">'. esc_html__( 'Load Extra Styles', 'wp_china_yes' ) .'</div>' : '';
|
||||
$placeholder = ( $this->chosen ) ? esc_html__( 'Load Extra Styles', 'wp_china_yes' ) : esc_html__( 'Default', 'wp_china_yes' );
|
||||
echo $this->create_select( $this->value['extra-styles'], 'extra-styles', $placeholder, true );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Subset
|
||||
if ( ! empty( $args['subset'] ) ) {
|
||||
echo '<div class="wp_china_yes--block wp_china_yes--block-subset hidden">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Subset', 'wp_china_yes' ) .'</div>';
|
||||
$subset = ( is_array( $this->value['subset'] ) ) ? $this->value['subset'] : array_filter( (array) $this->value['subset'] );
|
||||
echo $this->create_select( $subset, 'subset', esc_html__( 'Default', 'wp_china_yes' ), $args['multi_subset'] );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Text Align
|
||||
if ( ! empty( $args['text_align'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Text Align', 'wp_china_yes' ) .'</div>';
|
||||
echo $this->create_select( array(
|
||||
'inherit' => esc_html__( 'Inherit', 'wp_china_yes' ),
|
||||
'left' => esc_html__( 'Left', 'wp_china_yes' ),
|
||||
'center' => esc_html__( 'Center', 'wp_china_yes' ),
|
||||
'right' => esc_html__( 'Right', 'wp_china_yes' ),
|
||||
'justify' => esc_html__( 'Justify', 'wp_china_yes' ),
|
||||
'initial' => esc_html__( 'Initial', 'wp_china_yes' )
|
||||
), 'text-align', esc_html__( 'Default', 'wp_china_yes' ) );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Font Variant
|
||||
if ( ! empty( $args['font_variant'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Font Variant', 'wp_china_yes' ) .'</div>';
|
||||
echo $this->create_select( array(
|
||||
'normal' => esc_html__( 'Normal', 'wp_china_yes' ),
|
||||
'small-caps' => esc_html__( 'Small Caps', 'wp_china_yes' ),
|
||||
'all-small-caps' => esc_html__( 'All Small Caps', 'wp_china_yes' )
|
||||
), 'font-variant', esc_html__( 'Default', 'wp_china_yes' ) );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Text Transform
|
||||
if ( ! empty( $args['text_transform'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Text Transform', 'wp_china_yes' ) .'</div>';
|
||||
echo $this->create_select( array(
|
||||
'none' => esc_html__( 'None', 'wp_china_yes' ),
|
||||
'capitalize' => esc_html__( 'Capitalize', 'wp_china_yes' ),
|
||||
'uppercase' => esc_html__( 'Uppercase', 'wp_china_yes' ),
|
||||
'lowercase' => esc_html__( 'Lowercase', 'wp_china_yes' )
|
||||
), 'text-transform', esc_html__( 'Default', 'wp_china_yes' ) );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Text Decoration
|
||||
if ( ! empty( $args['text_decoration'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Text Decoration', 'wp_china_yes' ) .'</div>';
|
||||
echo $this->create_select( array(
|
||||
'none' => esc_html__( 'None', 'wp_china_yes' ),
|
||||
'underline' => esc_html__( 'Solid', 'wp_china_yes' ),
|
||||
'underline double' => esc_html__( 'Double', 'wp_china_yes' ),
|
||||
'underline dotted' => esc_html__( 'Dotted', 'wp_china_yes' ),
|
||||
'underline dashed' => esc_html__( 'Dashed', 'wp_china_yes' ),
|
||||
'underline wavy' => esc_html__( 'Wavy', 'wp_china_yes' ),
|
||||
'underline overline' => esc_html__( 'Overline', 'wp_china_yes' ),
|
||||
'line-through' => esc_html__( 'Line-through', 'wp_china_yes' )
|
||||
), 'text-decoration', esc_html__( 'Default', 'wp_china_yes' ) );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="wp_china_yes--blocks wp_china_yes--blocks-inputs">';
|
||||
|
||||
//
|
||||
// Font Size
|
||||
if ( ! empty( $args['font_size'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Font Size', 'wp_china_yes' ) .'</div>';
|
||||
echo '<div class="wp_china_yes--input-wrap">';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[font-size]' ) ) .'" class="wp_china_yes--font-size wp_china_yes--input wp_china_yes-input-number" value="'. esc_attr( $this->value['font-size'] ) .'" step="any" />';
|
||||
echo '<span class="wp_china_yes--unit">'. esc_attr( $args['unit'] ) .'</span>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Line Height
|
||||
if ( ! empty( $args['line_height'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Line Height', 'wp_china_yes' ) .'</div>';
|
||||
echo '<div class="wp_china_yes--input-wrap">';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[line-height]' ) ) .'" class="wp_china_yes--line-height wp_china_yes--input wp_china_yes-input-number" value="'. esc_attr( $this->value['line-height'] ) .'" step="any" />';
|
||||
echo '<span class="wp_china_yes--unit">'. esc_attr( $line_height_unit ) .'</span>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Letter Spacing
|
||||
if ( ! empty( $args['letter_spacing'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Letter Spacing', 'wp_china_yes' ) .'</div>';
|
||||
echo '<div class="wp_china_yes--input-wrap">';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[letter-spacing]' ) ) .'" class="wp_china_yes--letter-spacing wp_china_yes--input wp_china_yes-input-number" value="'. esc_attr( $this->value['letter-spacing'] ) .'" step="any" />';
|
||||
echo '<span class="wp_china_yes--unit">'. esc_attr( $args['unit'] ) .'</span>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Word Spacing
|
||||
if ( ! empty( $args['word_spacing'] ) ) {
|
||||
echo '<div class="wp_china_yes--block">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Word Spacing', 'wp_china_yes' ) .'</div>';
|
||||
echo '<div class="wp_china_yes--input-wrap">';
|
||||
echo '<input type="number" name="'. esc_attr( $this->field_name( '[word-spacing]' ) ) .'" class="wp_china_yes--word-spacing wp_china_yes--input wp_china_yes-input-number" value="'. esc_attr( $this->value['word-spacing'] ) .'" step="any" />';
|
||||
echo '<span class="wp_china_yes--unit">'. esc_attr( $args['unit'] ) .'</span>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
//
|
||||
// Font Color
|
||||
if ( ! empty( $args['color'] ) ) {
|
||||
$default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="'. esc_attr( $default_value['color'] ) .'"' : '';
|
||||
echo '<div class="wp_china_yes--block wp_china_yes--block-font-color">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Font Color', 'wp_china_yes' ) .'</div>';
|
||||
echo '<div class="wp_china_yes-field-color">';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name( '[color]' ) ) .'" class="wp_china_yes-color wp_china_yes--color" value="'. esc_attr( $this->value['color'] ) .'"'. $default_color_attr .' />';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Custom style
|
||||
if ( ! empty( $args['custom_style'] ) ) {
|
||||
echo '<div class="wp_china_yes--block wp_china_yes--block-custom-style">';
|
||||
echo '<div class="wp_china_yes--title">'. esc_html__( 'Custom Style', 'wp_china_yes' ) .'</div>';
|
||||
echo '<textarea name="'. esc_attr( $this->field_name( '[custom-style]' ) ) .'" class="wp_china_yes--custom-style">'. esc_attr( $this->value['custom-style'] ) .'</textarea>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
//
|
||||
// Preview
|
||||
$always_preview = ( $args['preview'] !== 'always' ) ? ' hidden' : '';
|
||||
|
||||
if ( ! empty( $args['preview'] ) ) {
|
||||
echo '<div class="wp_china_yes--block wp_china_yes--block-preview'. esc_attr( $always_preview ) .'">';
|
||||
echo '<div class="wp_china_yes--toggle fas fa-toggle-off"></div>';
|
||||
echo '<div class="wp_china_yes--preview">'. esc_attr( $args['preview_text'] ) .'</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[type]' ) ) .'" class="wp_china_yes--type" value="'. esc_attr( $this->value['type'] ) .'" />';
|
||||
echo '<input type="hidden" name="'. esc_attr( $this->field_name( '[unit]' ) ) .'" class="wp_china_yes--unit-save" value="'. esc_attr( $args['unit'] ) .'" />';
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
|
||||
public function create_select( $options, $name, $placeholder = '', $is_multiple = false ) {
|
||||
|
||||
$multiple_name = ( $is_multiple ) ? '[]' : '';
|
||||
$multiple_attr = ( $is_multiple ) ? ' multiple data-multiple="true"' : '';
|
||||
$chosen_rtl = ( $this->chosen && is_rtl() ) ? ' chosen-rtl' : '';
|
||||
|
||||
$output = '<select name="'. esc_attr( $this->field_name( '['. $name .']'. $multiple_name ) ) .'" class="wp_china_yes--'. esc_attr( $name ) . esc_attr( $chosen_rtl ) .'" data-placeholder="'. esc_attr( $placeholder ) .'"'. $multiple_attr .'>';
|
||||
$output .= ( ! empty( $placeholder ) ) ? '<option value="">'. esc_attr( ( ! $this->chosen ) ? $placeholder : '' ) .'</option>' : '';
|
||||
|
||||
if ( ! empty( $options ) ) {
|
||||
foreach ( $options as $option_key => $option_value ) {
|
||||
if ( $is_multiple ) {
|
||||
$selected = ( in_array( $option_value, $this->value[$name] ) ) ? ' selected' : '';
|
||||
$output .= '<option value="'. esc_attr( $option_value ) .'"'. esc_attr( $selected ).'>'. esc_attr( $option_value ) .'</option>';
|
||||
} else {
|
||||
$option_key = ( is_numeric( $option_key ) ) ? $option_value : $option_key;
|
||||
$selected = ( $option_key === $this->value[$name] ) ? ' selected' : '';
|
||||
$output .= '<option value="'. esc_attr( $option_key ) .'"'. esc_attr( $selected ).'>'. esc_attr( $option_value ) .'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '</select>';
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
public function enqueue() {
|
||||
|
||||
if ( ! wp_script_is( 'wp_china_yes-webfontloader' ) ) {
|
||||
|
||||
WP_CHINA_YES::include_plugin_file( 'fields/typography/google-fonts.php' );
|
||||
|
||||
wp_enqueue_script( 'wp_china_yes-webfontloader', 'https://jsd.admincdn.com/npm/webfontloader@1.6.28/webfontloader.min.js', array( 'wp_china_yes' ), '1.6.28', true );
|
||||
|
||||
$webfonts = array();
|
||||
|
||||
$customwebfonts = apply_filters( 'wp_china_yes_field_typography_customwebfonts', array() );
|
||||
|
||||
if ( ! empty( $customwebfonts ) ) {
|
||||
$webfonts['custom'] = array(
|
||||
'label' => esc_html__( 'Custom Web Fonts', 'wp_china_yes' ),
|
||||
'fonts' => $customwebfonts
|
||||
);
|
||||
}
|
||||
|
||||
$webfonts['safe'] = array(
|
||||
'label' => esc_html__( 'Safe Web Fonts', 'wp_china_yes' ),
|
||||
'fonts' => apply_filters( 'wp_china_yes_field_typography_safewebfonts', array(
|
||||
'Arial',
|
||||
'Arial Black',
|
||||
'Helvetica',
|
||||
'Times New Roman',
|
||||
'Courier New',
|
||||
'Tahoma',
|
||||
'Verdana',
|
||||
'Impact',
|
||||
'Trebuchet MS',
|
||||
'Comic Sans MS',
|
||||
'Lucida Console',
|
||||
'Lucida Sans Unicode',
|
||||
'Georgia, serif',
|
||||
'Palatino Linotype'
|
||||
)
|
||||
) );
|
||||
|
||||
$webfonts['google'] = array(
|
||||
'label' => esc_html__( 'Google Web Fonts', 'wp_china_yes' ),
|
||||
'fonts' => apply_filters( 'wp_china_yes_field_typography_googlewebfonts', wp_china_yes_get_google_fonts()
|
||||
) );
|
||||
|
||||
$defaultstyles = apply_filters( 'wp_china_yes_field_typography_defaultstyles', array( 'normal', 'italic', '700', '700italic' ) );
|
||||
|
||||
$googlestyles = apply_filters( 'wp_china_yes_field_typography_googlestyles', array(
|
||||
'100' => 'Thin 100',
|
||||
'100italic' => 'Thin 100 Italic',
|
||||
'200' => 'Extra-Light 200',
|
||||
'200italic' => 'Extra-Light 200 Italic',
|
||||
'300' => 'Light 300',
|
||||
'300italic' => 'Light 300 Italic',
|
||||
'normal' => 'Normal 400',
|
||||
'italic' => 'Normal 400 Italic',
|
||||
'500' => 'Medium 500',
|
||||
'500italic' => 'Medium 500 Italic',
|
||||
'600' => 'Semi-Bold 600',
|
||||
'600italic' => 'Semi-Bold 600 Italic',
|
||||
'700' => 'Bold 700',
|
||||
'700italic' => 'Bold 700 Italic',
|
||||
'800' => 'Extra-Bold 800',
|
||||
'800italic' => 'Extra-Bold 800 Italic',
|
||||
'900' => 'Black 900',
|
||||
'900italic' => 'Black 900 Italic'
|
||||
) );
|
||||
|
||||
$webfonts = apply_filters( 'wp_china_yes_field_typography_webfonts', $webfonts );
|
||||
|
||||
wp_localize_script( 'wp_china_yes', 'wp_china_yes_typography_json', array(
|
||||
'webfonts' => $webfonts,
|
||||
'defaultstyles' => $defaultstyles,
|
||||
'googlestyles' => $googlestyles
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function enqueue_google_fonts( $method = 'enqueue' ) {
|
||||
|
||||
$is_google = false;
|
||||
|
||||
if ( ! empty( $this->value['type'] ) ) {
|
||||
$is_google = ( $this->value['type'] === 'google' ) ? true : false;
|
||||
} else {
|
||||
WP_CHINA_YES::include_plugin_file( 'fields/typography/google-fonts.php' );
|
||||
$is_google = ( array_key_exists( $this->value['font-family'], wp_china_yes_get_google_fonts() ) ) ? true : false;
|
||||
}
|
||||
|
||||
if ( $is_google ) {
|
||||
|
||||
// set style
|
||||
$font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : '';
|
||||
$font_weight = ( ! empty( $this->value['font-weight'] ) ) ? $this->value['font-weight'] : '';
|
||||
$font_style = ( ! empty( $this->value['font-style'] ) ) ? $this->value['font-style'] : '';
|
||||
|
||||
if ( $font_weight || $font_style ) {
|
||||
$style = $font_weight . $font_style;
|
||||
if ( ! empty( $style ) ) {
|
||||
$style = ( $style === 'normal' ) ? '400' : $style;
|
||||
WP_CHINA_YES::$webfonts[$method][$font_family][$style] = $style;
|
||||
}
|
||||
} else {
|
||||
WP_CHINA_YES::$webfonts[$method][$font_family] = array();
|
||||
}
|
||||
|
||||
// set extra styles
|
||||
if ( ! empty( $this->value['extra-styles'] ) ) {
|
||||
foreach ( $this->value['extra-styles'] as $extra_style ) {
|
||||
if ( ! empty( $extra_style ) ) {
|
||||
$extra_style = ( $extra_style === 'normal' ) ? '400' : $extra_style;
|
||||
WP_CHINA_YES::$webfonts[$method][$font_family][$extra_style] = $extra_style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set subsets
|
||||
if ( ! empty( $this->value['subset'] ) ) {
|
||||
$this->value['subset'] = ( is_array( $this->value['subset'] ) ) ? $this->value['subset'] : array_filter( (array) $this->value['subset'] );
|
||||
foreach ( $this->value['subset'] as $subset ) {
|
||||
if( ! empty( $subset ) ) {
|
||||
WP_CHINA_YES::$subsets[$subset] = $subset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public function output() {
|
||||
|
||||
$output = '';
|
||||
$bg_image = array();
|
||||
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
|
||||
$element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
|
||||
|
||||
$font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : '';
|
||||
$backup_family = ( ! empty( $this->value['backup-font-family'] ) ) ? ', '. $this->value['backup-font-family'] : '';
|
||||
|
||||
if ( $font_family ) {
|
||||
$output .= 'font-family:"'. $font_family .'"'. $backup_family . $important .';';
|
||||
}
|
||||
|
||||
// Common font properties
|
||||
$properties = array(
|
||||
'color',
|
||||
'font-weight',
|
||||
'font-style',
|
||||
'font-variant',
|
||||
'text-align',
|
||||
'text-transform',
|
||||
'text-decoration',
|
||||
);
|
||||
|
||||
foreach ( $properties as $property ) {
|
||||
if ( isset( $this->value[$property] ) && $this->value[$property] !== '' ) {
|
||||
$output .= $property .':'. $this->value[$property] . $important .';';
|
||||
}
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'font-size',
|
||||
'line-height',
|
||||
'letter-spacing',
|
||||
'word-spacing',
|
||||
);
|
||||
|
||||
$unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
|
||||
$line_height_unit = ( ! empty( $this->value['line_height_unit'] ) ) ? $this->value['line_height_unit'] : $unit;
|
||||
|
||||
foreach ( $properties as $property ) {
|
||||
if ( isset( $this->value[$property] ) && $this->value[$property] !== '' ) {
|
||||
$unit = ( $property === 'line-height' ) ? $line_height_unit : $unit;
|
||||
$output .= $property .':'. $this->value[$property] . $unit . $important .';';
|
||||
}
|
||||
}
|
||||
|
||||
$custom_style = ( ! empty( $this->value['custom-style'] ) ) ? $this->value['custom-style'] : '';
|
||||
|
||||
if ( $output ) {
|
||||
$output = $element .'{'. $output . $custom_style .'}';
|
||||
}
|
||||
|
||||
$this->parent->output_css .= $output;
|
||||
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
61
framework/fields/upload/upload.php
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
|
||||
/**
|
||||
*
|
||||
* Field: upload
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @version 1.0.0
|
||||
*
|
||||
*/
|
||||
if ( ! class_exists( 'WP_CHINA_YES_Field_upload' ) ) {
|
||||
class WP_CHINA_YES_Field_upload extends WP_CHINA_YES_Fields {
|
||||
|
||||
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
|
||||
parent::__construct( $field, $value, $unique, $where, $parent );
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
$args = wp_parse_args( $this->field, array(
|
||||
'library' => array(),
|
||||
'preview' => false,
|
||||
'preview_width' => '',
|
||||
'preview_height' => '',
|
||||
'button_title' => esc_html__( 'Upload', 'wp_china_yes' ),
|
||||
'remove_title' => esc_html__( 'Remove', 'wp_china_yes' ),
|
||||
) );
|
||||
|
||||
echo $this->field_before();
|
||||
|
||||
$library = ( is_array( $args['library'] ) ) ? $args['library'] : array_filter( (array) $args['library'] );
|
||||
$library = ( ! empty( $library ) ) ? implode(',', $library ) : '';
|
||||
$hidden = ( empty( $this->value ) ) ? ' hidden' : '';
|
||||
|
||||
if ( ! empty( $args['preview'] ) ) {
|
||||
|
||||
$preview_type = ( ! empty( $this->value ) ) ? strtolower( substr( strrchr( $this->value, '.' ), 1 ) ) : '';
|
||||
$preview_src = ( ! empty( $preview_type ) && in_array( $preview_type, array( 'jpg', 'jpeg', 'gif', 'png', 'svg', 'webp' ) ) ) ? $this->value : '';
|
||||
$preview_width = ( ! empty( $args['preview_width'] ) ) ? 'max-width:'. esc_attr( $args['preview_width'] ) .'px;' : '';
|
||||
$preview_height = ( ! empty( $args['preview_height'] ) ) ? 'max-height:'. esc_attr( $args['preview_height'] ) .'px;' : '';
|
||||
$preview_style = ( ! empty( $preview_width ) || ! empty( $preview_height ) ) ? ' style="'. esc_attr( $preview_width . $preview_height ) .'"': '';
|
||||
$preview_hidden = ( empty( $preview_src ) ) ? ' hidden' : '';
|
||||
|
||||
echo '<div class="wp_china_yes--preview'. esc_attr( $preview_hidden ) .'">';
|
||||
echo '<div class="wp_china_yes-image-preview"'. $preview_style .'>';
|
||||
echo '<i class="wp_china_yes--remove fas fa-times"></i><span><img src="'. esc_url( $preview_src ) .'" class="wp_china_yes--src" /></span>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
echo '<div class="wp_china_yes--wrap">';
|
||||
echo '<input type="text" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .'/>';
|
||||
echo '<a href="#" class="button button-primary wp_china_yes--button" data-library="'. esc_attr( $library ) .'">'. $args['button_title'] .'</a>';
|
||||
echo '<a href="#" class="button button-secondary wp_china_yes-warning-primary wp_china_yes--remove'. esc_attr( $hidden ) .'">'. $args['remove_title'] .'</a>';
|
||||
echo '</div>';
|
||||
|
||||
echo $this->field_after();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||