OK managed to filter the button properly now.
function custom_follow_button( $button ) {
global $bp, $members_template;
$defaults = array(
'leader_id' => bp_displayed_user_id(),
'follower_id' => bp_loggedin_user_id()
);
$r = wp_parse_args( $args, $defaults );
extract( $r );
if ( !$leader_id || !$follower_id )
return false;
// if we're checking during a members loop, then follow status is already queried via bp_follow_inject_member_follow_status()
if ( !empty( $members_template->member ) && $follower_id == bp_loggedin_user_id() && $follower_id == bp_displayed_user_id() ) {
$is_following = $members_template->member->is_following;
}
// else we manually query the follow status
else {
$is_following = bp_follow_is_following( array( 'leader_id' => $leader_id, 'follower_id' => $follower_id ) );
}
// if the logged-in user is the leader, use already-queried variables
if ( bp_loggedin_user_id() && $leader_id == bp_loggedin_user_id() ) {
$leader_domain = bp_loggedin_user_domain();
$leader_fullname = bp_get_loggedin_user_fullname();
}
// else we do a lookup for the user domain and display name of the leader
else {
$leader_domain = bp_core_get_user_domain( $leader_id );
$leader_fullname = bp_core_get_user_displayname( $leader_id );
}
// setup some variables
if ( $is_following ) {
$id = 'following';
$action = 'stop';
$class = 'unfollow';
$link_text = $link_title = sprintf( __( 'Stop Following %s', 'bp-follow' ), apply_filters( 'bp_follow_leader_name', bp_get_user_firstname( $leader_fullname ), $leader_id ) );
}
else {
$id = 'not-following';
$action = 'start';
$class = 'follow';
$link_text = $link_title = sprintf( __( 'Follow %s', 'bp-follow' ), apply_filters( 'bp_follow_leader_name', bp_get_user_firstname( $leader_fullname ), $leader_id ) );
}
// setup the button arguments
$button = array(
'id' => $id,
'component' => 'follow',
'must_be_logged_in' => true,
'block_self' => empty( $members_template->member ) ? true : false,
'wrapper_class' => 'follow-button ' . $id,
'wrapper_id' => 'follow-button-' . $leader_id,
'link_href' => wp_nonce_url( $leader_domain . $bp->follow->followers->slug . '/' . $action .'/', $action . '_following' ),
'link_text' => $link_text,
'link_title' => '',
'link_id' => $class . '-' . $leader_id,
'link_class' => $class
);
return $button;
}
add_filter( 'bp_follow_get_add_follow_button', 'custom_follow_button' );
Link title was the only part I changed as poedit accepts HTML markup so was able to swap out the text for an image using the localisation file.
The approach works for me but if there is an easier way….? (i’m sure my filter can be stripped down too – probably have unnecessary stuff in there)
Ref: bp-follow-templatetags.php line 117