bp_get_activity_user_id()
is the function that you should be using. What does it return?
Test this (i haven’t 😉 ).
function one_star_videopoints() {
$profile_video_id = bp_get_activity_user_id();
echo $profile_video_id( bp_activity_user_id() );
}
add_action( 'one_star_videopoints_button', 'one_star_videopoints' );
On activities loop, use
bp_get_activity_user_id()
to return the ID and bp_activity_user_id()
to echo it.
On members loop, use
bp_get_member_user_id()
to return the ID and bp_member_user_id()
to echo it:
Thank you for your answers! Looks like that I did not describe clear what is my problem, because what I tried from you suggestions it did not work.
There is the code that I’m using to generate “Give a point” button”
function one_star_points() {
if ( ! function_exists( 'mycred' ) ) return;
$current_id = get_current_user_id();
$profile_id = bp_displayed_user_id();
if ( $current_id == $profile_id ) return;
echo '<div class="award-star-rating-img">';
echo do_shortcode( '[mycred_send to="' . $profile_id . '" amount="1" ref="tip" log="Tipping"]Give a point[/mycred_send]' );
echo '</div>';
}
add_action( 'one_star_points_button', 'one_star_points' );
To give points in user profile I used $profile_id = bp_displayed_user_id();
To give points in forum I used $profile_user_id = bbp_get_reply_author_id();
But i bumped into a problem when I want to give points to user in activity stream. I placed the button near every activity stream entry, so the user could give a point if the like what other user posted in activity stream. I used this code $profile_video_id = bp_get_activity_user_id();
There is no error or warning, but it’s not working, not giving points.
Also I would like to give a point if I like private message answer that other user send me. I used this $profile_message_id = bp_get_the_thread_message_sender_id() ;
, but it says that “Missing the recipient for this shortcode.”.
Looks like that in the last two cases (activity stream and messages) something is wrong with indicating user id.
Any recommendations on this? I have tried many functions, but still can’t grab user ID in those last two..
In the case of private messages, bp_get_the_thread_message_sender_id()
is the function you should be using. The problem might be related to where you’re calling from (i.e. the member’s ID might not be accessible at the point where you are using the function).
For example, the bp_get_the_thread_message_sender_id()
function must be used within a single message thread. Used anywhere else, it will return 0
.
Thank you @henrywright ! Button in messages start working when I use the function in a single message thread. My mistake was that I was using it before it.
@arcangelgirl great to hear you got it working! The same idea will apply to the activity stream. You’ll need to make sure you’re using bp_get_activity_user_id()
in the right place.
@henrywright I just tested activity by changing the places where I’m using bp_get_activity_user_id()
function, it did not gave me any effect.
I think it’s not that kind a problem.
I have found this, looks like it’s a filter. Maybe there is another way to declare it $profile_video_id = bp_get_activity_user_id();
I tried to echo, it’s showing right ID’s as I have it right now.
Careful not to confuse the bp_get_activity_user_id
filter hook with the bp_get_activity_user_id()
function.
See here for the function and here for the hook.