【发布时间】:2014-05-20 16:26:58
【问题描述】:
这是我想替换的函数: array('administrator','author') 带有类似 array($string) 的 var 所以我有一个来自我的主题选项(来自一个选择字段)的数组,它返回我在我的函数中需要的用户角色,它返回如下:
Array ( [0] => administrator [1] => author [2] => subscriber )
我做到了:
$string = "'".implode("','",$array)."'";
我的功能:
add_filter("login_redirect", "subscriber_login_redirect", 10, 3);
function subscriber_login_redirect($redirect_to, $request, $user) {
if(is_array($user->roles))
if ( count( array_diff( $user->roles, array($string) ) ) !== count( $user->roles ) ) return site_url('/wp-admin/')
return home_url();
}
但仍然存在问题,在我的控制台日志中,字符串 var 返回 'administrator'、'author'、'subscriber'
感谢您的帮助
【问题讨论】: