News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

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;

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

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 - My Themes on SMF | My Themes on ShadesWeb
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?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters


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.


Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

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;


Слaва
Украинi

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."

rcane

Quote from: Diego Andrés on November 29, 2021, 12:57:07 PMIt'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

It's been a while and I'm building 3 more SFM's.  I tried implementing this again (though now the group in question is "10" and not "13" in this install...ordering I suppose.  It's not working though. 

Can't figure out why....

Diego Andrés

Because like I said in my previous post, using that code could be inconsistent.
You should instead use something like this:  if (in_array(12$user_info['groups']))
Where 12 is the id of the group.

Searching for multiple:
if (in_array(12$user_info['groups']) || in_array(7$user_info['groups']))

SMF Tricks - Free & Premium Responsive Themes for SMF.

rcane

Quote from: Diego Andrés on February 03, 2022, 11:33:53 PMBecause like I said in my previous post, using that code could be inconsistent.
You should instead use something like this:  if (in_array(12$user_info['groups']))
Where 12 is the id of the group.

Searching for multiple:
if (in_array(12$user_info['groups']) || in_array(7$user_info['groups']))

no i understood.  searching the array was better than position 0. 

this test account only has one member group and it's still not working. going to go check permissions and see if i missed something

Diego Andrés

Anything in the error log?
Did you add $user_info to the globals in the function you are adding this code?

SMF Tricks - Free & Premium Responsive Themes for SMF.

rcane

Quote from: Diego Andrés on February 03, 2022, 11:45:56 PMAnything in the error log?
Did you add $user_info to the globals in the function you are adding this code?


yeah, it's already in the function.  no error logs. works fine on my other smf.

Advertisement: