最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mysql - edit_user_created_user hook - using to update Groups

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

The 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'
        )
    );
}
发布评论

评论列表(0)

  1. 暂无评论