Display links in the content to members only
-
Hello
I want a code to use in the function file of bbPress to hide all links in the content of forum’s topics and replies for visitors.
I mean until a visitor is not logged in the forum, instead of displaying links, it shows a text message like “displaying links to members only” and a registration link to register and enter his account so that redirects to the last page in the topic or reply.
Additional Explanation:
I Use the code below:
add_filter( 'the_content', 'content_link_for_user_snippets', 1 ); function content_link_for_user_snippets( $content = '' ) { // Snippets.ir if( ! is_user_logged_in() ) { preg_match_all( "#<a(.*?)>(.*?)#i", $content, $matches ); $num = count( $matches[0] ); for( $i = 0; $i < $num; $i++ ) { $content = str_replace( $matches[0][ $i ], '<a href="' . ( get_permalink() ) . '"><span style="color:#F00;">[displaying links to members only]<span></a>', $content ); } } return $content; }in My site’s Theme and word very nice but it doesn’t have any effect in form and couldn’t use it in bbPress function’ file.
-
sorry for late reply.
You would do better to link to topic and reply content
so
add_filter( 'bbp_get_reply_content', 'content_link_for_user_snippets',80, 2 ); add_filter( 'bbp_get_topic_content', 'content_link_for_user_snippets', 80, 2 );I’d run them at priority 80, as bbpress runs various actions at this point, including one called ‘bbp_make_clickable’ at priority 60, which would probably reverse your efforts !
and couldn’t use it in bbPress function’ file.
Put this in your child theme’s function file –
ie wp-content/themes/%your-theme-name%/functions.php
where %your-theme-name% is the name of your theme
or use
- You must be logged in to reply to this topic.