您需要将表单的结果发送到插件进行处理。
到目前为止,我只看到带有简码的选项。
例如,我在所需页面上连接一个简码,并将一个表单字段数组及其值传递给它:
$array = [
"title" => "title",
"description" => "description"
];
$json = json_encode($array);
do_shortcode( sprintf( '[test_shortcode ids="%s"]', $json ) );
在插件中我得到它是这样的:
add_shortcode('test_shortcode','my_shortcode_output');
function my_shortcode_output($atts, $content = '', $tag){
echo $atts[0];
}
结果:
ids="{"title":"title","description":"description"}"
接下来,您需要解析。不知怎的,它看起来不是很好。WordPress中是否有更优雅的方式来做这种事情?
对于您需要的功能,WordPress 有一个很棒的概念,叫做hooks。您的代码示例如下所示。
在插件中,在需要从主题调用(输出)函数的地方,我们初始化钩子:
在主题文件中