如何解决wordpress密码设置链接失效的问题
- 时间:2020-05-16 19:39:54
- 分类:网络文摘
- 阅读:75 次
对于开放注册的 wordpress 站点而言,当用户注册或者忘记密码需重获密码时,wordpress 都会自动向用户邮箱中发送一个验证链接,点击后就可以设置密码。但经常出现用户打开链接后,提示“您的密码重设链接无效”。此非 wordpress 本身的原因。正常的 wordpress 设置密码链接地址是没有超链接的,而是某些邮箱,主要是QQ邮箱收到邮件后,会将密码设置链接地址及其前后的“<>”一起当成链接地址生成超链接,结果造成链接错误。
网上有很多解决此问题的方法,但基本都是通过修改 wordpress 程序文件来解决的。这样一来,每次升级 wordpress 都需要重新修改程序文件,很是不便。下面分享一个简单的方法,让你一劳永逸的解决此问题。具体操作如下:
添加如下代码到 wordpress主题函数模板 functions.php 文件中,保存即可。
- // 修正忘记密码获取新密码链接
- add_filter('retrieve_password_message', 'zm_reset_password_message_amend', 99, 1);
- function zm_reset_password_message_amend($string) {
- return preg_replace('/<(' . preg_quote(network_site_url(), '/') . '[^>]*)>/', '\1', $string);
- }
- // 修正用户注册设置密码链接
- add_filter( 'wp_new_user_notification_email' , 'zm_user_notification_email_amend', 10, 3 );
- function zm_user_notification_email_amend( $wp_new_user_notification_email, $user, $user_email ) {
- global $wpdb, $wp_hasher;
- $key = wp_generate_password( 20, false );
- do_action( 'retrieve_password_key', $user->user_login, $key );
- if ( emptyempty( $wp_hasher ) ) {
- require_once ABSPATH . WPINC . '/class-phpass.php';
- $wp_hasher = new PasswordHash( 8, true );
- }
- $hashed = time() . ':' . $wp_hasher->HashPassword( $key );
- $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );
- $switched_locale = switch_to_locale( get_user_locale( $user ) );
- $message = sprintf(__('Username: %s'), $user->display_name) . "\r\n\r\n";
- $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
- $message .= '' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . "\r\n\r\n";
- $wp_new_user_notification_email['message'] = $message;
- return $wp_new_user_notification_email;
- }
如果你的wordpress主机不能发邮件请参考:免插件为wordpress配置SMTP服务
推荐阅读:5 Music Blogs That Are Rocking It And How To Get Your Own Band F Depth First Search Algorithm with Hash Set to Find Elements in a Algorithms to Count How Many Numbers Are Smaller Than the Curren Finding the Closest Divisors Greedy Solution to Reconstruct a 2-Row Binary Matrix How to Use jOOQ Library to Write SQL in Java using Fluent Style? Algorithm to Compute the Number of Days Between Two Dates How to Sort Integers by The Number of 1 Bits? Using Depth First Search Algorithm to Delete Tree Nodes with Sum Web Strategies to Start Your SEO Journey
- 评论列表
-
- 添加评论