You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 14:07:19