Wordpress - 使用路由操作查找表单处理程序文件

时间:2016-04-02 09:35:20

标签: php wordpress contact-form-7

我的一个档案中有这样的表格

<form action="/uploads/#wpcf7-f233-p2-o1" method="post" class="wpcf7-form" novalidate="novalidate">

我不知道这个表单处理程序在哪里。在Symfony中有一个路由文件,您可以在其中找到每个路由,Controller和Action,因此很容易找到它。

1 个答案:

答案 0 :(得分:1)

wp-content/plugins/wpcf7/中阅读WPCF7的代码。 Grep for do_action并识别钩子。

然后编写自定义函数并在主题或自己的插件中注册。

下面是before_send_mail挂钩的示例。

function wpcf7_ba_before_send_mail($cf7) {
    global $wpdb;
    $cfid = $cf7->id();
    error_log("Hit wpcf7_ba_before_send_mail with id: ".$cfid);


    /* This is the ID of your form  */
    if ($cfid==1850) {

        /* Get the form object */
        $submission = WPCF7_Submission::get_instance(); 

        /* Get posted data */
        $posted_data = $submission->get_posted_data();

        /* change receiver */
        $recs = explode(',', $posted_data['mailto']);
        $mails = Array();
        foreach ( $recs as $r ) {
            $m = $wpdb->get_results("SELECT mail,name FROM webservice_cache WHERE id='$r'");
            $t = $m[0]->mail ? $m[0]->mail : '';
            array_push($mails,$t);
        }
        $mail = $cf7->prop('mail');
        $bccs = join(',', $mails);
        error_log('Would mail to: '.$bccs);
        $mail['additional_headers'] =  Bcc:foo@example.com,bar@example.com\r\nReply-To:foobar@example.com\r\n";
        /* persist changes in form object */
        $cf7->set_properties( array( 'mail' => $mail ) );
    }

    return $cf7;
}

/* register your custom function to be called on 
 * do_action before_send_mail.
 */
add_action("wpcf7_before_send_mail", "wpcf7_ba_before_send_mail", 10, 1);  

代码基于this resource。只需使用shure,就可以使用新语法来更新表单对象。

P.S。通过注册wordpress.sackexchange.com

来避免downvotes