Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get IP address that can pass current $user_ID?

  • Hello. I am trying to put the user’s IP address in the group/members.php, or the group’s directory. I want the user listed’s IP address to show only if the user is the group admin or mod. But now what I am having trouble on, is that the IP address is the same for all users, (my IP), but I want it to be the user listed’s IP, not mine. Here is what I tried, but it’s not working.

    in my bp-cutsom.php I put:

    `function my_member_list_id() {
    global $members_template;
    return $members_template->member->user_id;
    }`

    and then in the file I put:

    ``

    I thought that would work, but it’s still the same. Any ideas?

Viewing 25 replies - 1 through 25 (of 46 total)
  • anyone?

    Uhh i m so frustrated I tried

    `function bp_group_member_list_ip() {
    global $bp;

    echo get_IP( ‘$bp->displayed_user->id’ );

    }`

    i also tried `member->user_id ) ; ?>`


    Brandon Allen
    Participant

    @cnorris23

    @VegasParty607 First, there is no one dedicated to answering questions on the forum. It’s all volunteer. Sorry no one has replied, but repeatedly posting isn’t going to make anyone want to help you.

    Sencond, your code for displaying the IP address looks correct, so the problem is likely within the get_IP function. Without seeing the function it’s hard to tell.


    Brandon Allen
    Participant

    @cnorris23

    After a second look you should be using `$members_template->member->id` or `get_IP( $bp->displayed_user->id );`. If either of those don’t fix it, then it’s the get_IP function.

    Where are all the functions located in wordpress???

    If I could find where they created “ I would be good


    Brandon Allen
    Participant

    @cnorris23

    The functions are located within the WP code, but there is no get_IP function.

    is there another function that can fetch the IP address??

    Well than why does get_ip fetch the ip address?


    Brandon Allen
    Participant

    @cnorris23

    My guess, you’re using the WP-Ban plugin. You would have to write your own function to get the IP address, and the store it somewhere, most likely in the usermeta table.

    ok, now in this code:

    `function get_IP() {
    if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else {
    $ip_address = ”;
    }
    if(strpos($ip_address, ‘,’) !== false) {
    $ip_address = explode(‘,’, $ip_address);
    $ip_address = $ip_address[0];
    }
    return esc_attr($ip_address);`

    how do i edit it with:

    `function my_member_list_id() {
    global $members_template;
    return $members_template->member->user_id;` so it will work like i want?


    Brandon Allen
    Participant

    @cnorris23

    You’re getting closer. I would change the get_IP() function to something like this:

    `function my_update_user_IP() {
    $user_id = (int) get_current_user_id();

    if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else {
    $ip_address = ”;
    }
    if(strpos($ip_address, ‘,’) !== false) {
    $ip_address = explode(‘,’, $ip_address);
    $ip_address = $ip_address[0];
    }

    if ( $updated = update_user_meta( $user_id, ‘ip_address’ $ip_address ) )
    return $ip_address;
    else
    return false;
    }
    add_action( ‘wp_login’, ‘my_update_user_IP’ );`

    You’ll need to change get_IP to something like my_get_IP() since get_IP already exists in your setup. Do something like this:

    `function my_get_IP( $user_id = false ) {
    if ( empty( $user_id )
    return false;

    $ip_address = esc_attr( trim( get_user_meta( $user_id, ‘ip_address’, true ) ) );

    return $ip_address;
    }`

    You’ll also want to change

    `return $members_template->member->user_id;`

    to

    `return $members_template->member->id;`

    since $members_template->member->user_id doesn’t exist.

    im so lost… which code is the one i want to use!?

    The first code I get: `Parse error: syntax error, unexpected T_VARIABLE`


    Brandon Allen
    Participant

    @cnorris23

    You use the two functions I listed, my_update_user_IP and my_get_IP, and then you’ll add

    ``

    to your template where you want the IP address displayed. You don’t need the my_member_list_id() function.


    Brandon Allen
    Participant

    @cnorris23

    I don’t know what you mean by “first code”


    Brandon Allen
    Participant

    @cnorris23

    There was an error in the code I gave you. Try this instead:

    `function my_update_user_IP() {
    $user_id = (int) get_current_user_id();

    if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else {
    $ip_address = ”;
    }
    if(strpos($ip_address, ‘,’) !== false) {
    $ip_address = explode(‘,’, $ip_address);
    $ip_address = $ip_address[0];
    }

    if ( update_user_meta( $user_id, ‘ip_address’, $ip_address ) )
    return $ip_address;
    else
    return false;
    }
    add_action( ‘wp_login’, ‘my_update_user_IP’ );`

    I still got the Error with the updated code


    Brandon Allen
    Participant

    @cnorris23

    Found another error. Try this:

    `function my_get_IP( $user_id = false ) {
    if ( empty( $user_id ) )
    return false;

    $ip_address = esc_attr( trim( get_user_meta( $user_id, ‘ip_address’, true ) ) );

    if ( $ip_address = esc_attr( trim( get_user_meta( $user_id, ‘ip_address’, true ) ) ) )
    return $ip_address;
    else
    return false;
    }`

    thats the entire thing? or is it

    `function my_get_IP( $user_id = false ) {
    if ( empty( $user_id ) )
    return false;

    $ip_address = esc_attr( trim( get_user_meta( $user_id, ‘ip_address’, true ) ) );

    return $ip_address;

    if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else if(!empty($_SERVER)) {
    $ip_address = $_SERVER;
    } else {
    $ip_address = ”;
    }
    if(strpos($ip_address, ‘,’) !== false) {
    $ip_address = explode(‘,’, $ip_address);
    $ip_address = $ip_address[0];
    }

    if ( update_user_meta( $user_id, ‘ip_address’, $ip_address ) )
    return $ip_address;
    else
    return false;
    }
    add_action( ‘wp_login’, ‘my_update_user_IP’ );`


    Brandon Allen
    Participant

    @cnorris23

    No. They are two separate functions with two different names. There were syntax errors in both fuctions. I fixed one a few hours ago, and the other I just fixed. Make sure you copy and paste each exactly as I have them.

    Thanks…. but to no avail… still. I’m so bummed i could cry.

    Nothing appears where i put the function… uhh. ;( :(


    Brandon Allen
    Participant

    @cnorris23

    Did you put both functions in your bp-custom.php file? Then did you put the html in the theme file where you’d like it to appear?

    yeah, i even tried changing it in the plugin file, and nothing changed then either

    trial and error now…

    where is the $members_template->member->user_id; supposed to be?


    Brandon Allen
    Participant

    @cnorris23

    Nowhere. If you’re placing the html I posted within the bp_has_members() loop, you don’t need `$members_template->member->user_id;`. The code I gave you handles it. Besides, as I’ve stated before `$members_template->member->user_id;` isn’t valid.

Viewing 25 replies - 1 through 25 (of 46 total)
  • The topic ‘Get IP address that can pass current $user_ID?’ is closed to new replies.
Skip to toolbar