• jameshh93

    (@jameshh93)


    It makes little sense to set nofollow links on my site from trusted members. Is there a quick functions.php fix that will remove the no follow tag on external links for accounts who have admin or editor status only? or even just a remove for all roles?

    For bbpress I have tried:

    add_filter (‘bbp_get_topic_content’ , ‘follow_topic_if_admin’ , 10 , 2) ;

    function follow_topic_if_admin ($content, $topic_id) {
    $user_id = bbp_get_topic_author_id( $topic_id ) ;
    $user_meta=get_userdata($user_id);
    $user_roles=$user_meta->roles;
    $allowed_roles = array(‘editor’, ‘administrator’);
    if( array_intersect($allowed_roles, $user_roles ) ) {
    remove_filter( ‘bbp_get_topic_content’, ‘bbp_rel_nofollow’, 50 );
    }
    return apply_filters( ‘follow_topic_if_admin’, $content, $topic_id );
    }

    add_filter (‘bbp_get_reply_content’ , ‘follow_reply_if_admin’ , 10 , 2) ;

    function follow_reply_if_admin ($content, $reply_id) {
    $user_id = bbp_get_reply_author_id( $reply_id ) ;
    $user_meta=get_userdata($user_id);
    $user_roles=$user_meta->roles;
    $allowed_roles = array(‘editor’, ‘administrator’);
    if( array_intersect($allowed_roles, $user_roles ) ) {
    remove_filter( ‘bbp_get_reply_content’, ‘bbp_rel_nofollow’, 50 );
    }
    return apply_filters( ‘follow_reply_if_admin’, $content, $reply_id );
    }

    But that proves unsuccessful as I think buddypress is ignoring it using
    https://buddypress.wp-a2z.org/oik_api/bp_activity_make_nofollow_filter_callback/

    Any help would be great as I have search and searched and there is no solution anywhere online for this.

    Thank you.

    • This topic was modified 7 years ago by jameshh93.
Viewing 3 replies - 1 through 3 (of 3 total)
  • danieltj

    (@danieltj)

    Hi, take a look at this post on the bbPress forums. I think this should sort out the problem. You can use the code you wrote above to check if the user is an admin or editor and then remove the filter if true.

    As a suggestion though, I’d check if the user has certain capabilities rather than a particular role as that will allow you to have more granular control over who’s links are set to nofollow etc. Details about capabilities can be found here.

    I’d suggest using the edit_pages cap for this using the current_user_can() function which should do the trick.

    Thread Starter jameshh93

    (@jameshh93)

    @danieltj thanks for the reply ?? unfortunately I did write the code above credit goes to Robin w here https://bbpress.org/forums/topic/remove-relnofollow-for-admin-only/

    I tried adding just to see if I could turn off the nofollow for all users in buddypress but it didnt work.

    remove_filter( 'bp_activity_post_update', 'bp_activity_make_nofollow_filter' );

    • This reply was modified 7 years ago by jameshh93.
    danieltj

    (@danieltj)

    It looks like you might need to add a priority to the filer.

    remove_filter( 'bp_activity_post_update', 'bp_activity_make_nofollow_filter', 50 ); if you try that, does it work then?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Buddypress/bbpress remove rel=”nofollow” in links’ is closed to new replies.