Web Analytics Made Easy -
StatCounter How to get wordpress userID on registration and add it into a table? - CodingForum

Announcement

Collapse
No announcement yet.

How to get wordpress userID on registration and add it into a table?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get wordpress userID on registration and add it into a table?

    Hi

    I want to get the userID upon new user registration and add the userID to a column wp_prli_links.user_id of an already existing table wp_prli_links

    I have added the column to the table using ALTER TABLE.

    Code:
    ALTER TABLE wp_prli_links ADD wp_prli_links.user_id INT NOT NULL;
    The Table is as follows:

    Code:
    +----+---------------------+------+---------------+----------+---------+
    | id | url                 | slug | redirect_type | group_id | user_id |
    +----+---------------------+------+---------------+----------+---------+
    |  1 | http://example.com/ | 3qqd |           301 |        0 |       0 |
    |  2 | http://example.com/ | t8af |           301 |        0 |       0 |
    |  3 | http://example.com/ | sjim |           301 |        0 |       0 |
    |  4 | http://example.com/ | awfo |           301 |        0 |       0 |
    |  5 | http://example.com/ | 6myy |           301 |        0 |       0 |
    +----+---------------------+------+---------------+----------+---------+

    What I am trying tachieve is to capture userID upon new user registration and add it to wp_prli_links.user_id column, so that each row under the colum has a different and distinct userID.

    I tried with several variations but neither worked UserID did not showup in the table.

    Variation 1

    PHP Code:
    function add_to_aff($user_id) {

    global 
    $wpdb;
    $wpdb->insert'wp_prli_links', array('wp_prli_links.user_id' => $user_id ), array('%d') ); 
    }
    add_action'user_register''add_to_aff'); 
    Variation 2

    PHP Code:
    function add_to_aff($user_id) {

    $user_info get_userdata$user_id );

    global 
    $wpdb;
    $wpdb->insert'wp_prli_links', array('wp_prli_links.user_id' => $user_info->ID ), array('%d') ); 
    }
    add_action'user_register''add_to_aff'); 
    I am adding them to my-theme/functions.php

    I think, what I am trying to achieve will be best served by UPDATE instead of INSERT. I have to update the wp_prli_links.user_id column with user_id (from registration). So that, each row under the wp_prli_links.user_id column will have a different and unique user_id.

    I just can't figure out how to perform the UPDATE. Any help is appreciated!
Working...
X