admin管理员组文章数量:1336631
I am adding functionality to require users to login to view a website by hooking into the template_redirect
action and sending non-authenticated users to wp-login. This is all working fine.
I would like to add a message to the wp-login screen for these visitors, but I do not want the message to be displayed to backend users who are also logging in through the same page. I'm using the login_message
filter to add the text.
Is there a way, when on the wp-login page to determine if the person is trying to login into the frontend or wp-admin? I'm seeing a $_REQUEST['redirect_to']
variable, but it can sometimes be empty, especially after repeated login attempts, and is just a string so would be a messy conditional.
Thanks!
I am adding functionality to require users to login to view a website by hooking into the template_redirect
action and sending non-authenticated users to wp-login. This is all working fine.
I would like to add a message to the wp-login screen for these visitors, but I do not want the message to be displayed to backend users who are also logging in through the same page. I'm using the login_message
filter to add the text.
Is there a way, when on the wp-login page to determine if the person is trying to login into the frontend or wp-admin? I'm seeing a $_REQUEST['redirect_to']
variable, but it can sometimes be empty, especially after repeated login attempts, and is just a string so would be a messy conditional.
Thanks!
Share Improve this question asked May 23, 2020 at 1:11 Louis WLouis W 4741 gold badge6 silver badges18 bronze badges 1 |1 Answer
Reset to default 0You can use additional parameters while redirecting users from front-end.
i.e; http://yourdomain/wp-login.php?frontend=true
And get this parameter to check and determine whether the users have been redirected from the front-end or not.
if( isset($_GET['frontend']) && $GLOBALS['pagenow'] === 'wp-login.php' ) {
echo "<h2 id='fr-msg'>Message To display</h2>";
}
Use this code inside your function.php or in plugin. You can use css and javascript adjustments to display the message in correct position.
jQuery(document).ready(function(){
jQuery("#login").prepend(jQuery("#fr-msg"));
// Use as per your requirement.
}
This will have a dependency of jQuery hence it is necessary to include this script with a jQuery dependency. Include this in your function.php or plugin.
add_action( 'login_enqueue_scripts', function() {
wp_register_script('custom_script', [SCRIPT_URL]/customScript.js, array('jquery'),'4.2', true);
wp_enqueue_script( 'custom_script' );
} );
本文标签: redirectDetermine user destination on wploginphp
版权声明:本文标题:redirect - Determine user destination on wp-login.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742407613a2469146.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$_REQUEST['redirect_to']
be empty if the user comes from the frontend? – Himad Commented May 23, 2020 at 1:46