Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Can anyone help solve this error please?

Featured Replies

I keep getting this error:-

 

Warning: in_array() [function.in-array]: Wrong datatype for second argument in /homepages/45/d430176851/htdocs/DynamicDance/wp-content/themes/parallelus-unite/functions.php on line 181

 

I am still learning PHP so struggling to see what I have done wrong.

 

The code is:-

function users_login_redirect($redirect_to, $request, $user) 
{
    if(in_array('administrator', $user->roles))
    {
        return admin_url();
    } 
    else
    {
        return '/members-area/';
    }
}

add_filter( 'login_redirect', 'users_login_redirect', 10, 3);

Thank you in advance :-)

Maybe you can try and use a variable:

$user_roles = $user->roles

then your code will be:

function users_login_redirect($redirect_to, $request, $user) 
{
$user_roles = $user->roles
if(in_array('administrator', $user_roles))
{
return admin_url();
} 
else
{
return '/members-area/';
}
}

add_filter( 'login_redirect', 'users_login_redirect', 10, 3);

Shot in the dark, the above.

 

Maybe also try:

if ( current_user_can( 'administrator' ) )

so you need:

function users_login_redirect($redirect_to, $request, $user) 
{
if ( current_user_can( 'administrator' ) )
{
return admin_url();
} 
else
{
return '/members-area/';
}
}

add_filter( 'login_redirect', 'users_login_redirect', 10, 3);
  • Author

Hello Teodora,

 

Thanks for your reply.

 

I did try both codes, I got an error with the first and the second redirected all users to the members area.

 

I have setup a custom user role, I was trying to target these only and not admin. I tried changing "administrator" to the custom role but it didn't work.

 

The original code I posted works but displays the error on the login screen.

You're getting the error because you are not providing an array in which to search. You need to search within the individual users for the role of administrator (or your custom role) for example try:

<?php 
$users= get_users();

var_dump($users[0]->roles);

?>

then you can use inarray();

 

In your case you can use a php counter to loop through all of the users.

Edited by mantis

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.