XF 2.3 Hide specific posts (or part of a post) from guests

Mr Lucky

Well-known member
Does anyone know a way to hide specific posts with in thread from guests?

Alternatively choose a portion of a post and hide that from guests?

EDIT (Sorry I wasn’t very clear):

What I mean is as a moderator function. Ideally like soft delete but visible to registered users. This would need to not show in source code also as I want the posts to not be crawled and indexed.

Failing that bbcode could work but not so useful i.e. moderators select the text and apply bbcode. Then the text is still visible to logged in members but hidden from guests (including Google)
 
Last edited:
Built-in
Soft delete the posts

Template edit
If you don't mind showing varying number of posts / page (maybe even none at all) you can add a conditional in template post_macros

Custom BB-Code
You can add a custom BB code with PHP callback that renders empty for guests

Add-on
You can create a custom Add-on thst does this, this would be the most flexible option
 
Built-in
Soft delete the posts
This would also hide them from members
Custom BB-Code
You can add a custom BB code with PHP callback that renders empty for guests
This sounds good, can you please explain how to do that?
Add-on
You can create a custom Add-on thst does this, this would be the most flexible option
I cannot create addons as I'm on a shared server.
 
Does anyone know a way to hide specific posts with in thread from guests?
As Kirby mentioned a template edit would be the quickest "hardcoded" hack. I've often thought it would be nice to have custom post fields which could be used as the basis for things like this.

Alternatively choose a portion of a post and hide that from guests?
There are a couple of Add-Ons that provide "hide" BBCodes that could be used for this.
I've a feeling I've seen a third one, but I can't find it right now. Anyhow you could markup some or all of a post within those tags and it'd only be shown to those meeting whatever conditions were set by the tag. Or as mentioned since those add-ons probably have more functionality than you need you could roll your own with a callback.
 
This would also hide them from members
Yeah. Your question was "Does anyone know a way to hide specific posts with in thread from guests?" - this option does that.
You did not ask for a way to hide posts for guests only :)

This sounds good, can you please explain how to do that?


Use conditional # 4 and smth. like
Code:
OR !in_array($post.post_id, [1, 2, 3])

I cannot create addons as I'm on a shared server.
Unless your server is very restricted you most certainly can use Add-ons.
 
Last edited:
Yeah. Your question was "Does anyone know a way to hide specific posts with in thread from guests?"

I'll edit my first post, I meant could someone please explain how to do it...


Unless your server is very restricted you most certainly can use Add-ons.
" for this we need to open a command prompt / shell / terminal window," I am unable to use command prompt on the server.

Use conditional # 4 and smth. like
I think maybe I'm not explaining myself very well. (I'll edit my first post) I can see how that could would hiding some posts, but I need to be able to do this as a moderator function, so when you said bbcode that would be perfect. Using conditionals in a template would not work like that.

Ideally I select some text in the post, and apply the bbcode so that it hides that text from guests.
 
Ideally I select some text in the post, and apply the bbcode so that it hides that text from guests.
Given you can't easily add your own PHP code it's probably easiest to install one of the add-ons I mentioned. I know with the MMO one you can disable most of the more esoteric tags and just stick with the [club] ... content for members only ... [/club] tag which will do what you need. Granted you may want to style it a little.
 
Given you can't easily add your own PHP code i

Is it not just a question of adding it in the custom bbcode editor?

Granted you may want to style it a little.

Yes, I'm wrestling with that at the moment.

I was hoping it would be a bit simpler just to add my own bbcode.

This seems ideal:

Custom BB-Code
You can add a custom BB code with PHP callback that renders empty for guests

But I just need to know what PHP callback.
 
Last edited:
I do something like this for guests who use adblocking to blur out the posts using conditionals. I can send the template mod code and css if interested.
 
This seems ideal:

Custom BB-Code
You can add a custom BB code with PHP callback that renders empty for guests

But I just need to know what PHP callback.
You'd have to write the PHP code as a PHP file on the filesystem and then you reference it here - so you'd need to either generate an add-on (which is the neater way) or just dump a PHP file in and reference it. You'd need access to the filesystem and to write some PHP code.
If (as I think you may have) you've installed the MMO add-on you'll see those tags referencing the add-on code as an example.
 
I do something like this for guests who use adblocking to blur out the posts using conditionals. I can send the template mod code and css if interested.
Thanks, but this would be something mods do on the fly just for certain posts.
You'd need access to the filesystem and to write some PHP code.
If (as I think you may have) you've installed the MMO add-on you'll see those tags referencing the add-on code as an example.
Thanks, maybe I need to rethink this or request an addon.

Ideally a mod would be able to choose to hide a whole post (like soft delete but still viewable by registered users) , or else a part of the text. I'm trying think of a way to remove off topic guff from Google etc. mainly.
 
I'm trying think of a way to remove off topic guff from Google etc. mainly.
Presumably it's mixed in with other content? Otherwise you'd just have it in a node that was not fully visible to guests.

I would personally just use the MMO add-on and style the boxes to be invisible:
CSS:
div.bbCodeBlock--hide.bbCodeBlock--visible {
    color: inherit !important;
    background: none !important;
    border-left: none !important;
    margin: 0 !important;
    border: none !important;
}

Or something like that, or still use the add-on and just edit it to tweak the markup! You could commission your own version, but the trick is getting the information about the user "rendering" the tag into the code, so there are some hoops to jump through as I don't think this information is available in the information passed to the BBCode renderer. Still presumably not that hard for someone who knows their XF!
 
Back
Top Bottom