I need to do something witn current node by my module only if anonymous users can view this node. How to check it?
By default I use
$node->status == 1, but some other modules can change anonymous access rights also for published nodes.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
The check if the anonymous user has access to a given
$node, you can use the
node_access() like this:
node_access('view', $node, user_load(0)).
As a side note,
$node->status == 1 will check that the node is published. An unpublished node is usually not visible by anonymous user. Which users are allowed to view unpublished node depends on the granted permissions and node access module enabled on the site.
Do you use a special module to set node permissions? Or just core Drupal?
If just core Drupal, then I think anonymous users only need the "access content" permission, and maybe you could check this with (I have not tested this code):
$anonymous = user_load(0); // load anonymous user $can_access_content = user_access('access content', $anonymous);