快捷码在html输入中不起作用

时间:2015-07-27 作者:paimoe

I\'m using Wordpress 4.2.3

The shortcode is added with the following:

function upsellxid_shortcode() {
    return \'9eaa86d1a36a126313aa752c2ff8e16c\';
}

function upsellxid_shortcode_2() {
    return \'4849f6a5e3b188fa4b3b4c1f37975706\';
}

function upsellxid_shortcode_rsa() {
    return \'7a9bc3b332605817594dbac27847dff0\';
}

function infusionsoftEmail_shortcode() {
    // Code
    $in = $_REQUEST;
    if (isset($_REQUEST[\'q\'])) {
        $parse = parse_url($_REQUEST[\'q\']);
        parse_str($parse[\'query\'], $get);
        $in = $get;
    }

    $email = false;
    if (isset($in[\'inf_field_Email\']) == true &&  empty($in[\'inf_field_Email\']) == false) {
        $email = $in[\'inf_field_Email\'];
    } else if(isset($in[\'Contact0Email\']) == true &&  empty($in[\'Contact0Email\']) == false) {
        $email = $in[\'Contact0Email\'];
    }
    return $email;
}
add_shortcode(\'upsellxid\', \'upsellxid_shortcode\');
add_shortcode(\'xid_RSAMonthly\', \'upsellxid_shortcode_2\');
add_shortcode(\'rsa30daytrial\', \'upsellxid_shortcode_rsa\');
add_shortcode(\'infusionsoftEmail\', \'infusionsoftEmail_shortcode\');

Using it in a post seems fine (just [rsa30daytrial] will output the correct code). But using it inside an html input returns the raw text:

[rsa30daytrial]
[rsa30daytrial]
<input type="text" value="[rsa30daytrial]" />

results in (page source):

<p>7a9bc3b332605817594dbac27847dff0
7a9bc3b332605817594dbac27847dff0
<input type="text" value="[rsa30daytrial]" /></p>
1 个回复
最合适的回答,由SO网友:paimoe 整理而成

如上所述,https://wordpress.stackexchange.com/a/195673/22728 解决了它:

add_filter( \'wp_kses_allowed_html\', function ( $allowedposttags, $context ) {
    if ( $context == \'post\' ) {
        $allowedposttags[\'input\'][\'value\'] = 1;
    }
    return $allowedposttags;
}, 10, 2 );

结束

相关推荐

Apply_Filters(‘the_content’,$Content)与DO_ShortCode($Content)

假设我有一个主题选项或自定义的postmeta文本区域。现在我想执行多个短代码、一般文本、图像等。最佳实践是什么?为什么?选项1:$content = //my text area data; echo apply_filters(\'the_content\', $content); 选项2:$content = //my text area data; echo do_shortcode($content); 请告诉我哪一个是最佳实践,以及为什么。EDIT让我详细描