Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: NanoSector on April 14, 2012, 04:36:33 AM

Title: [TRICK] Show an error when a guest tries to view a topic
Post by: NanoSector on April 14, 2012, 04:36:33 AM
Since this has been requested several times now, and I've posted a solution before, here goes:

In /Sources/Display.php, find this:

Code (Find) Select
// What are you gonna display if these are empty?!
if (empty($topic))
fatal_lang_error('no_board', false);


And add this after:

Code (Add after) Select
// Are we a guest?
if ($context['user']['is_guest'])
fatal_lang_error('cannot_view_topic_guest');


Then, in your Modifications.{language}.php, add this before the ?> and change the message:

$txt['cannot_view_topic_guest'] = 'The error you would like in here';

So if I'd like to have "Sorry, guest, but you are unable to view topics!" as error message, I'd put this in:

$txt['cannot_view_topic_guest'] = 'Sorry, guest, but you are unable to view topics!';

So now guests should be unable to view topics and instead get that message smashed in their face ;)
Title: Re: [TRICK] Show an error when a guest tries to view a topic
Post by: Robert. on April 14, 2012, 04:37:44 AM
Nice trick :)
Title: Re: [TRICK] Show an error when a guest tries to view a topic
Post by: NanoSector on April 14, 2012, 04:39:03 AM
Thanks, and thank you for reminding me to post a trick for it ;)
Title: Re: [TRICK] Show an error when a guest tries to view a topic
Post by: flower12 on November 21, 2021, 05:22:00 PM
Quote from: NanoSector on April 14, 2012, 04:36:33 AMSince this has been requested several times now, and I've posted a solution before, here goes:

In /Sources/Display.php, find this:

Code (Find) Select
// What are you gonna display if these are empty?!
if (empty($topic))
fatal_lang_error('no_board', false);

And add this after:

Code (Add after) Select
// Are we a guest?
if ($context['user']['is_guest'])
fatal_lang_error('cannot_view_topic_guest');

Then, in your Modifications.{language}.php, add this before the ?> and change the message:

$txt['cannot_view_topic_guest'] = 'The error you would like in here';
So if I'd like to have "Sorry, guest, but you are unable to view topics!" as error message, I'd put this in:

$txt['cannot_view_topic_guest'] = 'Sorry, guest, but you are unable to view topics!';
So now guests should be unable to view topics and instead get that message smashed in their face ;)

Thank you!!