I have this function
function bp_insert_activity_meta( $content ) {
global $activities_template;
// Strip any legacy time since placeholders from BP 1.0-1.1
$content = str_replace( '<span class="time-since">%s</span>', '', $content );
// Insert the time since.
$time_since = apply_filters_ref_array( 'bp_activity_time_since', array( '<span class="time-since">' . bp_core_time_since( $activities_template->activity->date_recorded ) . '</span>', &$activities_template->activity ) );
// Insert the permalink
if ( !bp_is_single_activity() )
$content = apply_filters_ref_array( 'bp_activity_permalink', array( sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since ), &$activities_template->activity ) );
else
$content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );
return apply_filters( 'bp_insert_activity_meta', $content );
}
I want to add_Filter to this part:
$content = apply_filters_ref_array( 'bp_activity_permalink', array( sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since ), &$activities_template->activity ) );
This is how I tried to add_filter, but the output comes out twice, one for the original code and a second time with my code (note I added a "testing-class-for-filter" class to the link to see if it is outputting it)
function testing_filter_abc( $content ) {
global $activities_template;
// Insert the time since.
$time_since = apply_filters_ref_array( 'bp_activity_time_since', array( '<span class="time-since">' . bp_core_time_since( $activities_template->activity->date_recorded ) . '</span>', &$activities_template->activity ) );
return sprintf( '%1$s <a href="%2$s" class="view testing-class-for-filter activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since );
}
add_filter( 'bp_activity_permalink', 'testing_filter_abc' );
Is there something obvious that I am not doing? Been trying for hours to get this to work! Thanks in advance
In your function testing_filter_abc( $content )
$content is an array with 2 elements; a string and a reference.
There is no variable $content like that variable in function bp_insert_activity_meta
Your return in testing_filter_abc() includes the array that was passed to your filter.
Use a different name for the array passed to your filter and it will be more obvious.
function testing_filter_abc( $content_array ) {
var_dump( $content_array )