Jump to content

\IPS\Member::loggedIn() object question - isAdmin... isMod?


Go to solution Solved by IPCommerceFan,

Recommended Posts

Posted (edited)

Question 1: How would I check if a user is in a Moderator group?
I understand that the below exists:

\IPS\Member::loggedIn()->isAdmin()

Is there an equivalent for Moderator? What is it? - I understand I could just check all Group IDs that I know are Moderators but that means hardcoding and it isn't very elegant, I put an example below of that:

{{if \IPS\Member::loggedIn()->inGroup( array( 28, 15, 6 ) )}}
	Groups 28, 15 and 6 can view this. (All of which are Moderator groups)
{{endif}}

But... I don't really want to do this. I would much rather something like an "isMod" check that would update itself, rather than needing me to put IDs every time a moderator group is added, or removed.

Question 2: How can I check all of the things available for me to use for an object in IPS such as \IPS\Member::loggedIn()? What documentation exists to show me all the methods, etc. if any?

Thank you!

Edited by Liloz01
Posted
3 minutes ago, Liloz01 said:

How can I check all of the things available for me to use for an object in IPS such as \IPS\Member::loggedIn()?

The best option is to look at the corresponding file which sets these functions. In this case, this would be: system → Member → Member.php

Posted
8 hours ago, opentype said:

The best option is to look at the corresponding file which sets these functions. In this case, this would be: system → Member → Member.php

Thanks for letting me know. I wish some type of easier to search system existed though. Even just a PDF, lol.

 

8 hours ago, Daniel F said:

You could use IPS\Member::loggedIn()->modPermission() to see if the member has any mod permissions 

This will do the job! Thank you.

  • Solution
Posted

 

On 9/6/2021 at 12:33 AM, Liloz01 said:

Question 2: How can I check all of the things available for me to use for an object in IPS such as \IPS\Member::loggedIn()? What documentation exists to show me all the methods, etc. if any?

@Liloz01, I'd say the comments in the source files are a pretty good form of documentation.  I use a 3rd party app called FileLocator aka Agent Ransack to search the source files for these sorts of things:

image.thumb.png.3c1afffe454003a091837c00f7f91726.png

We knew exactly what to search for in this case, but a search for just "moderator" would have ultimately led to the same result since the comment includes the word in line 72.

I'm no programmer, but this tool along with a good IDE like PhpStorm have made all the difference in developing my own plugins as the need arises!

As for how to know what you can do with \IPS\Member::loggedIn, I'd search for "\IPS\Member" and browse around to see how it is used, especially as it pertains to functions which accept a Member object.  (To find it used strictly in functions I'd search for "@param    \IPS\Member")

e.g.:   \IPS\Member::loggedIn()->memberPostCount() 

	/**
	 * Post count for member
	 *
	 * @param	\IPS\Member	$member								The member
	 * @param	bool		$includeNonPostCountIncreasing		If FALSE, will skip any posts which would not cause the user's post count to increase
	 * @param	bool		$includeHiddenAndPendingApproval	If FALSE, will skip any hidden posts, or posts pending approval
	 * @return	int
	 */
	public static function memberPostCount( \IPS\Member $member, bool $includeNonPostCountIncreasing = FALSE, bool $includeHiddenAndPendingApproval = TRUE )

Hope that helps!

Posted (edited)
On 9/7/2021 at 5:02 PM, IPCommerceFan said:

I'm no programmer, but this tool along with a good IDE like PhpStorm have made all the difference in developing my own plugins as the need arises!

You don't need that other program if you already have and use PhpStorm. Ctrl + Shift + F will give you an equal solution 🙂 

image.thumb.png.5e570b11099d4e82a3e03ad002df9f34.png

Edited by Martin A.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...