Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to get user id of activity


  • ARCangelGIRL
    Participant

    @arcangelgirl

    I’m using MyCred plugin and a shortcode to have a button that when a user press it, he will send points to other user.
    This button is displayed in every activity entry near user avatar. I need to to get displayed activity user ID. I tried t used bp_get_activity_user_id();, but it is not returning the right value. Is there is any other function that returns user ID of activity?

    Code in function.php

    function one_star_videopoints() {
    global $bp;
    	if ( ! function_exists( 'mycred' ) ) return;
    	$current_id = get_current_user_id();
    	$profile_video_id = bp_get_activity_user_id();
    	if ( $current_id == $profile_video_id ) return;
    	echo '<div class="award-star-rating-img">';
    	echo do_shortcode( '[mycred_send to="' . $profile_video_id . '" amount="1" ref="tip" log="Tipping"][/mycred_send]' );
    	echo '</div>';
    }
    add_action( 'one_star_videopoints_button', 'one_star_videopoints' );

    Code in activity entry.php
    <?php do_action('one_star_videopoints_button'); ?>

Viewing 8 replies - 1 through 8 (of 8 total)

  • Henry Wright
    Moderator

    @henrywright

    bp_get_activity_user_id() is the function that you should be using. What does it return?


    danbp
    Participant

    @danbp

    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:


    ARCangelGIRL
    Participant

    @arcangelgirl

    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..


    Henry Wright
    Moderator

    @henrywright

    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.


    ARCangelGIRL
    Participant

    @arcangelgirl

    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.


    Henry Wright
    Moderator

    @henrywright

    @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.


    ARCangelGIRL
    Participant

    @arcangelgirl

    @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.


    Henry Wright
    Moderator

    @henrywright

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to get user id of activity’ is closed to new replies.
Skip to toolbar