我试图增加wp_user_meta
表,利用重力形式。我一点运气都没有。我正在研究这个版本gform_pre_submission
(虽然没有类嗅探),但我想在提交后这样做,因为会涉及贝宝,在付款验证之前不想发布。
我试图使用cssClass作为过滤器,以便其他开发人员可以自由创建任意多个gravity表单,只要他们使用这些类product_name
和product_price
不幸的是,我的数据库现在刚刚充满了故障。
// hook onto gravity forms and update payment history field
add_action(\'gform_after_submission\', \'payment_history_handler\', 10, 2);
function payment_history_handler($entry, $form){
$current_user = wp_get_current_user();
$payment_history = get_user_meta($current_user->ID, \'payment_history\', true);
foreach($form[\'fields\'] as &$field){
if(strpos($field[\'cssClass\'], \'payment_name\') === true){
$payment_name = $entry[$field[\'id\']];;
} else {
$payment_name = \'fail\';
}
if(strpos($field[\'cssClass\'], \'payment_price\') === true){
$payment_price = $entry[$field[\'id\']];
} else {
$payment_price = 1;
}
}
if(!empty($payment_name) && !empty($payment_price)){
$payment_history[] = array(\'date\' => date(\'U\'), \'name\' => $payment_name, \'price\' => $payment_price);
update_user_meta($current_user->ID, \'payment_history\', $payment_history);
}
}
这些类已就位,如我的输出示例所示:
<div class=\'gform_body\'>
<ul id=\'gform_fields_4\' class=\'gform_fields top_label description_below\'>
<li id=\'field_4_1\' class=\'gfield payment_name gfield_contains_required\' >
<label class=\'gfield_label\' for=\'input_4_1\'>What Thing are you choosing?<span class=\'gfield_required\'>*</span></label>
<div class=\'ginput_container\'>
<select name=\'input_1\' id=\'input_4_1\' class=\'medium gfield_select\' tabindex=\'1\' >
<option value=\'The first one\' >The first one</option>
<option value=\'The second one\' >The second one</option>
<option value=\'The third one\' >The third one</option>
</select>
</div>
</li>
<li id=\'field_4_2\' class=\'gfield payment_price gfield_contains_required\' >
<label class=\'gfield_label\' for=\'input_4_2\'>Price<span class=\'gfield_required\'>*</span></label>
<div class=\'ginput_container\'>
<input name=\'input_2\' id=\'input_4_2\' type=\'text\' value=\'\' class=\'medium\' tabindex=\'2\' />
</div>
</li>
</ul>
</div>
非常感谢您的帮助。