亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home CMS Tutorial WordPress How to Fix WordPress Password Settings Link Error

How to Fix WordPress Password Settings Link Error

Feb 24, 2020 pm 04:49 PM
wordpress

下面由WordPress教程欄目給大家介紹修正 WordPress 密碼設(shè)置鏈接錯(cuò)誤的方法,希望對(duì)需要的朋友有所幫助!

How to Fix WordPress Password Settings Link Error

當(dāng)用戶注冊(cè)或者忘記密碼獲取新密碼時(shí)WordPress會(huì)自動(dòng)向用戶郵箱中發(fā)送一個(gè)驗(yàn)證鏈接地址,用戶通過打開這個(gè)鏈接設(shè)置密碼,不過經(jīng)常發(fā)現(xiàn)這個(gè)鏈接直接打開后,并不是設(shè)置密碼的正確鏈接。

這個(gè)問題的并不是WordPress的原因,正常WordPress設(shè)置密碼的鏈接地址是沒有超鏈接的,而是QQ郵箱自作聰明為個(gè)鏈接地址加上了超鏈接,并把本不是鏈接地址內(nèi)容的<>符號(hào)也加了進(jìn)去,結(jié)果造成鏈接錯(cuò)誤,貌似只有大家常用的QQ郵箱有此問題。這是一個(gè)老生常談問題,網(wǎng)上解決辦法比比皆是,不過都是千篇一律,充分體現(xiàn)了天下文章一大抄。

下面是我的解決方法,以WordPress 5.3.2為例:

一、最簡單的方法

修改WordPress程序文件刪除代碼中的<>符號(hào),

修正忘記密碼獲取新密碼鏈接

打開WordPress程序根目錄的wp-login.php文件,將大約417行的:

$message .= &#39;<&#39; . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), &#39;login&#39; ) . ">\r\n";

改為:

$message .= &#39;&#39; . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), &#39;login&#39; ) . "\r\n";

只是把代碼中前后<>符號(hào)去掉。

修正用戶注冊(cè)設(shè)置密碼鏈接

打開WordPress程序wp-includes目錄中的pluggable.php文件,將大約2003行的:

$message .= &#39;<&#39; . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), &#39;login&#39; ) . ">\r\n\r\n";

改為

$message .= &#39;&#39; . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), &#39;login&#39; ) . "\r\n\r\n";

也是只需要把代碼中前后<>符號(hào)去掉即可。

缺點(diǎn):升級(jí)WordPress程序后,需要再次修改。

二、一勞永逸的方法

這也是本文的重點(diǎn),也是應(yīng)主題用戶的要求,添加到目前主題中的方法,這里分享一下。

將下面代碼添加到當(dāng)前主題函數(shù)模板functions.php中即可。

