WordPress PHP/React插件短码formType属性值异常求助
WordPress PHP/React插件formType属性跨页面缓存问题
问题描述
- 该插件基于WordPress开发,采用PHP+React技术栈,通过短码接收
lang和formType两个属性,站点多页面均部署有插件实例 - 先加载页面1(短码参数
lang=lang1、formType=type1),再加载页面2(lang=lang2、formType=type2):lang能正确识别为lang2,但formType仍沿用type1,此问题已在PHP注入的React HTML元素中验证 - 即使站点使用Autoptimize和Breeze缓存,清除缓存后问题依旧;若先加载页面2,页面1的
formType会变为type2 - 测试
plugin_name_dev短码(仅加载不同JS/CSS资源):页面3(lang1、type1)加载正常,页面4(lang2、type2)加载时formType仍为type1
核心代码
短码定义
add_shortcode('plugin_name', function ($atts) { $args = shortcode_atts([ 'lang' => 'lang1', 'formType' => 'type2' ], $atts); return plugin_name_shortcode($args['lang'], $args['formType']); });
plugin_name_shortcode函数
function plugin_name_shortcode($lang = 'lang1', $formType = 'type2') { $config = load_config(); $country = detect_country(); $config['country'] = $country; wp_enqueue_style('plugin-name-style'); wp_enqueue_script('plugin-name-script'); wp_localize_script( 'plugin-name-script', 'businessConfig', $config ); return make_plugin_html($lang, $formType); }
已尝试方案
- 修改Apache的
.htaccess文件禁止JS缓存 - 重命名
formType属性
以上方案均未解决问题,寻求技术支持。
内容的提问来源于stack exchange,提问作者ZacheryMarcum
相关产品推荐
相关产品推荐

