• Welcome to Simple Machines Community Forum. Please login or sign up.

Could someone guide me on restricting the NEWS panel from specific membergroups?

Started by rcane, November 27, 2021, 10:08:26 AM

Previous topic - Next topic

rcane

Good morning Gurus:

I'd like to have the 'guests' memberGroup (and perhaps one other group) be restricted from seeing the NEWS feature window.

I found a mod for it called Advanced News but it wouldn't work (wasn't entirely for 2.0.18).

I've never written in php before, only swift for iOS, but I'd like to give it a shot. 

Any guidance would be greatly appreciated.


Sir Osis of Liver

This will hide it from guests -

BoardIndex.template.php



/// hide info center from guests
if ($context['user']['is_logged'])
template_info_center();

}

function template_info_center()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;

"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

rcane

Quote from: Sir Osis of Liver on November 27, 2021, 05:24:48 PMThis will hide it from guests -

BoardIndex.template.php



/// hide info center from guests
if ($context['user']['is_logged'])
template_info_center();

}

function template_info_center()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;



Hi and thanks,

This is for the info center though; I was referring to the NEWS feature at the top of the page.   I don't allow guests so the only "guests" are folks looking at the registration and/or login page.  But, the NEWS still appears for those initial views.  Trying to keep that under wraps.

Shades.


ShadesWeb.com - Custom Logos
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

Sir Osis of Liver

Ooofa, don't know how I misread that.  Do you want to hide the random news item, news fader, or both?
"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns


rcane

Quote from: Sir Osis of Liver on November 27, 2021, 06:00:42 PMOoofa, don't know how I misread that.  Do you want to hide the random news item, news fader, or both?


Well both actually.  But if this is the easiest fix, then just this. 


rcane

Quote from: rcane on November 27, 2021, 06:46:03 PM
Quote from: Sir Osis of Liver on November 27, 2021, 06:00:42 PMOoofa, don't know how I misread that.  Do you want to hide the random news item, news fader, or both?


Well both actually.  But if this is the easiest fix, then just this. 

It seems like this fix above works fine for both. 

I need a good book on this.  Trying to understand all the php files and their relationships in SMF is overwhelming.



rcane

Quote from: Shades. on November 27, 2021, 05:47:27 PMMaybe this will help... 8)

https://www.simplemachines.org/community/index.php?topic=515425.msg3644601#msg3644601

Works for 2.0 & 2.1 ;)

A follow-up question to this solution:

If I have another restricted memberGroup I'd like to prevent from seeing news, can I add it within this code as an "or", or would I have to duplicate the entire statement for the new group?

And if that group's name was a two word, like "pending approval" would it require an underscore between the words?

if ($user_info['is_guest'])
    $settings['enable_news'] = false;

Sir Osis of Liver



if ($user_info['is_guest']) || $user_info['groups']['0'] == 9)
    $settings['enable_news'] = false;


9 would be id_group of the membergroup you want to block.  Members pending approval are guests.


"The best laid schemes o' mice an' men / Gang aft a-gley." - Robert Burns

Diego Andrés

in_array could probably be another option instead of [groups][0], the user could have primary and additional groups too and might fail

SMF Tricks - Free & Premium Responsive Themes for SMF.

rcane

Sir Osis, thanks.  I'll try that.

And Diego, a person wouldn't have conflicting groups if that is what you meant. 

If they are in that restricted group (in the door but not full access to the forums) they can't have additional groups.  I think this should work.

rcane

Quote from: Sir Osis of Liver on November 28, 2021, 10:32:46 PM
if ($user_info['is_guest']) || $user_info['groups']['0'] == 9)
    $settings['enable_news'] = false;


9 would be id_group of the membergroup you want to block.  Members pending approval are guests.




I replaced the "9", with:  13   (which is the group id of the desired group to block). 

The entire forum was inaccessible.   admin level too.  couldn't even bring up the login page.  :)

I think there was a typ. lol.    I entered it as a separate conditional statement below the one restricting guests.  Seems to work. 

If you can explain, what is the [groups]['0'] == 9 part ?  I get the 9 == the group in question, but why the zero in the braces after "group"?

Diego Andrés

It's the index of the first element in the array of groups. In theory that should be either the primary group or the first group found

SMF Tricks - Free & Premium Responsive Themes for SMF.

Kindred

the forum was not accessible because your code is wrong...   it has an extra closing ) which will definitely break everything.

should be this

if ($user_info['is_guest'] || $user_info['groups']['0'] == 9)
    $settings['enable_news'] = false;


Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: