Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add profile meta to activity item

  • @graeme_bryson

    Participant

    Hi,

    I’m looking to insert some information from the extended profile into a user’s activity item. Specifically, I’m trying to show the ‘Job Title’ field I’ve created and included at registration next to their name. I’ve drafted up a quick mockup and marked the new field with a (1) for clarity here: https://www.dropbox.com/s/1rnmrt5kjnkph1m/sample.png?dl=0

    Initially I’ve searched for ‘activity-header’ in the BuddyPress core files to see if it’s something I can easily drop in (which led me to entry.php), but from what I understand this file just pulls in bp_activity_action. I’m pretty overwhelmed and not quite sure where to start, so any advice would be massively appreciated.

    Thanks in advance, Graeme

Viewing 4 replies - 1 through 4 (of 4 total)
  • @shanebp

    Moderator

    …this file just pulls in bp_activity_action

    And that’s what you need to filter.
    There are a couple of filters you can use.
    Look at function bp_activity_action
    in this file buddypress\bp-activity\bp-activity-template.php

    You probably want to use the first filter.
    Something like:

    function graeme_activity_action( $action, $activity, $r) {
    
       $action .= ' something added here';  // simple example
    
       return $action; 
    }
    add_filter( 'bp_get_activity_action_pre_meta', 'graeme_activity_action', 1, 3 );

    @graeme_bryson

    Participant

    @shanebp Thanks for this – it’s exactly what I’m looking for. I’ve dropped in some quick text just to test the placement and it’s dropping the job title in between ‘Posted an update…’ and ‘3 days, 16 hours go’, visible here: https://www.dropbox.com/s/9hh9ty6db63ct34/Screen%20Shot%202016-02-22%20at%2009.35.04.png?dl=0

    I’m using the following, and assumed that tweaking the 1, 3 will re-order the placement, but from my attempts it either stays in the same place, or removes the user’s display name.

    //* Add Job Title to activity
    function graeme_activity_action( $action, $activity, $r) {
    
       $action .= '<span class="job-title">' . ' | Web Developer' . '</span>';  // simple example
    
       return $action;
    }
    add_filter( 'bp_get_activity_action_pre_meta', 'graeme_activity_action', 1, 3 );

    Do you know which configuration I need to place the job title immediately after the user’s display name? I assume there’s also a way to move the ‘Posted an update’ text afterwards, I’m just not sure which is best practice.

    @shanebp

    Moderator

    …assumed that tweaking the 1, 3 will re-order the placement

    Read this to learn what the 1, 3 does.

    To insert your string into the action string, use str_replace.

    Something like:

    $job_title = '</a> <span class="job-title">' . ' | Web Developer' . '</span>'; 
    $action = str_replace( '</a>', $job_title, $action);

    @graeme_bryson

    Participant

    Read this to learn what the 1, 3 does.

    Thanks for this, that’s actually cleared up a bit of misinformation I’ve had in the past.

    I’m now using the following snippet if anyone needs it in the future. It may not be perfect in terms of logic, but it seems to be working well.

    //* Add Job Title to activity
    function job_title_activity_action( $action, $activity, $r) {
    
    	$bp_job_title = bp_get_profile_field_data( 'field=Job Title&user_id=' . bp_get_activity_user_id());
    	$job_title = '</a> <span class="job-title">' . $bp_job_title . '</span>';
    	$action = str_replace( '</a>', $job_title, $action);
    
       return $action;
    
    }
    add_filter( 'bp_get_activity_action_pre_meta', 'job_title_activity_action', 1, 3 );

    Thanks for your help @shanebp, I really appreciate it!

    Cheers, Graeme

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add profile meta to activity item’ is closed to new replies.
Skip to toolbar