[英]Joomla PHP plugin how to check the current component is not com_users
So I have the following code that causes a infinite redirect loop because I can't check if the current URL the user is on is the "com_users" component. 因此,我有以下代码会导致无限重定向循环,因为我无法检查用户所在的当前URL是否为“ com_users”组件。
If they are on the com_users component i don't want any more code to execute. 如果它们在com_users组件上,则我不想再执行任何代码。
public function onAfterInitialise() {
$app = JFactory::getApplication();
$user = JFactory::getUser();
if (!$user->guest) {
//THIS CAN'T GET CURRENT COMPONENT AND CAUSES INFINITE redirect LOOP
if ( !($app->input->get('option') == 'com_users' && JRequest::getVar('view') == 'profile') ) { //IF NOT on the EDIT PROFILE URL then force the user to go and change their email
if ($user->email === "fakemail@spam-disposable-domain.com") {
$app->enqueueMessage('Please change your email address!');
$app->redirect(
JRoute::_(
'index.php?option=com_users&view=profile&layout=edit'
)
);
}
}
}
}
Use watchers to keep the complexity low. 使用观察者来降低复杂性。
JRequest
is deprecated, use $app->input
instead. JRequest
已过时,请改用$app->input
。 Input::getCmd()
does some automatic sanitation. Input::getCmd()
一些自动清洁。
public function onAfterInitialise()
{
$user = JFactory::getUser();
$app = JFactory::getApplication();
if ($user->guest)
{
return;
}
if ($app->input->getCmd('option') === 'com_users' && $app->input->getCmd('view') === 'profile')
{
return;
}
if ($user->email === "fakemail@spam-disposable-domain.com")
{
$app->enqueueMessage('Please change your email address!');
$app->redirect(
JRoute::_(
'index.php?option=com_users&view=profile&layout=edit'
)
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.