I am using following code for not to show block for administrators. I am using this for adsense blocks.

global $user;
if ($user->uid != 1)
return TRUE;

I do not want to show the block on following pages also. Please modify above code or suggest any alternative.

all pages if user is admin
all pages if user is user 5
user
user/register
user/password
user/*/edit
user/*/contact
node/add
node/add/*

Thank you.

Comments

nevets’s picture

global $user;
if ($user->uid == 1 || $user->uid == 5) {
  return FALSE;
}
$arg0 =  arg(0);
$arg1 = arg(1);
$arg2 = arg(2);
if ( $arg0 == 'user' ) {
  if ( $arg1 == 'register' || $arg1 == 'password' ) {
    return FALSE;
  }
  if ( $arg2 === 'edit' || $arg2 ==  'contact' )  {
    return FALSE;
  }
}
else if ( $arg0 == 'node' && $arg1 == 'add' ) {
  return FALSE;
}

return TRUE;
jeditdog’s picture

also, if you don't want as many if statements in your block, try the block-configuration tool to designate which pages a block should not show up on.

sarmiluv’s picture

Thank you. This is exactly what I wanted. I have small addition to make on the above code. I do not want the blocks to be visible in following ip addresses types also.

12.34.56.789
34.56.78.***
56.34.**.***
78.**.**.***

* means it can be any number. Please suggest a code for the above numbers. I will modify according to my needs.

nevets’s picture

How about this

$ip = ip_address();
$parts = explode('.', $ip);
if ( $parts[0] == '12' && $parts[1] ==  '34' && $parts[2] == '56' && $parts[3] == '789' ) {
  return FALSE;
}
if ( $parts[0] == '34' && $parts[1] ==  '56' && $parts[2] == '78' ) {
  return FALSE;
}
if ( $parts[0] == '56' && $parts[1] ==  '34' ) {
  return FALSE;
}
if ( $parts[0] == '78' ) {
  return FALSE;
}

sarmiluv’s picture

Sorry I have no knowledge with codes. Please combine the the two codes into one.

nevets’s picture

Here is the code all together. (If you are going to use PHP code, you should at least learn the basics).

<?php
global $user;
if ($user->uid == 1 || $user->uid == 5) {
  return FALSE;
}
$arg0 =  arg(0);
$arg1 = arg(1);
$arg2 = arg(2);
if ( $arg0 == 'user' ) {
  if ( $arg1 == 'register' || $arg1 == 'password' ) {
    return FALSE;
  }
  if ( $arg2 === 'edit' || $arg2 ==  'contact' )  {
    return FALSE;
  }
}
else if ( $arg0 == 'node' && $arg1 == 'add' ) {
  return FALSE;
}

$ip = ip_address();
$parts = explode('.', $ip);
if ( $parts[0] == '12' && $parts[1] ==  '34' && $parts[2] == '56' && $parts[3] == '789' ) {
  return FALSE;
}
if ( $parts[0] == '34' && $parts[1] ==  '56' && $parts[2] == '78' ) {
  return FALSE;
}
if ( $parts[0] == '56' && $parts[1] ==  '34' ) {
  return FALSE;
}
if ( $parts[0] == '78' ) {
  return FALSE;
}
return TRUE;
?>
sarmiluv’s picture

Thank you. I want to learn php basics. If you know of any learning materials available online, please let me know. I have some knowledge on C programming. I hope that will be of some help.

sarmiluv’s picture

I do not want the block to be visible in following pages also. Please make the necessary additions on the code.

user
content/privacy-policy-wwwdomaincom
contact

Thank you.

nevets’s picture

I will let you make the changes. Given a path like user/1, 'user' is arg(0), '1', is arg(1). So the new code goes along with

$arg0 =  arg(0);
$arg1 = arg(1);
$arg2 = arg(2);

that sets up values for the first three parts of the path. You want to add code that checks $arg0, $arg1 and $arg2 as needed to see if the path is one you care about.

sarmiluv’s picture

I can't make it work. Please help.

sarmiluv’s picture

I was just curious whether this is a type-o or it is correct in the following part of the code. Let me know if I should just use "==" instead of "===".

if ( $arg2 === 'edit' || $arg2 == 'contact' ) {

aac’s picture

bookmarked!!

---~~~***~~~---
aac