admin管理员组文章数量:1333673
I am integrating Gravity Forms, Gravity Forms User Registration Add On and Groups by ithinx.
I have written the following function:
add_action( 'edit_user_created_user', 'hl_add_group', 10, 1 );
function hl_add_group($user_id,$notify) {
$group = get_user_meta($user_id,'hl_user_group');
global $wpdb;
// add form data to custom database table
$wpdb->insert(
'wp_groups_user_group',
array(
'user_id' => $user_id,
'group_id' => $group,
),
array(
'%d',
'%d'
)
);
}
The custom meta field h1_user_group
is created based on a Gravity Forms field. The value stored corresponds to a Group ID. I have tired hooking user_registration
and edit_user_created_user
. When using user_registration
, it successfully creates the new table row, but get_user_meta
returns 0 because the meta hasn't been added yet. When using the version above, nothing is added at all — and I am not sure why.
I appreciate your help very much!
I am integrating Gravity Forms, Gravity Forms User Registration Add On and Groups by ithinx.
I have written the following function:
add_action( 'edit_user_created_user', 'hl_add_group', 10, 1 );
function hl_add_group($user_id,$notify) {
$group = get_user_meta($user_id,'hl_user_group');
global $wpdb;
// add form data to custom database table
$wpdb->insert(
'wp_groups_user_group',
array(
'user_id' => $user_id,
'group_id' => $group,
),
array(
'%d',
'%d'
)
);
}
The custom meta field h1_user_group
is created based on a Gravity Forms field. The value stored corresponds to a Group ID. I have tired hooking user_registration
and edit_user_created_user
. When using user_registration
, it successfully creates the new table row, but get_user_meta
returns 0 because the meta hasn't been added yet. When using the version above, nothing is added at all — and I am not sure why.
I appreciate your help very much!
Share Improve this question asked Jun 15, 2020 at 21:22 NYCjbdNYCjbd 131 silver badge4 bronze badges 2- Might be helpful to start the question with what you're trying to do as it's not very clear – mozboz Commented Jun 15, 2020 at 22:37
- Sorry. Seemed clear to me. It was answered on another forum, though. Appreciate your inquiry. – NYCjbd Commented Jun 16, 2020 at 13:56
1 Answer
Reset to default 0The GravityForms folks chimed in. To clarify, I wanted to add a row to a database table on user activation (not on form submit), and I had not found that hook. Here is the completed code…
add_action( 'gform_user_registered', 'hl_add_group', 10, 4 );
function hl_add_group($user_id, $feed, $entry) {
$group = $entry[8];
global $wpdb;
// add form data to custom database table
$wpdb->insert(
'wp_groups_user_group',
array(
'user_id' => $user_id,
'group_id' => $group,
),
array(
'%d',
'%d'
)
);
}
本文标签: mysqleditusercreateduser hookusing to update Groups
版权声明:本文标题:mysql - edit_user_created_user hook - using to update Groups 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742344396a2457232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论