Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 12 replies - 1 through 12 (of 12 total)
  • @sjs719

    Participant

    Any thoughts @coffeywebdev?

    @sjs719

    Participant

    For example, I have tried the following code and tried to call it onClick but it either doesn’t register or throws an error:

    function add_featured_activity(){
    
    GLOBAL $wpdb;
    $user_id = get_current_user_id();
    $user_info = get_userdata( $user_id );
    
    $button_action = "<a href='".site_url()."/members/".$user_info->user_login."'></a>";
    
    // arguments to pass to the bp_activity_add() function
    $args = array(
    'action'            => $button_action,                     // The activity action - e.g. "Jon Doe posted an update"
    'component'         => 'profile',                  // The name/ID of the component e.g. groups, profile, mycomponent
    'type'              => 'activity_update',                  // The activity type e.g. activity_update, profile_updated
    'user_id'           => $user_id,  // Optional: The user to record the activity for, can be false if this activity is not for a user.
    'item_id'           => $user_id,                  // Optional: The ID of the specific item being recorded, e.g. a blog_id
    'recorded_time'     => bp_core_current_time(), // The GMT time that this activity was recorded
    'hide_sitewide'     => 0,                  // Should this be hidden on the sitewide activity stream?
    'is_spam'           => 0,                  // Is this activity item to be marked as spam?
    );
    
    $add_activity = bp_activity_add($args);
    
    // Update the members's last activity
    update_last_activity( $user_id );
    
    return true;
    }  
    add_action('bp_activity_add', 'add_featured_activity' );

    @sjs719

    Participant

    Hey Coffeywebdev,

    I really appreciate your help! Here is what I am trying to do:

    I have a checkbox in the members profile (it’s not a XProfile field) that when clicked makes their profile “Featured” for a while. When the user checks the box it creates a meta entry named “Featured” in the database. Whenever a user checks their checkbox I want it to register as an activity saying something along the lines of “user’s profile is now featured!”.

    Here is the code I am using to display the checkbox:

    <div id="featured-button">   
    <form name="feat_chkbox">
    <label>  
      <input type="checkbox" hidden="hidden" name="feat_chk" id="feat_chk"><span id="featlbl">Featured Member</span> 
    </label>
    </form>
    </div>
    

    I took out all of the onClick functions to avoid confusion. I am guessing I need to create a new onClick event which calls to the bd_activity_add() function, but I don’t know how to build that function. I have tried multiple codes using the following layout:

    function add_featured_activity(){
    global $wpdb, $bp;
    
    $user_id = get_current_user_id();
    
    $args = array(
    'action'            => 
    'content'           => 
    'component'         => 
    'type'              => 
    'primary_link'      => 
    'user_id'           => 
    'item_id'           => 
    'secondary_item_id' => 
    );
    
    $add_activity = bp_activity_add($args);
    
    add_action('comment_post', 'add_featured_activity' );

    But I must not be using the correct args or something. Do you know what args need to be used to register this activity using either the checkbox click event or the meta data created by the checkbox?

    Thx!

    @sjs719

    Participant

    Hey Coffeywebdev,

    Thank you for the reply and info. I understand what code I need to use to add an activity but what I can’t figure out is how to implement a button click into this code. I can create an activity for a new post or comment but I cannot get the button action to properly register as an activity.

    When the button is clicked it creates user meta in the database named “Featured” can I use that in the add activity function? So instead of $comment = get_comment( $comment_id ); it would be something like $activity = get_user_meta ($user_id, 'featured') ?

    @sjs719

    Participant

    No I can’t get any support…

    @sjs719

    Participant

    Anyone? Seems like something that many others would have come across…

    @sjs719

    Participant

    bump2

    @sjs719

    Participant

    bump

    @sjs719

    Participant

    @shanebp

    I understand that I need to create and call a function, I have tried using the following code and no activity gets registered:

    function bp_custom_record_activity() {
     
        $activity_id = bp_activity_add( array(
            'id'		    => '',
            'action'            => '',
            'content'           => '',
            'component'         => '',
            'type'              => '',
            'primary_link'	    => '',
            'user_id'	    => '',
            'item_id'	    => '',
            'secondary_item_id' => '',
            'recorded_time'	    => '',
            'hide_sitewide'	    => '',
        ) );
     
        return $activity_id;
    }

    I have tried multiple values in each field but cannot get it working. So if this is the correct function to use then which values must be filled?
    thx

    @sjs719

    Participant

    Anyone?

    @sjs719

    Participant

    I think you are telling me to add add a function such as this:

    function bp_custom_record_activity() {
     
        $activity_id = bp_activity_add( array(
            'id'		    => '',
            'action'            => '',
            'content'           => '',
            'component'         => '',
            'type'              => '',
            'primary_link'	    => '',
            'user_id'	    => '',
            'item_id'	    => '',
            'secondary_item_id' => '',
            'recorded_time'	    => '',
            'hide_sitewide'	    => '',
        ) );
     
        return $activity_id;
    }

    And then call that function onChange but I am not sure which params I need to include and what the value of those parameters needs to be. I read the bp_activity_add codex but I’m still a little confused.

    bp_activity_add()

    If I have the following checkbox, what values should I use for params such as item_id, action, ID, etc:

    <div id="bd-button">   
    <form name="bdchkbox">
    <label>  
      <input type="checkbox" hidden="hidden" name="bdchk" id="bdchk" onChange="set_check(this);submit()"><span id="bdlbl">Featured</span> 
    </label>
    </form>
    </div>

    @sjs719

    Participant

    Thanks for the reply shane, I have tried adding an onChange and onClick event to the checkbox called “bp_activity_add()” but it breaks the button because it doesn’t recognize the function “bp_activity_add()”.

    Do I need to add something to functions.php as well as the onChange event? If you could provide me with an example I would REALLY appreciate it!
    Thx

Viewing 12 replies - 1 through 12 (of 12 total)
Skip to toolbar