How to modify the list of domain names allowed by wp_safe_direct(), and how to modify real name authentication by King Glory

1 year ago (2023-12-05) Chief Editor
7 minutes
two hundred and ninety-one
zero

This problem will hardly be considered by anyone. After all, the number of people who use this function may be relatively small. So what is this function for?

Introduction to wp_safe_direct() function

Function Usage wp_safe_redirect( string $location, int $status = 302, string $x_redirect_by = WordPress ) Performs a safe (local) redirect, using wp_redirect(). Function introduction

Checks whether the $location is using an allowed host, if it has an absolute path. A plugin can therefore set or remove allowed host(s) to or from the list. If the host is not allowed, then the redirect defaults to wp-admin on the siteurl instead. This prevents malicious redirects which redirect to another host, but only used in a few places. Note: wp_safe_redirect() does not exit automatically, and should almost always be followed by a call to exit;: wp_safe_redirect( $url ); exit; Exiting can also be selectively manipulated by using wp_safe_redirect() as a conditional

in conjunction with the ‘wp_redirect’ and ‘wp_redirect_location’ filters:if ( wp_safe_redirect( $url ) ) { exit; }
Parameter introduction $location

(string)

(Required)

The path or URL to redirect to. $status

(int)

(Optional)

HTTP response status code to use. Default 302 (Moved Temporarily). Default value: 302 $x_redirect_by

(string)

(Optional)

The application doing the redirect. Default value: WordPress Return value

(bool) False if the redirect was cancelled, true otherwise.

Through the above introduction, we basically know that this function is used to redirect, but in addition to this function, the wp_redirect() function also has the redirect function. What is the difference between the two?

The following is the wp_safe_direct() source code:

Through the source code, we can see that the function is processed by the wp_validate_redirect() function and finally output through the wp_redirect() function. The key is what the wp_validate_redirect() function does:

Through the source code of this function, we know that this function passes through a filter, and this filter is the key to the realization of this function: allowed_redirect_hosts

A brief introduction to allowed_redirect_hosts:

Introduction to the allowed_redirect_hosts function

Function Usage apply_filters( allowed_redirect_hosts, string[] $hosts, string $host ) Filters the list of allowed hosts to redirect to. Function introduction No data temporarily Parameter introduction $hosts

(string[])

An array of allowed host names. $host

(string)

The host name of the redirect destination; empty string if not set. Return value No data temporarily

The simple understanding is to provide an array. The domain names in these arrays can be considered safe and can be skipped. Otherwise, you can directly jump to the/wp admin interface. This is also One of the biggest differences between wp_redirect() and wp_safe_direct() is that the latter provides a set of safe jump address ranges, while the former ignores them

After understanding the allowed_redirect_hosts filter, what we need to do is to combine a security address array provided by ourselves with the array provided by the system and return:

function my_allowed_redirect_hosts( $hosts ) {

$my_hosts = array(

blog.example.com,

codex.example.com,

);

return array_merge( $hosts, $my_hosts );

};

add_filter( allowed_redirect_hosts, my_allowed_redirect_hosts );

The above examples are official and are the most standard function codes. You only need to modify blog. example. com and code. example. com to achieve the goal, and then add them to function. php.

The above is all about this article. If you are interested in it, you can practice it yourself. Copying and pasting can't help you. Understand the principle. Even if you can only get 1%, you will earn money.

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/1873.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

What technologies have been applied and developed in the field of new media, and the application of new technologies in media

In the field of new media, many technologies have been applied and developed. These include: cloud computing: cloud computing technology enables new media companies to develop and deploy applications more quickly, and can dynamically adjust resources according to needs. Big data: New media companies can use big data technology to analyze massive user data, understand user preferences, behavior habits and other information
nine hundred and seventy-one
one
1 year ago (2024-02-20)

WMS warehouse management system, promoting the transformation of warehousing from extensive to fine management, WMS warehouse management

Warehousing is extremely important for the manufacturing industry and is an important guarantee for the survival and development of manufacturing enterprises. However, with the expansion of manufacturing enterprises' business, the traditional warehouse management has been unable to respond to business changes quickly. The extensive management mode not only makes the warehouse operation not smooth, but also increases the storage cost. Therefore, it is necessary for manufacturing enterprises to deploy a WMS warehouse management system
eight hundred and forty-eight
one
1 year ago (2024-02-20)

How to select MES system? Main contents of MES production management

Original title: How to select MES system? The main content of MES production management Production and manufacturing activities are the core activities of manufacturing enterprises. As the entity unit of manufacturing activities, planning objectives and the realization of enterprise value, workshop management is the focus of enterprise management. With the rapid development of manufacturing industry, MES is the focus and current hot spot of manufacturing enterprise information automation system
nine hundred and sixty-four
zero
1 year ago (2024-02-20)

The WeChat management system can manage the information content of WeChat more effectively. Let's manage the data of WeChat here

Original title: WeChat management system manages the information content of WeChat more effectively. Many enterprises will assign work to WeChat, because no one wants their personal WeChat to mix work and other related knowledge, but someone will always use the company's loopholes to do something harmful to the company's interests. Don't think such things are rare. I learned about a media financing company in Shenzhen. They have 3
seven hundred and seventy-seven
zero
1 year ago (2024-02-19)

Student electronic file management system, three-dimensional communication space of "home", "school" and "community", and school electronic files

In the era of big data, in the process of recording the growth of students, the school reexamines the management of student files, moves with the times, and promotes the reform of student growth files with new thinking. "Electronic files of primary and secondary school students' growth records" have been gradually introduced into educational management, and show vigorous vitality. Student file management system is an indispensable part of the school, its content for the school
five hundred and seventy-one
zero
1 year ago (2024-02-19)

Ruizhe Information: Select Sitecore? Or... just six steps to choose a content management system, Ruizhe Information Technology Service Co., Ltd

The content management system (CMS) is an important part of the success of website construction. At present, the content management system on the network is relatively complex. It is not easy to find a good content management system that is very suitable for the current digital marketing environment. Before we compare the functionality, operation, scalability, security and other specific performance of the major CMS systems, we need to achieve
three hundred and forty-three
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: