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.

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

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据