根本原因:kratos_option() 运行时只读数据库,`std` 仅在后台表单预填和 「恢复默认」时生效,前台根本读不到。因此新装站点所有图片项都是空值。 另外 isset() 挡不住「用户清空」——of_sanitize_upload() 对空输入返回 '', 键存在且值为空串,调用方传的兜底值被绕过。 同时不能把绝对 URL 写进 std:它会随保存一起写库,主题目录改名/换 CDN/ 迁站后永久 404。本站 s_wechat_url / g_donate_alipay / g_donate_wechat 三项就指向已删除的 kratos-master 目录,一直在破图(这三项是 hidden 字段, 后台界面上看不到,所以坏了很久没人发现)。 做法: - 新增 inc/theme-option-defaults.php,图片默认值注册表(11 项), 默认图一律运行时给出,不写数据库。 - yang_option_image() 三层判断:空/纯空白 → 默认图;指向已不存在的主题 目录 → 默认图;文件不存在则不输出地址(避免换来一个 404)。 - 陈旧判断用 get_template()(主题 slug)而非 basename(目录名),避免本地 开发目录名与 slug 不一致时误伤当前主题自己的图。 - 模板统一走取值函数:header(logo/favicon/banner)、footer(微信码/国旗)、 404、index、article 缩略图、widgets 头像、page-toolbar、theme-core 赞赏码。 - 国旗与 favicon 的渲染抽成 yang_flag_block() / yang_favicon_tag(), 空值时不输出空 src / 空 href。 - 后台 9 处 std 改为 yang_options_default_img(),与前台默认图同源; 该包装函数自带 function_exists 防护,单独加载 theme-options.php 不会 Fatal。 新增图片(本地生成,合计 291KB):default-404 / default-share / default-empty / default-avatar / default-banner / default-flag / favicon.ico。 favicon 为 WordPress 风格自绘(品牌蓝圆底 + 白色 W),非站长个人专用那张。 验证:run_tests 146 条(新增第 4 组图片默认值 22+ 条);falsify 35 条注入 全部能被抓住(新增 10 条);verify_all.sh 14 组全绿。
60 lines
2.0 KiB
PHP
60 lines
2.0 KiB
PHP
<?php
|
||
/**
|
||
* 模板函数
|
||
* @author Yongquan Yang <yangyq.net>
|
||
* @license MIT License
|
||
* @version 2020.03.17
|
||
*/
|
||
|
||
define('THEME_VERSION', wp_get_theme()->get('Version'));
|
||
|
||
// 主题配置
|
||
require get_template_directory() . '/inc/options-framework/autoload.php';
|
||
|
||
// 自定义代码(CSS / JS,存选项表而非主题目录)
|
||
require get_template_directory() . '/inc/theme-custom-code.php';
|
||
|
||
// 更新配置
|
||
require get_template_directory() . '/inc/update-checker/autoload.php';
|
||
|
||
// 核心配置
|
||
require get_template_directory() . '/inc/theme-core.php';
|
||
|
||
// 图片类选项的默认值(Logo/favicon/404/分享图… 空值时落到包内默认图)。
|
||
// 必须排在 theme-core.php 之后:它要用 ASSET_PATH 与 kratos_option。
|
||
require get_template_directory() . '/inc/theme-option-defaults.php';
|
||
|
||
// 站点配置
|
||
require get_template_directory() . '/inc/theme-setting.php';
|
||
|
||
// 纪念日自动哀悼(按日期判断,需在 theme-setting 之后,
|
||
// 因为它用到 kratos_option)
|
||
require get_template_directory() . '/inc/theme-mourning.php';
|
||
|
||
// 哀悼说明页(固定路径 /memory,由主题判定路由,不写数据库)
|
||
require get_template_directory() . '/inc/theme-mourning-page.php';
|
||
|
||
// 文章配置
|
||
require get_template_directory() . '/inc/theme-article.php';
|
||
|
||
// 小工具配置
|
||
require get_template_directory() . '/inc/theme-widgets.php';
|
||
|
||
// 文章增强
|
||
require get_template_directory() . '/inc/theme-shortcode.php';
|
||
|
||
// 添加导航目录
|
||
require get_template_directory() . '/inc/theme-navwalker.php';
|
||
|
||
// 对象存储配置
|
||
require get_template_directory() . '/inc/theme-dogecloud.php';
|
||
|
||
// 邮件模板:必须先于 theme-mail.php 加载,
|
||
// 因为后者在发信时会调用 yang_mail_render()
|
||
require get_template_directory() . '/inc/theme-mail-template.php';
|
||
|
||
// 邮件治理:统一接管发信通道、去重、关掉重复通知
|
||
require get_template_directory() . '/inc/theme-mail.php';
|
||
|
||
// SMTP 配置(连通性相关,实际接管在 theme-mail.php)
|
||
require get_template_directory() . '/inc/theme-smtp.php'; |