返回介绍

wp_safe_redirect()

发布于 2017-09-11 12:47:17 字数 2429 浏览 1110 评论 0 收藏 0

wp_safe_redirect( string $location,  int $status = 302 )

Performs a safe (local) redirect, using wp_redirect().


description

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.


参数

$location

(string) (Required) The path to redirect to.

$status

(int) (Optional) Status code to use.

Default value: 302


源代码

File: wp-includes/pluggable.php

function wp_safe_redirect($location, $status = 302) {

	// Need to look at the URL the way it will end up in wp_redirect()
	$location = wp_sanitize_redirect($location);

	/**
	 * Filters the redirect fallback URL for when the provided redirect is not safe (local).
	 *
	 * @since 4.3.0
	 *
	 * @param string $fallback_url The fallback URL to use by default.
	 * @param int    $status       The redirect status.
	 */
	$location = wp_validate_redirect( $location, apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status ) );

	wp_redirect($location, $status);
}

更新日志

Versiondescription
2.3.0Introduced.

相关函数

Uses

  • wp-includes/pluggable.php: wp_safe_redirect_fallback
  • wp-includes/pluggable.php: wp_sanitize_redirect()
  • wp-includes/pluggable.php: wp_validate_redirect()
  • wp-includes/pluggable.php: wp_redirect()
  • wp-includes/link-template.php: admin_url()
  • wp-includes/plugin.php: apply_filters()
  • Show 1 more use Hide more uses

Used By

  • wp-admin/includes/misc.php: set_screen_options()
  • wp-admin/custom-background.php: Custom_Background::take_action()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文