wp_safe_redirect()获取一个安全的重定向链接

目录

描述

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

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 is to wp-admin on the siteurl instead. This prevents malicious redirects which redirect to another host, but only used in a few places.

wp_safe_redirect() 描述

用法

wp_safe_redirect() does not exit automatically and should almost always be followed by exit.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?phpwp_safe_redirect( $location, $status );exit;?>

wp_safe_redirect() 用法

参数

$location

(string) (必填)

默认值: None

$status

(integer) (可选)

默认值: 302

wp_safe_redirect() 参数

返回值

(void

Does not return anything

wp_safe_redirect() 返回值

历史

添加于 版本: 2.3

wp_safe_redirect() 历史

源文件

wp_safe_redirect() 函数的代码位于 wp-includes/pluggable.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Performs a safe (local) redirect, using wp_redirect().
 *
 * 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.
 *
 * @since 2.3.0
 */
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);

	/**
	 * Filter 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);
}
endif;

if ( !function_exists('wp_validate_redirect') ) :

wp_safe_redirect() 源文件

相关