MyBB Community Forums

Full Version: detect guest?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can i detect guest in header template?
What variables can I use? Is there any document related to this?
You can rely on the template "header_template_welcome_guest".
This template is displayed for guests (visitors not logged in).

What do you want to achieve exactly?

[ExiTuS]
If you wanted to display something only to guests, you can be clever with CSS:

<div class="guest-notice guest-notice-uid-{$mybb->user['uid']}">
...
</div>

.guest-notice {
    display: none;
}

.guest-notice-uid-0 {
    display: block;
}

$mybb->user['uid'] will be 0 for guests so the CSS class would be guest-notice-uid-0 and would then use the CSS to show the div again.

This is assuming this is the sort of thing you wanted to do.
(2021-02-22, 10:46 AM)Matt Wrote: [ -> ]If you wanted to display something only to guests, you can be clever with CSS:

<div class="guest-notice guest-notice-uid-{$mybb->user['uid']}">
...
</div>

.guest-notice {
    display: none;
}

.guest-notice-uid-0 {
    display: block;
}

$mybb->user['uid'] will be 0 for guests so the CSS class would be guest-notice-uid-0 and would then use the CSS to show the div again.

This is assuming this is the sort of thing you wanted to do.

Thanks for reply, so, can i do that?
if ({$mybb->user['uid']}==0){
//guest javascript codes
}else{
//members javascript codes
}
You can't have conditions in templates without an additional plugin (this is the one people usually use I think http://mybbhacks.zingaburga.com/showthread.php?tid=464).
As I said before,
put the code for guests into template "header_template_welcome_guest",
for members into "header_template_welcome_member"

[ExiTuS]
(2021-02-22, 03:05 PM)[ExiTuS] Wrote: [ -> ]As I said before,
put the code for guests into template "header_template_welcome_guest",
for members into "header_template_welcome_member"

[ExiTuS]

Oh yes, this would work Smile
(2021-02-22, 10:46 AM)Matt Wrote: [ -> ]If you wanted to display something only to guests, you can be clever with CSS:

<div class="guest-notice guest-notice-uid-{$mybb->user['uid']}">
...
</div>

.guest-notice {
    display: none;
}

.guest-notice-uid-0 {
    display: block;
}

$mybb->user['uid'] will be 0 for guests so the CSS class would be guest-notice-uid-0 and would then use the CSS to show the div again.

This is assuming this is the sort of thing you wanted to do.

Hi Matt! 

I want to do something very similar with this plugin
https://community.mybb.com/mods.php?action=view&pid=462

but to be able to display the message to the every group not just moderator and regardless if they able to post or not

https://community.mybb.com/mods.php?acti...w&pid=1344

Looks I have to change only this

if (is_moderator($fid, "canpostclosedthreads") && $thread['closed'])
        eval("\$newreply = \"".$display.$templates->get("showthread_newreply")."\";");


but I do not know how to do it

Can you please help with this?

Thanks