For a "Page" node, I want to add an event that only acts on node edited by users who are not administrator user.

I use the following code, it doesn't work:

<?php [node:user-id] != 1 ? TRUE : FALSE; ?> 

No matter what I change; for Admin the event is getting called. I've checked all permutations and combinations of syntax (including return) but it seems that "Check a truth values" is getting ignored.


The code you are using is not outputting any value; the PHP code you are writing is supposed to output 1 if the actions associated to the condition need to be executed, and 0 when they don't need to be executed.

The correct condition is the following one:

<?php echo ([node:author-uid] != 1); ?>

Alternatively, you can use the following one:

<?php echo ($author->uid != 1); ?>
  • Verify the token you are using is the correct one; the one I see with Drupal 6 is [node:author-uid].
  • The operator != already returns a boolean value; there is no need to convert it to a boolean, as you do with the code you have written. The "Truth value" field accepts also 1 and 0 as values; there is no need to convert a value to a boolean.

The description reported for "PHP Evaluation" is the following one:

PHP code inside of <?php ?> delimiters will be evaluated and replaced by its output. E.g. <? echo 1+1; ?> will be replaced by 2.


To notice that the user with ID equal to 1 is a particular user to whom Drupal always give any permission defined from any module; this is the only user account that is treaded in this particular way. Administrator users don't have their user ID always equal to 1; if you are checking the user ID to verify if the user is an administration user, then you are doing it wrong. In Drupal, you usually check the permissions the user has with user_access().

| improve this answer | |
  • Grate answer the only thing it's missing is that Drupal re-directs a lot, particularly on node edits, loggins, and other user input interactions. This can make the echo lost along the way. Logging can help with that. watchdog can be helpful with that. – ransom bot Dec 3 '12 at 9:43
  • The Rules module is using ob_start(), eval(), ob_get_contents(), and ob_end_clean() to get what the user's code echo()-ed. With the code I wrote, no redirection happens. The string passed to echo() is never shown to the user. – kiamlaluno Dec 3 '12 at 19:33

In addition to kiamlaluno's answer describing the appropriate syntax, the other vital clue is that you must turn the PHP Filter module on. Otherwise, Rules interprets your input as plain text, which almost always evaluates to TRUE in PHP. Turn the PHP Filter on, use the syntax in the other answer, and you should be all set.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.