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

Wordpress - Find the form-handler file with the route action

我的一个文件中有这样的表格

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

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

阅读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。请确定,您使用新语法来更新您的表单对象。

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

避免投票