所以我启用了用户注册重力表单附加组件,我希望在用户注册/提交表单时将特定部分添加到转发器字段。
在我的 functions.php 中,我创建了这些:
add_action( 'gform_after_submission_6', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
//getting post
$post = get_post( $entry['post_id'] );
//change the 4 to your gravity form field number
$caryear = rgar( $entry, '21' );
#add the row to the repeater
$row = array(
'field_5aff6ca2a2def' => $caryear #this is your repeater subfield key
);
$i = add_row('field_5ac6602d483d7', $row, $post_id->ID); #this is the main repeater key
}
我也试过这个,但我不知道我到底在做什么
add_action( 'gform_user_registered_6', 'car_regs', 10, 3 );
function car_reg( $user_id, $feed, $entry ) {
$user = new WP_User( $user_id );
$userid = 'user_'.$user;
$caryear = rgar( $entry, '21' );
$post = get_post( $entry['post_id'] );
#add the row to the repeater
$row = array(
'field_5aff6ca2a2def' => $caryear #this is your repeater subfield key
);
$i = add_row('field_5ac6602d483d7', $row, $userid); #this is the main repeater key
}
add_action( 'gform_after_submission_6', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {
//getting post
$post = get_post( $entry['post_id'] );
$emailaddress = rgar( $entry, '3' );
$user = get_user_by( 'email', $emailaddress );
$userId = $user->ID;
$userACF = 'user_'.$userId;
//change the 4 to your gravity form field number
$caryear = rgar( $entry, '21' );
#add the row to the repeater
$row = array(
'field_5aff6ca2a2def' => $caryear #this is your repeater subfield key
);
add_row('field_5ac6602d483d7', $row, $userACF); #this is the main repeater key
}
有关更多上下文,我想做的是在用户注册(表单提交)时,它会在附加到他们的个人资料的转发器表单中添加一个条目。
我试过很多次了,但是根本不管用。我非常困惑,不知道我是否错过了什么。任何帮助都会很棒!
我能够找出解决方案。结果我需要将它挂接到重力表单注册挂钩,通过用户电子邮件查找用户,然后以这种方式获取用户 ID,因为在不引用要查找的内容的情况下获取用户 ID 将返回空值。
这是我为所有关心的人更新的功能。
add_action( 'gform_user_registered', 'add_custom_user_meta', 10, 4 );
function add_custom_user_meta( $user_id, $feed, $entry, $user_pass ) {
$email = rgar( $entry, '3' );
$user = get_user_by( 'email', $email );
$userID = $user->ID;
$userACF = 'user_'.$userID;
$post = get_post( $entry['post_id'] );
$caryear = rgar( $entry, '7' );
$row = array(
'field_5aff6ca2a2def' => $caryear #this is your repeater subfield key
);
add_row('field_5ac6602d483d7', $row, $userACF); #this is the main repeater key
}