wp_validate_redirect [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Validates a URL for use in a 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 $default supplied
Source
<?php
function wp_validate_redirect($location, $default = '') {
// browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
if ( substr($location, 0, 2) == '//' )
$location = 'http:' . $location;
// In php 5 parse_url may fail if the URL query part contains http://, bug #38143
$test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;
$lp = parse_url($test);
// Give up if malformed URL
if ( false === $lp )
return $default;
// Allow only http and https schemes. No data:, etc.
if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) )
return $default;
// Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
if ( isset($lp['scheme']) && !isset($lp['host']) )
return $default;
$wpp = parse_url(home_url());
$allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');
if ( isset($lp['host']) && ( !in_array($lp['host'], $allowed_hosts) && $lp['host'] != strtolower($wpp['host'])) )
$location = $default;
return $location;
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- Function Reference/wp validate redirect « WordPress Codex
Description. Validates a URL for use in a redirect. Checks whether the $location is using an allowed host, if it has an absolute path. A plugin can therefore set or ...
codex.wordpress.org - Docs for page pluggable.php
return: Does not return anything; since: 2.3; uses: wp_validate_redirect() - To validate the redirect is to an allowed host. void wp_safe_redirect ( $location ...
phpdoc.wordpress.org - wp_validate_redirect | A HitchHackers guide through WordPress
Feb 12, 2011 ... function wp_validate_redirect($location, $default = '') { // browsers will assume ' http' is your protocol, and will obey a redirect to a URL starting ...
hitchhackerguide.com - wp_validate_redirect:WordPress私的マニュアル
2011年11月2日 ... wp_validate_redirect - URLがリダイレクト先として有効か調べる.
elearn.jp