is there a method for isModerator ? (XenForo_Visitor::getInstance()) ?!

TBDragon

Active member
hi how r u

i just saw in some addon

XenForo_Visitor::getInstance()->isSuperAdmin()

so it can check whether the visitor is super admin or no

but what if i need to check of moderator or some group id ?!
which class i need to extend so i can use that
or its same in the XenForo_ControllerPublic_Abstract ?!

and thank ^_^
 
You should be using an IDE that will suggest functions and properties that are available:

upload_2014-3-20_18-40-4.webp

As it happens, you have access to the full user record from the Visitor object. is_moderator is a field in xf_user.

To find out if a visitor is registered or not, just use XenForo_Visitor::getInstance()->getUserId() or XenForo_Visitor::getInstance()->user_id.
 
You should be using an IDE that will suggest functions and properties that are available:

View attachment 70022

As it happens, you have access to the full user record from the Visitor object. is_moderator is a field in xf_user.

To find out if a visitor is registered or not, just use XenForo_Visitor::getInstance()->getUserId() or XenForo_Visitor::getInstance()->user_id.
ya i think i will do this
=_= as my sublime text dont have this ability =( i will use phpstorm for XF

thanks again ^_^
 
i have small issue

PHP:
  if (!((XenForo_Visitor::getInstance()->isSuperAdmin()) || (XenForo_Visitor::getInstance()->is_moderator)))
     {
       throw $this->getNoPermissionResponseException();
     }

its give me the getNoPermissionResponseException()
when iam loging as moderator

but if i use the id for example

PHP:
if (!((XenForo_Visitor::getInstance()->isSuperAdmin()) || (XenForo_Visitor::getInstance()->getUserId(31635))))

its work fine y that no permission appear for me >_< and when i used the getUserId($id) work fine ?

btw even the isMemberOf(4) its work fine <<< as the number 4 is the moderator group id !!

y with is_moderator not working

and thanks
 
PHP:
if (!((XenForo_Visitor::getInstance()->isSuperAdmin()) || (XenForo_Visitor::getInstance()->getUserId(31635))))
The usage of this is wrong.

getUserId returns the logged in user's ID that's all. It doesn't help you get another user's details.
 
PHP:
if (!((XenForo_Visitor::getInstance()->isSuperAdmin()) || (XenForo_Visitor::getInstance()->getUserId(31635))))
The usage of this is wrong.

getUserId returns the logged in user's ID that's all. It doesn't help you get another user's details.
yes i know but i just to try the options i have for the usage i need
the isMemberOf(4) is great as this is what i need for moderator but the confusing is y is_moderator is not working ?!
 
Being in the Moderating user group does not automatically make you a moderator.

A moderator is a user who has been created as a moderator on this page: admin.php?moderators/

If your user does not appear there, they are not a moderator and therefore is_moderator would be 0.

Also you don't need to set up a new instance every time. Also most of your parenthesises are unnecessary.

PHP:
$visitor = XenForo_Visitor::getInstance();

if (!$visitor->isSuperAdmin() || $visitor->is_moderator)
{
    // Your code
}
 
Being in the Moderating user group does not automatically make you a moderator.

A moderator is a user who has been created as a moderator on this page: admin.php?moderators/

If your user does not appear there, they are not a moderator and therefore is_moderator would be 0.

Also you don't need to set up a new instance every time. Also most of your parenthesises are unnecessary.

PHP:
$visitor = XenForo_Visitor::getInstance();

if (!$visitor->isSuperAdmin() || $visitor->is_moderator)
{
    // Your code
}

i see thats great then ^_^

so even if i need to use it several time on the same php file i just define it one time only then use it
< its not my code i just modify it to fit my need but i will send this to the one who make it to know about it

thanks again brother ^^
 
so even if i need to use it several time on the same php file i just define it one time only then use it

It has to be within the same function. For example

PHP:
class Your_Class
{
 function test()
 {
   $visitor = XenForo_Visitor::getInstance();
   var_dump(isset($visitor)); // returns bool(true);
   $this->test2();
 }
 function test2()
 {
  var_dump(isset($visitor)); // returns bool(false);
 }
}

You can use $visitor however much you want within the first function, but you'll have to re-assign it in the second function for it to work.
 
It has to be within the same function. For example

PHP:
class Your_Class
{
function test()
{
   $visitor = XenForo_Visitor::getInstance();
   var_dump(isset($visitor)); // returns bool(true);
   $this->test2();
}
function test2()
{
  var_dump(isset($visitor)); // returns bool(false);
}
}

You can use $visitor however much you want within the first function, but you'll have to re-assign it in the second function for it to work.

thanks @Daniel Hood , is it possible to make it as global ?! or it will not work in this way !?
 
It's not necessary to make it global. Just use it when you need it. If you need to use XenForo_Visitor::getInstance() more than once in a function, that's when you should consider assigning it to a variable, e.g. $visitor.
 
It's not necessary to make it global. Just use it when you need it. If you need to use XenForo_Visitor::getInstance() more than once in a function, that's when you should consider assigning it to a variable, e.g. $visitor.
hmmm the problem the addon its not mine so idk what every thing happen
but its used in 4 function so its just let the one who have the permission to do the actions
 
Top Bottom