Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding xprofile fields to activity header


  • karmatiger
    Participant

    @karmatiger

    in the activity stream, for each entry there is the user’s avatar, and beside that a header that include their username, latest action (‘updated their profile’ or whatever), and below that smaller print indicating when they were last online.

    That info is all in the activity-header generated on entry.php. How entry.php calls this info is to run the self-echoing function bp_activity_action.

    I want to add xpfofile field data and the delete link to this header. Some would try to ram it into entry.php but then you must fuss around with the CSS to get the info up near or into the activity header, risking breaking something else.

    I’m trying to add it to the bp_activity_action. I found a thread sort of on topic here, but this chap was trying to do something else and his self-discovered solution was to ram it into entry.php before the header rather than using the action hook.

    I’ve created a simple function to test adding something to bp_activity_action, simply trying to add the word “success!” somewhere in the header:

    function SN_member_header() {	
        echo "success!";
    }
    
    add_action( 'bp_activity_action', 'SN_member_header');

    …but nothing appears. What am I missing?

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

  • ckchaudhary
    Participant

    @ckchaudhary

    The filter you are looking for is bp_get_activity_action. So you’ll need to do something like:

    function SN_member_header( $action ) {	
        return $action . "success!";
    }
    
    add_filter( 'bp_get_activity_action', 'SN_member_header');

    For a better understanding, you can check the code in function bp_get_activity_action in plugins/buddypress/bp-activity/bp-activity-template.php


    karmatiger
    Participant

    @karmatiger

    thanks 🙂 That narrows it down. However, I’m trying to add text to the header, inline with the timestamp. The filter solution above places text after the header, two line breaks down.

    I’ve added

    if ( ! function_exists( 'bp_get_activity_action' ) ) {
        function bp_get_activity_action( $args = array() ) {... 

    …the rest is a copy of the original bp_get_activity_action function so I can override it with this new one via the child theme. However, I’ve tried adding the new info at various points throughout the function and still nothing is displaying other than the default info.


    danbp
    Participant

    @danbp

    They are filters for timestamp.
    To get some text before the ago part, try this:

    function text_pre_timestamp() {
    
    $var = 'custom text %s'; // %s = timestamp
       return $var;
    
    }
    add_filter( 'bp_core_time_since_ago_text', 'text_pre_timestamp' );

    Code references


    karmatiger
    Participant

    @karmatiger

    dan that was extremely helpful 🙂 I’m so close now…

    I’m using

    function text_pre_timestamp() {
      $link = '';
      if ( bp_activity_user_can_delete() ) {
    	  $url   = bp_get_activity_delete_url();
    	  $link = '<a href="' . $url . '" class="activity-list delete">' . __( 'Delete', 'buddypress' ) . '</a>';
    	  $test = 'sample text ';
      }
      
      $var = ' %s ago ';// %s = timestamp
      if (!$link == '') $var = $var . '| ' . $test . $link; 
      return $var;
    
    }
    add_filter( 'bp_core_time_since_ago_text', 'text_pre_timestamp' );

    and it works! Well… for some reason it’s putting the Delete link on a separate line, and I can’t figure out why. As you can see I’ve included test text, which it includes on the same line as the timestamp. If I put $link before the timestamp it displays inline; but if I put it after the timestamp it puts the href one line down. Is this a Buddypress thing?

    The CSS used:

    .activity-list .delete {
      display: inline; 
      font-size:10px; 
      padding: 0; 
      margin: 0;
    }

    You can see by the display: inline I’m attempting to get the href to be on the same line as the rest of the text. have you any thoughts as to why it’s inserting a line break?


    danbp
    Participant

    @danbp

    No idea ! Perhaps try something like <span style=”white-space: nowrap”>Long line with no breaks</span> to your CSS ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar