Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using the buddypress hovercards plugin and Im dislaying some profile info as well as the latest status update. If a user posts a long status, it will run out of the hovercard div field. How can I properly truncate this?

<div class="update">
  <strong><?php _e("Last update", 'bp-hovercards'); ?></strong>
  <br>
  <?php bp_member_latest_update( 'length=10' ) ?>
</div>
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can filter 'bp_get_activity_latest_update_excerpt'. Sample code, not tested, you will need my function utf8_truncate():

add_filter( 'bp_get_activity_latest_update_excerpt', 'wpse_56860_trim_buddypress_excerpt' );

function wpse_56860_trim_buddypress_excerpt( $excerpt )
{
    // Number of characters to show. Adjust this to your needs.
    $length = 80;

    // Fix BuddyPress’ wrong quotes.
    return _x( '&#8220;', 'opening curly double quote' ) 
        . utf8_truncate( $excerpt, $length )
        . _x( '&#8221;', 'closing curly double quote' );
}

Download as complete plugin.

Update

There is an alternative: create a hovercard.php in your theme, the plugin will use this file then instead of the same named file in the plugin directory. In hovercard.php change the line bp_member_latest_update( 'length=10' ) to get the proper length or add the filter at the top of the file and remove it after the last endif;:

<?php if ( bp_has_members( "include={$_POST['userid']}&max=1") ) : 
add_filter( 'bp_get_activity_latest_update_excerpt', 'wpse_56860_trim_buddypress_excerpt', 8 );
?>
// lots of stuff
<?php endif; 

remove_filter( 'bp_get_activity_latest_update_excerpt', 'wpse_56860_trim_buddypress_excerpt', 8 );
share|improve this answer
    
I'm sorry. I would love to give this a try but I don't know where to place it. Can you please tell me where in my php files to place these snippets? Do I put them in my theme's functions.php or the plugin's php or..? –  Aliyah Jun 28 '12 at 22:35
    
See my update. You can download the complete code as a plugin and install it on your blog. –  toscho Jun 28 '12 at 22:38
    
I've uploaded it into my plugins folder but can't see it in the plugins list. Is that supposed to happen? Also, I need to only truncate the activity that is shown in a certain plugin (hovercards plugin) –  Aliyah Jun 28 '12 at 22:59
    
Hm, it should be visible. Did you save the raw file as bp-last-activity-shortener.php? –  toscho Jun 28 '12 at 23:04
    
Well yes but that is inside of a folder. Should I upload it to plugins without a folder? –  Aliyah Jun 28 '12 at 23:07
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.