douren2831 2014-05-29 15:24
浏览 50
已采纳

WP短代码将变量传递给函数

I'm trying to pass or store a file path string which the CMS user provides in the shortcode, and use this in a function which is then executed when the short code has rendered.

Here are the details:

function wpsdc( $atts ) {
extract( shortcode_atts( array(
    'file_path' => '', 
    'text' => ''
    ), $atts ) );

$wpsdc_output = wpsdc_short_code($text);

return $wpsdc_output;
}
add_shortcode('wpsdc','wpsdc');

My wpsdc_short_code function returns some basic form html:

<form action='wpsdc-validate-email.php' method='post' id='download_content'>
   <input id='emailtext' name='email' type='text'>
   <button id='submit-email' type='submit'>Click</button>
</form>

What I am aiming to do is return a string (which I render as an anchor text link) to the file path defined in the initial short code.

[wpsdc file_path='/downloads/some_pdf_file.pdf' text='Click']

How therefore do I get the $file_path variable to my 'wpsdc-validate-email.php' file WITHOUT having the file string visible in the html form mark-up?

Thank you very much in advance.

  • 写回答

1条回答 默认 最新

  • dongzanghui4624 2014-05-29 17:30
    关注

    I can see a few approaches to this:

    1. Use php's mcrypt functions to encrypt your file_path and store it in a hidden field on the form, then use mcrypt_decrypt to decode it in your form action script. Documentation here: http://www.php.net/manual/en/book.mcrypt.php

    2. Store the file_path in a php $_SESSION and use this. See this Wordpress support thread for the basics: http://wordpress.org/support/topic/using-session-in-wordpress

    3. You could also use a plugin like WP Session Manager in the event that your PHP server is locked down.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式