Hey guys,

Anyone else getting an error message like this when they login?

warning: in_array(): Wrong datatype for second argument 
in /includes/common.inc(1882) : eval()'d code on line 3.

The error message above appears where a custom PHP block should appear for ADMIN only..i.e. I used to have a php based block that only displayed if the user has the "Site Admin" role.

the custom block - which worked very well with 4.5.0 is below.

<?php
global $user;
if (in_array('Site Admin',$user->roles)) {
$output = '<a href="/?q=admin/settings">Site Settings</a> - <a href="/?q=admin/themes">Theme Settings</a> - <a href="/?q=admin/user/configure/permission">User Settings</a> - <a href="/?q=admin/modules">List of Modules</a> - <a href="/?q=admin/block">Blocks</a> - <a href="/?q=admin/settings">module settings</a>';
}
return $output;
?>

have spent a few hours trying to work out whats going on...the weird thing is the error only happens the first time I try and login as the Site Admin...

Any ideas anyone?

thanks in advance for any pointers...

Dub

Comments

carlmcdade’s picture

Try

global $user;
if (in_array((string)('Site Admin'),$user->roles)) {
$output = '<a href="/?q=admin/settings">Site Settings</a> - <a href="/?q=admin/themes">Theme Settings</a> - <a href="/?q=admin/user/configure/permission">User Settings</a> - <a href="/?q=admin/modules">List of Modules</a> - <a href="/?q=admin/block">Blocks</a> - <a href="/?q=admin/settings">module settings</a>';
}
return $output;

or

global $user;
if (in_array(t('Site Admin'),$user->roles)) {
$output = '<a href="/?q=admin/settings">Site Settings</a> - <a href="/?q=admin/themes">Theme Settings</a> - <a href="/?q=admin/user/configure/permission">User Settings</a> - <a href="/?q=admin/modules">List of Modules</a> - <a href="/?q=admin/block">Blocks</a> - <a href="/?q=admin/settings">module settings</a>';
}
return $output;

When you login the first time the SiteAdmin string is probably returning as a boolean 0 or 1.
---------------------------
www.hivemindz.com (running PHP5)
www.fireorb.org (documentation and hacks)
__________________________
Carl McDade
Information Technology Consult
Team Macromedia

Dublin Drupaller’s picture

Thanks Carl..tried both options but it was still giving me errors....

I think it's related to something else....I notice drupal doesn't remember a login so there must be something wrong with the user module..

thanks anyway for your tips...appreciate it..

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

carlmcdade’s picture

Sorry,

I was not reading. The SECOND arguement right ;)

Try setting global $user with user_roles();

$roles_array = user_roles();
$roleids_array = array_keys($roles_array);

foreach ($roleids_array as $roleid) {
			 
check for a match here
			  }

---------------------------
www.hivemindz.com (running PHP5)
www.fireorb.org (documentation and hacks)
__________________________
Carl McDade
Information Technology Consult
Team Macromedia

bermin’s picture

I am having a similar problem (same error) when using the same code (as dude above) to show a block to a specific role. The error comes up when someone incorrectly logs in (wrong id or pw). I have tried your fix, but perhaps I have it wrong because the problem still exists. Maybe a bit more instruction?

thanks