Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 25 replies - 76 through 100 (of 162 total)
  • @cnorris23

    Participant

    Are you sure the globals are correct within `bp_core_get_username`? I’m going under the assumption that you did your homework and found the right globals. The code inside bp_core_get_username() is the only place things could go wrong.

    @cnorris23

    Participant

    Yes, but you changed more than that. You changed the code in bp_core_get_username() from:

    `bp_core_get_username( $topic_template->post->poster_id, $topic_template->displayed_user->userdata->user_nicename, $topic_template->displayed_user->userdata->user_login )`

    ,which was correct, to:

    `bp_core_get_username( $bp->topic_template->post->poster_id, $bp->topic_template->displayed_user->userdata->user_nicename, $bp->topic_template->displayed_user->userdata->user_login )`

    which is incorrect.

    @cnorris23

    Participant

    That’s be cause you changed too much. You only need to change the line I told you to change. Which was:

    `global $topic_template;`

    to

    `global $bp, $topic_template;`

    Nothing else should change.

    @cnorris23

    Participant

    In your theme’s activity/entry.php file change:

    `
    <a href="” class=”acomment-reply” id=”acomment-comment-“> ()
    `

    to:

    `
    if ( my_bp_activity_type_is_new_forum_post() ) {
    <a href="” class=”acomment-reply” id=”acomment-comment-“>
    } else {
    <a href="” class=”acomment-reply” id=”acomment-comment-“> ()
    }
    `

    and add the following to your theme’s functions.php file:

    `function my_bp_activity_type_is_new_forum_post() {
    ( ‘new_forum_post’ == bp_get_activity_type() ) ? return true : return false;
    }`

    @cnorris23

    Participant

    I would start with adding $bp to your global statement.

    `global $bp, $topic_template;`

    @cnorris23

    Participant

    I have not tested it. I have no way of testing it on your site. That’s why I gave the code to you, so that you could test it. It’s there forever. It will be updated each time the user logs in, so if their IP address changes, which most will, the old IP will be replace with the new IP.

    @cnorris23

    Participant

    Should be the same code as you use within the group members loop, just use `bp_get_the_topic_poster_id()` instead of `bp_get_group_member_id()`.

    ``

    @cnorris23

    Participant

    One option is to do as @embergermedia stated. To catch everyone, you could hook in a profile edit action and check to see if all the fields you require have been completed. If they have, then you could add something in their usermeta saying they’ve completed everything. Then you could hook into bp_init, check that usermeta field, and if you don’t get the correct response, then you can redirect them to their profile, or display an error telling them they need to complete their profile. However, as both @embergermedia and @brooker said, it wouldn’t be the most user friendly way to go.

    @cnorris23

    Participant

    It will likely take a while before everyone has logged in and had their IP’s updated. With cookies and general delay between an individual user’s login, not everyone will end up logging in every day, or especially multiple times a day. With the current code, the user has to log in before their IP address is saved.

    @cnorris23

    Participant

    Are you using the code exactly as I’ve placed it? Are you putting the html below
    “

    but before

    “

    ?

    @cnorris23

    Participant

    Looks okay. I would change:

    `foreach ($postcat as $value)`
    to
    `foreach ((array)$postcat as $value)`
    just in case something happens and $postcat isn’t an array.

    Have you tried r-a-y’s suggestion for using the `bb_get_postmeta()` and `bb_update_postmeta()` functions rather than a direct query?

    @cnorris23

    Participant

    Yes I have tested it, which means it works on my site. It saves and outputs the IP address. It’s a local installation, so as I said above, I can’t speak to the validity of the IP address. I haven’t tested that portion, as I have no easy way to test.

    Where are you placing the code?

    @cnorris23

    Participant

    Okay. I’ve finally been able to test the code I gave you. There was an issue with the retrieval of the $user_id during log in, so nothing was being saved. I’ll post below with the updated code. The code works as far as saving/retrieving/displaying the IP address. If the IP address continues to be your address, and you are using the code I give you below, then the problem is with the part of the function that determines the IP address. I have not tested whether that works. I’m trusting that you’ve done your homework and found the right one.

    These first two functions will go in your bp-custom.php file or in your themes functions.php file:

    `function my_update_user_IP( $user_login = ” ) {
    $user = get_user_by( ‘login’, $user_login );
    $user_id = (int) $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’ );

    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;
    }`

    The next bit of code will go within the members loop of your themes groups/members.php file:

    ``

    @cnorris23

    Participant

    After seeing more of what you’re trying to do here (https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/how-to-display-the-user-post-count-in-topic-php/#post-96750) I should also point out, that this will only work if the person has logged in since you started using the code. What the code I gave does is to retrieve and save the user’s IP address each time they log in. If you can get in touch with someone who has an account with a different IP address than yourself, you can have them log out, the log in, and you should then see their IP address. To recap, here is the code you need in your bp-custom.php:

    `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;
    }`

    `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’ );`

    then add the following to your group/members.php template:

    ``

    @cnorris23

    Participant

    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.

    @cnorris23

    Participant

    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?

    @cnorris23

    Participant

    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.

    @cnorris23

    Participant

    @cnorris23

    Participant

    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;
    }`

    @cnorris23

    Participant

    @cnorris23

    Participant

    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’ );`

    @cnorris23

    Participant

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

    @cnorris23

    Participant

    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.

    @cnorris23

    Participant

    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.

    @cnorris23

    Participant

    Haha! No worries. Post back if you get stuck.

Viewing 25 replies - 76 through 100 (of 162 total)
Skip to toolbar