在wp-login.php上确定用户目标

时间:2020-05-23 作者:Louis W

我添加了一些功能,要求用户通过连接到template_redirect 操作并将未经身份验证的用户发送到wp登录。一切正常。

我想为这些访问者在wp登录屏幕上添加一条消息,但我不想将该消息显示给也通过同一页面登录的后端用户。我正在使用login_message 筛选以添加文本。

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? 我看到一个$_REQUEST[\'redirect_to\'] 变量,但它有时可能为空,尤其是在多次登录尝试后,并且它只是一个字符串,因此可能是一个混乱的条件。

谢谢

1 个回复
最合适的回答,由SO网友:Behemoth 整理而成

您可以在从前端重定向用户时使用其他参数
即:;http://yourdomain.com/wp-login.php?frontend=true

并获取此参数以检查并确定是否已从前端重定向用户。

if( isset($_GET[\'frontend\']) && $GLOBALS[\'pagenow\'] === \'wp-login.php\' ) {
    echo "<h2 id=\'fr-msg\'>Message To display</h2>";
}
在函数中使用此代码。php或插件。您可以使用css和javascript调整将消息显示在正确的位置。

jQuery(document).ready(function(){
    jQuery("#login").prepend(jQuery("#fr-msg"));
// Use as per your requirement.
}
这将具有jQuery的依赖关系,因此有必要将此脚本包含在jQuery依赖关系中。在您的函数中包含此项。php或插件。

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\' );
} );

相关推荐

WP_REDIRECT进入无限循环

我想根据位置重定向WordPress页面,例如域名/ar、域名/fr等,但代码进入无限循环。这是飞贼:function redirect_location(){ //$UserDetailss = var_export(unserialize(file_get_contents(\'http://www.geoplugin.net/php.gp?ip=\'))); $UserDetails = unserialize(file_get_contents(\'ht