WordPress自定义身份验证在管理员登录时失败

我已经创建了一个自定义的身份验证过程,这样我就可以基于外部来源。那个部件工作正常,不是这个问题的主题。 我遇到的问题是在长时间不活动(一夜之间,浏览器关闭等)后以管理员(或编辑)身份登录时。在这种情况下,管理员不是能够登录,没有错误,我只是返回登录第页解决方法(奇怪的是…)是我以订阅者身份登录(成功),然后注销并以订阅者身份重新登录管理员。这个系列作品每时间到了管理员可以重复登录,直到另一段时间处于不活动状态。 问题是:有人能告诉我我为什么要这样做吗必须以订户身份登录一次才能成功登录?我怀疑这与饼干。之后我在一个浏览器(比如Mozilla)中成功地成为管理员,我可以打开另一个浏览器(比如Chrome),第二个浏览器也会遇到同样的问题,直到用户登录。 下面是我的代码。我已经减少了代码并删除了自定义身份验证一块。一块只需验证代码中的两个用户:SiteUser(订阅者)和SiteAdmin(管理员)。 add_filter( \"authenticate\", \"my_login_validation\", 10, 3 );//add_action(\"wp_authenticate_user\", \"check_validation_status\", 10, 2);// doesn\"t workfunction my_login_validation($user, $username, $password) {// Make sure a username and password are present for us to work withif($username == \"\" || $password == \"\") == \"SiteAdmin\" && $password == \"SiteAdminpwd123\") {return $user;}// SiteUser authenticates hereif ($username == \"SiteUser\" && $password == \"SiteUserpwd123\") {return> - This topic was modified 8 months, 2 weeks ago by bcworkz. Reason: code fixed What version of WP are you using? I\"ve encountered similar behavior before, but I don\"t recall it happening lately. At least in my case, I actually am correctly logged in even though the login screen takes me in circles. Directly requesting a back end URL like /wp-admin/ results in the expected admin screen. I never tried logging in as a subscriber, nor do I have a custom authentication process, so the similarity could be coincidental. There\"s definitely something off with the original auth cookie, so that doing an alternate log in forces the cookies to be refreshed. In my case, the flaw only affects the login page, other back end requests honor the original cookie without complaint. I\"ve not determined the root cause because I cannot reliably replicate the behavior. You were right, I was logged in as admin.despite the login page showing again. My version is 5.5.1 The site I was building was a prototype.I have since built the live site on a different host and I haven\"t seen the problem there yet.On the prototype I was using a code snippet to force the default page to be the login page.That may have been part of the problem.The live site has a static front page with a \"click to log in\" button. NEW QUESTION: Would you happen to know some code I could add to my authentication function to (in some cases) hand the authentication back over to the standard WordPress code?I\"d like to be able to allow some native WordPress users to log in, in addition to my externally-authenticated users. BTW, my external authentication talks to a VBScript running on my MS IIS server which uses LDAP internally to validate the existence of the user, and uses LDAP to confirm the password is correct.Thus, my WordPress site is available only to MS domain users with their domain pwd.My full script on the WordPress side also creates the WordPress user upon their first login to WordPress.(I got all of the code from the work of others via web searches.) I think the redirect while still logged in is due to the server not forwarding the auth cookie with a redirect. Apparently most do, some occasionally don\"t. I\"ve no idea what setting would affect that behavior. If your callback simply returns what ever value it was passed unchanged (usually null),WP将验证如果没有添加回调,它通常会如何进行验证。我认为您只需要注释掉新的WP_Error()行就可以了。 顺便说一句,我认为您不需要删除带有remove_action()的回调,除非您正在跟踪登录尝试并将其保留在中会增加统计数据。不管怎么说,这样做也没什么坏处,如果你愿意的话就让它保持原样吧。我对不必要的代码感到恼火 谢谢你对这件事的见解。我不明白你的意思答案。答案authorization函数接受3个参数($user,$username,$password)。如何将它们原封不动地返回?我只能返回一个值。 筛选器只能将第一个传递的值更改为返回值。$user是返回不变的值。WP将把剩余的值原样传递给其他回调,而不管回调如何处理它们。应该没有必要更改用户名和密码。即使有,\"authenticate\"也不是这样做的地方。 这个概念只适用于普通过滤器。还有一个filter by reference变量,您可以在其中更改各种传递的值。在这种情况下,单个对象通过引用传递,因此您可以直接更改其任何属性。不过,这不是\"身份验证\"的工作方式,它是一个普通的过滤器

admin_action_{$_REQUEST[‘action’]}

do_action( "admin_action_{$_REQUEST[‘action’]}" )动作钩子::在发送“Action”请求变量时激发。Action Hook: Fires when an ‘action’ request variable is sent.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$_REQUEST['action']引用从GET或POST请求派生的操作。源码(Source)更新版本源码位置使用被使用2.6.0 wp-admin/admin.php:...

日期:2020-09-02 17:44:16 浏览:1157

admin_footer-{$GLOBALS[‘hook_suffix’]}

do_action( "admin_footer-{$GLOBALS[‘hook_suffix’]}", string $hook_suffix )操作挂钩:在默认页脚脚本之后打印脚本或数据。Action Hook: Print scripts or data after the default footer scripts.目录锚点:#说明#参数#源码说明(Description)钩子名的动态部分,$GLOBALS['hook_suffix']引用当前页的全局钩子后缀。参数(Parameters)参数类...

日期:2020-09-02 17:44:20 浏览:1058

customize_save_{$this->id_data[‘base’]}

do_action( "customize_save_{$this->id_data[‘base’]}", WP_Customize_Setting $this )动作钩子::在调用WP_Customize_Setting::save()方法时激发。Action Hook: Fires when the WP_Customize_Setting::save() method is called.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_data...

日期:2020-08-15 15:47:24 浏览:798

customize_value_{$this->id_data[‘base’]}

apply_filters( "customize_value_{$this->id_data[‘base’]}", mixed $default )过滤器::过滤未作为主题模式或选项处理的自定义设置值。Filter Hook: Filter a Customize setting value not handled as a theme_mod or option.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分,$this->id_date['base'],指的是设置...

日期:2020-08-15 15:47:24 浏览:883

get_comment_author_url

过滤钩子:过滤评论作者的URL。Filter Hook: Filters the comment author’s URL.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/comment-template.php:32610...

日期:2020-08-10 23:06:14 浏览:924

network_admin_edit_{$_GET[‘action’]}

do_action( "network_admin_edit_{$_GET[‘action’]}" )操作挂钩:启动请求的处理程序操作。Action Hook: Fires the requested handler action.目录锚点:#说明#源码说明(Description)钩子名称的动态部分$u GET['action']引用请求的操作的名称。源码(Source)更新版本源码位置使用被使用3.1.0 wp-admin/network/edit.php:3600...

日期:2020-08-02 09:56:09 浏览:869

network_sites_updated_message_{$_GET[‘updated’]}

apply_filters( "network_sites_updated_message_{$_GET[‘updated’]}", string $msg )筛选器挂钩:在网络管理中筛选特定的非默认站点更新消息。Filter Hook: Filters a specific, non-default site-updated message in the Network admin.目录锚点:#说明#参数#源码说明(Description)钩子名称的动态部分$_GET['updated']引用了非默认的...

日期:2020-08-02 09:56:03 浏览:854

pre_wp_is_site_initialized

过滤器::过滤在访问数据库之前是否初始化站点的检查。Filter Hook: Filters the check for whether a site is initialized before the database is accessed.目录锚点:#源码源码(Source)更新版本源码位置使用被使用 wp-includes/ms-site.php:93910...

日期:2020-07-29 10:15:38 浏览:825

WordPress 的SEO 教学:如何在网站中加入关键字(Meta Keywords)与Meta 描述(Meta Description)?

你想在WordPress 中添加关键字和meta 描述吗?关键字和meta 描述使你能够提高网站的SEO。在本文中,我们将向你展示如何在WordPress 中正确添加关键字和meta 描述。为什么要在WordPress 中添加关键字和Meta 描述?关键字和说明让搜寻引擎更了解您的帖子和页面的内容。关键词是人们寻找您发布的内容时,可能会搜索的重要词语或片语。而Meta Description则是对你的页面和文章的简要描述。如果你想要了解更多关于中继标签的资讯,可以参考Google的说明。Meta 关键字和描...

日期:2020-10-03 21:18:25 浏览:1688

谷歌的SEO是什么

SEO (Search Engine Optimization)中文是搜寻引擎最佳化,意思近于「关键字自然排序」、「网站排名优化」。简言之,SEO是以搜索引擎(如Google、Bing)为曝光媒体的行销手法。例如搜寻「wordpress教学」,会看到本站的「WordPress教学:12个课程…」排行Google第一:关键字:wordpress教学、wordpress课程…若搜寻「网站架设」,则会看到另一个网页排名第1:关键字:网站架设、架站…以上两个网页,每月从搜寻引擎导入自然流量,达2万4千:每月「有机搜...

日期:2020-10-30 17:23:57 浏览:1294