// 修正忘記密碼獲取新密碼鏈接
add_filter(&#39;retrieve_password_message&#39;, &#39;zm_reset_password_message_amend&#39;, 99, 1);
function zm_reset_password_message_amend($string) {
return preg_replace(&#39;/<(&#39; . preg_quote(network_site_url(), &#39;/&#39;) . &#39;[^>]*)>/&#39;, &#39;\1&#39;, $string);
}
 
// 修正用戶注冊(cè)設(shè)置密碼鏈接
add_filter( &#39;wp_new_user_notification_email&#39; , &#39;zm_user_notification_email_amend&#39;, 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( &#39;retrieve_password_key&#39;, $user->user_login, $key );
if ( empty( $wp_hasher ) ) {
require_once ABSPATH . WPINC . &#39;/class-phpass.php&#39;;
$wp_hasher = new PasswordHash( 8, true );
}
$hashed = time() . &#39;:&#39; . $wp_hasher->HashPassword( $key );
$wpdb->update( $wpdb->users, array( &#39;user_activation_key&#39; => $hashed ), array( &#39;user_login&#39; => $user->user_login ) );
$switched_locale = switch_to_locale( get_user_locale( $user ) );
$message = sprintf(__(&#39;Username: %s&#39;), $user->display_name) . "\r\n\r\n";
$message .= __(&#39;To set your password, visit the following address:&#39;) . "\r\n\r\n";
$message .= &#39;&#39; . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), &#39;login&#39;) . "\r\n\r\n";
$wp_new_user_notification_email[&#39;message&#39;] = $message;
return $wp_new_user_notification_email;
}

網(wǎng)上能找到修正重置密碼鏈接的方法,不過代碼略顯拖沓,本文的方法只一句關(guān)鍵代碼解決。

至于修正用戶注冊(cè)設(shè)置密碼鏈接,經(jīng)過重寫郵件函數(shù)解決,貌似代碼還有精簡的余地,以后再研究了。

優(yōu)點(diǎn):一勞永逸,不會(huì)因?yàn)閃ordPress程序的頻繁升級(jí)而再次修改。

更多編程相關(guān)內(nèi)容,請(qǐng)關(guān)注php中文網(wǎng)編程入門欄目!

The above is the detailed content of How to Fix WordPress Password Settings Link Error. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

10 latest tools for web developers 10 latest tools for web developers May 07, 2025 pm 04:48 PM

Web development design is a promising career field. However, this industry also faces many challenges. As more businesses and brands turn to the online marketplace, web developers have the opportunity to demonstrate their skills and succeed in their careers. However, as demand for web development continues to grow, the number of developers is also increasing, resulting in increasingly fierce competition. But it’s exciting that if you have the talent and will, you can always find new ways to create unique designs and ideas. As a web developer, you may need to keep looking for new tools and resources. These new tools and resources not only make your job more convenient, but also improve the quality of your work, thus helping you win more business and customers. The trends of web development are constantly changing.

How to import the source code of wordpress How to import the source code of wordpress Apr 20, 2025 am 11:24 AM

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

How to build a website for wordpress host How to build a website for wordpress host Apr 20, 2025 am 11:12 AM

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

How to add your WordPress site in Yandex Webmaster Tools How to add your WordPress site in Yandex Webmaster Tools May 12, 2025 pm 09:06 PM

Do you want to connect your website to Yandex Webmaster Tools? Webmaster tools such as Google Search Console, Bing and Yandex can help you optimize your website, monitor traffic, manage robots.txt, check for website errors, and more. In this article, we will share how to add your WordPress website to the Yandex Webmaster Tool to monitor your search engine traffic. What is Yandex? Yandex is a popular search engine based in Russia, similar to Google and Bing. You can excel in Yandex

How to set, get and delete WordPress cookies (like a professional) How to set, get and delete WordPress cookies (like a professional) May 12, 2025 pm 08:57 PM

Do you want to know how to use cookies on your WordPress website? Cookies are useful tools for storing temporary information in users’ browsers. You can use this information to enhance the user experience through personalization and behavioral targeting. In this ultimate guide, we will show you how to set, get, and delete WordPresscookies like a professional. Note: This is an advanced tutorial. It requires you to be proficient in HTML, CSS, WordPress websites and PHP. What are cookies? Cookies are created and stored when users visit websites.

How to fix HTTP image upload errors in WordPress (simple) How to fix HTTP image upload errors in WordPress (simple) May 12, 2025 pm 09:03 PM

Do you need to fix HTTP image upload errors in WordPress? This error can be particularly frustrating when you create content in WordPress. This usually happens when you upload images or other files to your CMS using the built-in WordPress media library. In this article, we will show you how to easily fix HTTP image upload errors in WordPress. What is the reason for HTTP errors during WordPress media uploading? When you try to upload files to Wo using WordPress media uploader

How to register a wordpress account How to register a wordpress account Apr 20, 2025 am 11:45 AM

To create an account on WordPress, simply visit its website, select the registration option, fill in the registration form, and verify your email address. Other ways to register include using a Google account or Apple ID. The benefits of signing up include creating a website, gaining features, joining the community, and gaining support.

See all articles