[development] Blocks and page context

Sam Tresler sam at treslerdesigns.com
Fri Apr 23 23:23:45 UTC 2010

user_access takes an optional account parameter.  

I think 

$account = user_load(0);
user_access('perm', $account);

Should work...

"Jennifer Hodgdon" <yahgrp at poplarware.com> wrote:

>Is this in a test? Then you can probably use $this->userLogout() and 
>then browse, I think?
>    Jennifer
>E.J. Zufelt wrote:
>> Good afternoon,
>> I am planning on releasing as a contrib module, so if there is a better way to test to see if a menu item is available for anonymous access without a hack I'd happily implement it.
>> On 2010-04-23, at 6:58 PM, Jennifer Hodgdon wrote:
>>> That's the "hack" I was referring to. As far as acceptability goes, I don't know what to tell you. If it's in your own private module, no one can complain...
>>>   --Jennifer
>>> E.J. Zufelt wrote:
>>>> Would it be acceptable in the Drupal community for me to solve this problem by creating a user0 object, switching it with the global $user, perform the test, and then switch back?  By acceptable I mean are there any significant problems I shoud be aware of if using this approach?
>>>> On 2010-04-23, at 6:12 PM, Jennifer Hodgdon wrote:
>>>>> E.J. Zufelt wrote:
>>>>>> I notice that menu_get_item() will tell me if the current user can access the current menu item.  Is there a simple method to test if user0 can access the current menu item?  That is, regardless who the current user is, I would like to see if there is a function to let me know if user0 can access the current page, essentially a test to see if the current page is available to anonymous users or not.
>>>>> I don't think there's an easy way. The access checking for menu_get_item() is done in _menu_check_access(). This figures out and calls the access callback for the particular menu item. For the most general case of a menu item with a custom access callback, it would probably not be possible to modify the function to check a specific $account instead of the current global $user, without some sort of hack.
>>>>>  --Jennifer
>Jennifer Hodgdon * Poplar ProductivityWare
>Drupal, WordPress, and custom Web programming

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

More information about the development mailing list