first post
-
I can not start a new thread?
Are new users blocked first or do you have to check my thread until its visible…
Thanks
Matthias
-
sorry, sometimes the spam filters are overactive.
Add you real question below !
I still can not post my question. It’s a longer question and its a link in it.
Perhabs that’s the problem…?I found a nice code, that shows the first message in a thread for everyone.
Answer are shown only to logged in users.Perfekt so far.
BUT the code shows in every answer the same message for non logged users
“Replies only viewable for logged in users”Does anyone know, how to change the code, to show only one template-notice
“Replies only viewable for logged in users” instead?function bb_auth_reply_view( $reply_id ) { $reply_id = bbp_get_reply_id( $reply_id ); // Check if password is required if ( post_password_required( $reply_id ) ) return get_the_password_form(); $content = get_post_field( 'post_content', $reply_id ); // first topic reply shouldn't be hiding $rep_position = bbp_get_reply_position($reply_id); // if user is not logged in and not the first post topic if( !is_user_logged_in() && $rep_position > 1 ) { return "Replies only viewable for logged in users"; } else { // return normal return $content; } } add_filter( 'bbp_get_reply_content', 'bb_auth_reply_view' );
Thanks
Matthiastry your link again, as it should make it clear what you are after !
That’s how it looks in my forum. There are all answer-posters visible only the text is hidden.
and I just want to show like the yellow template notice here
Thanks
Matthiasthe filter is just applying to the reply content.
You probably want to amend a template – How php code/wordpress knowledgable are you?
I thought I can do it with a filter in functions.php.
Don’t want to setup a child theme for this.
Is it possible to do it with just adding a additonal bbpress file to my theme?My php-code knowledge is just search, copy and paste đ
Thanks
MatthiasI thought I can do it with a filter in functions.php.
unfortunately not that easy if you don’t want to show the replies, as the loop-replies file has no easy filter to hook to !
yes you can put this in your main theme, just be aware itr will get overwritten by any theme update, so keep a good note of what you did, so you can do it again if needed.
create a directory on your theme called ‘bbpress’
ie wp-content/%your-theme-name%/bbpress
find
wp-content/plugins/bbpress/templates/default/bbpress/loop-replies.php
Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
wp-content/%your-theme-name%/bbpress/loop-replies.php
bbPress will now use this template instead of the originalso that gets the right file
I wish I had time to write a solution for you for free, but I’m tied up in other work.
but basically you want to look at lines
<?php while ( bbp_replies() ) : bbp_the_reply(); ?> <?php bbp_get_template_part( 'loop', 'single-reply' ); ?>
You want to stop it getting the template loop-single-reply if it is after pos 1, so something like
<?php while ( bbp_replies() ) : bbp_the_reply(); ?> <?php // if user is not logged in and is the first reply if( !is_user_logged_in() && $rep_position =2 ) { echo "Replies only viewable for logged in users"; } // if user is not logged in and is after the forst reply, then don't do naything elseif( !is_user_logged_in() && $rep_position >2 ) { } //otherwise carry on as usual else bbp_get_template_part( 'loop', 'single-reply' ); ?>
small correction to above done
Hm, it shows this error…
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'bb_auth_reply_view' not found or invalid function name in ..../blog/wp-includes/plugin.php on line 213
I wish I had time to write a solution for you for free, but Iâm tied up in other work.
sorry, I’ll keep a note of this and if I get a chance look at again shortly.
Otherwise contact me via my website
maybe
<?php while ( bbp_replies() ) : bbp_the_reply(); ?>
// first topic reply shouldn’t be hiding
$rep_position = bbp_get_reply_position($reply_id);<?php // if user is not logged in and is the first reply
if( !is_user_logged_in() && $rep_position =2 ) {
echo “Replies only viewable for logged in users”;
}
// if user is not logged in and is after the forst reply, then don’t do naything
elseif( !is_user_logged_in() && $rep_position >2 ) {
}
//otherwise carry on as usual
else bbp_get_template_part( ‘loop’, ‘single-reply’ ); ?>I think we are close, but it gives me an error in this line
echo âReplies only viewable for logged in usersâ;
Parse error: syntax error, unexpected ‘only‘ (T_STRING), expecting ‘,’ or ‘;’
Seems like it uses the message as code?can you post the full error and a copy of the lines above and below
Hi Robin,
The full error is this:
Parse error: syntax error, unexpected ‘only’ (T_STRING), expecting ‘,’ or ‘;’ in …./blog/wp-content/themes/virtue_premium/bbpress/loop-replies.php on line 54<?php // if user is not logged in and is the first reply
if( !is_user_logged_in() && $rep_position =2 ) {
echo âReplies only viewable for logged in usersâ;
}
// if user is not logged in and is after the forst reply, then donât do naything
elseif( !is_user_logged_in() && $rep_position >2 ) {
}
//otherwise carry on as usual
else bbp_get_template_part( âloopâ, âsingle-replyâ ); ?>try
if( !is_user_logged_in() && $rep_position ==2 ) {
That’s causing the same error!
can only suggest that there is some hidden formatting in that line, try typing it from scratch
I put the whole code in the editor. But I get the same error…
sorry, but I’d need to spend time to fix this.
If you want a paid solution, contact me via my website
- You must be logged in to reply to this topic.