联系表格 7 - wpcf7_before_send_mail 和 wpcf7_submit 的问题

Contact Form 7 - Issues with wpcf7_before_send_mail and wpcf7_submit

我目前在一个网站上工作,该网站有用户通过使用 Contact Form 7 创建的表单提交。我正在尝试将其扩展为记录 activity(date/time,已登录用户,从填写的字段中获取信息),我已经尝试了很多次并尝试了使用钩子 wpcf7_before_send_mail 和 wpcf7_submit 的方法,但似乎都没有用。表单提交了,但是下面的代码没有提交运行。我什至尝试手动输入信息(table 名称、用户 ID、客户等)以查看它是否会提交,但仍然没有。

下面是我用来将一些信息保存到数据库的当前代码,我希望 activity 存储在:

add_action('wpcf7_before_send_mail', 'save_in_database');

function save_in_database($data) {
    global $wpdb;
    $account_number = get_account_number();
    $department = get_user_role();

    if ($data->title == 'Social_Media_Tool_Form'){
        $submission = WPCF7_Submission::get_instance();
        if ( $submission ) {
            $cf7_data = $submission->get_posted_data();
            $name = $cf7_data['customer-name'];
        }
    }


    $activity_table_name = $wpdb->prefix .'_'. $account_number . '_activity_log';

    //Creates activity log
    $wpdb->insert($activity_table_name, array(
        'date'              =>  current_time('Y-m-d H:i:s'),
        'user_id'           =>  get_current_user_id(),
        'customer_name'     =>  $name,
        'activity_type'     =>  'social',
        'department'        =>  $department
    ));
}

我以前用过同样的代码来记录其他活动,所以理论上,它应该在这里工作。

我目前使用的是 Wordpress 5.1 并使用 Contact Form 7 5.1.1

我想通了这个问题。在表单上,​​您必须将 "subscribers_only: true" 添加到其他设置中。因为没有设置,所以不允许我从当前用户那里提取信息,这就是它没有提交到数据库的原因。