[pmwiki-users] Is there a way to disable a cookbook in some Group and how ?

Peter Bowers pbowers at pobox.com
Fri Jan 29 01:45:37 CST 2010

On Fri, Jan 29, 2010 at 7:51 AM, ABClf <languefrancaise at gmail.com> wrote:
> if ($group != 'Private' && $action == 'edit') {
> include_once("$FarmD/cookbook/authorcontrib.php"); }

This (above) is correct.

> if (!$group == 'P' && $action == 'edit') {
> include_once("$FarmD/cookbook/authorcontrib.php"); }
> That blocks too other group.
> I don't see where is the trouble : doesn't the « if condition » says :
> if not group P + if action=edit ?

You have a problem with the order of processing of operators.  You are
assuming NOT (group == P) while it is actually being processed as
((NOT GROUP) == P).

Since all data types in PHP can be used as booleans (0 or blank or
null or whatever is false, other values are true) what you have done
is converted $group from a string to a boolean -- since $group always
has a value (i.e., boolean TRUE) then putting the ! in front of it
says "NOT $group" or boolean FALSE when $group contains something.
Thus when you are saying (!$group == 'P') it becomes (FALSE == 'P').

Anyway, that was a long explanation and maybe not so helpful.  Here's
what you're looking for to implement the semantics you were aiming

> if (!($group == 'P' && $action == 'edit')) {
> include_once("$FarmD/cookbook/authorcontrib.php"); }

(Note the parentheses surrounding the entire inner conditional)

This is kind of different than the way it's usually written, although
I may be just expressing my own stylistic preferences.  I would tend
to write the same thing like this:

> if ($group != 'P' || $action != 'edit') {
> include_once("$FarmD/cookbook/authorcontrib.php"); }

Note the change of both == operators to != and the change of && to ||.


More information about the pmwiki-users mailing list