将自定义字段添加到Contact Form 7标签

Fra*_*sco 0 wordpress wordpress-plugin contact-form-7

我想将自定义字段添加到cf7标签。(见图)我可以使用任何add_filter钩子吗?请帮我。

谢谢 范例图片

Obm*_*nen 5

好吧,我可能误会了你想要的东西,但是:

CF7就是这样注册文本字段shorttag的:

add_action( 'wpcf7_init', 'wpcf7_add_shortcode_text' );

function wpcf7_add_shortcode_text() {
    wpcf7_add_shortcode(
        array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
        'wpcf7_text_shortcode_handler', true );
}
Run Code Online (Sandbox Code Playgroud)

请注意,如果我们创建自己的示例,则该钩子wpcf7_init用于函数wpcf7_add_shortcode()so:

add_action( 'wpcf7_init', 'custom_add_shortcode_hello' );



function custom_add_shortcode_hello() {
    wpcf7_add_shortcode( 'helloworld', 'custom_hello_shortcode_handler' ); // "helloworld" is the type of the form-tag
}
Run Code Online (Sandbox Code Playgroud)

然后是回调处理程序

function custom_hello_shortcode_handler( $tag ) {
    return 'hello world ! ';
}
Run Code Online (Sandbox Code Playgroud)

现在,如果您将其添加到表单中

CF7 say : [helloworld]
Run Code Online (Sandbox Code Playgroud)

你应该看到

CF7 say : hello world ! 
Run Code Online (Sandbox Code Playgroud)

如果要使用普通表单标签,请注意可用的默认类型为:

text, text*, email, email*, tel, tel*, url, url*, textarea ,textarea* , number, number*, range and range* , date , date*,checkbox, checkbox*, radio, select and select* , file , file*, captchac ,captchar, quiz , acceptance, submit;
Run Code Online (Sandbox Code Playgroud)

现在,我写下了所有这些内容,因为据我所知(可能是错误的),对于在函数wpcf7_tg_pane_text_and_relatives()中定义的已经存在的标记,HTML表单没有过滤器 。modules/text.php

,但是您可以做的是通过使用删除默认标签(例如text)wpcf7_remove_shortcode( $tag );,然后通过创建新的标签(例如text)来添加自己的上述示例以适应您的需要

话虽这么说,但我还不确定您想要什么以及为什么要这么做(您确实没有解释目标,只是这样),因为恕我直言,在我编写了许多CF7自定义插件之后,我真的不明白为什么不仅仅是创建一个新标签,它更容易构造。

但是话又说回来,我可能是错的。