Forum Replies Created
-
In reply to: Need help with PM function in forums
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.
In reply to: Need help with PM function in forumsYes, 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.
In reply to: Need help with PM function in forumsThat’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.
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;
}`In reply to: Need help with PM function in forumsI would start with adding $bp to your global statement.
`global $bp, $topic_template;`
In reply to: Get IP address that can pass current $user_ID?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.
In reply to: Get IP address that can pass current $user_ID?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()`.
``
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.
In reply to: Get IP address that can pass current $user_ID?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.
In reply to: Get IP address that can pass current $user_ID?Are you using the code exactly as I’ve placed it? Are you putting the html below
“but before
“
?
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?
In reply to: Get IP address that can pass current $user_ID?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?
In reply to: Get IP address that can pass current $user_ID?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:
``
In reply to: Get IP address that can pass current $user_ID?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:
``
In reply to: Get IP address that can pass current $user_ID?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.
In reply to: Get IP address that can pass current $user_ID?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?
In reply to: Get IP address that can pass current $user_ID?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.
In reply to: require users to login to see rest of pages?Have you read over the FAQs here: (https://buddypress.org/community/groups/private-buddypress/)?
In reply to: Get IP address that can pass current $user_ID?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;
}`In reply to: Organize / Hierarchy BlogsIn reply to: Get IP address that can pass current $user_ID?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’ );`In reply to: Get IP address that can pass current $user_ID?I don’t know what you mean by “first code”
In reply to: Get IP address that can pass current $user_ID?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.
In reply to: Get IP address that can pass current $user_ID?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.
Haha! No worries. Post back if you get stuck.