I am looking for this question How can I nofollow all external links by user role? I have found these codes to convert all links to Nofallow, can anyone change these codes according to the user's role /
// add nofollow to links
function nofollow_for_external($content) {
$content = preg_replace_callback( '/<a[^>]*href=["|\']([^"|\']*)["|\'][^>]*>([^<]*)<\/a>/i', function($m) {
if (strpos($m[1], "domain") === false)
return '<a href="'.$m[1].'" rel="nofollow">'.$m[2].'</a>';
else
return '<a href="'.$m[1].'">'.$m[2].'</a>';
},
$content );
return $content;
}
add_filter('the_content', 'nofollow_for_external');
// Stop self pingback
function disable_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'disable_self_ping' );