本文整理汇总了PHP中wp_http_validate_url函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_http_validate_url函数的具体用法?PHP wp_http_validate_url怎么用?PHP wp_http_validate_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_http_validate_url函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pingback_ping_source_uri
/**
* Default filter attached to pingback_ping_source_uri to validate the pingback's Source URI
*
* @since 3.5.1
* @see wp_http_validate_url()
*
* @param string $source_uri
* @return string
*/
function pingback_ping_source_uri($source_uri)
{
return (string) wp_http_validate_url($source_uri);
}
示例2: request
//.........这里部分代码省略.........
*
* @param array $r An array of HTTP request arguments.
* @param string $url The request URL.
*/
$r = apply_filters('http_request_args', $r, $url);
// The transports decrement this, store a copy of the original value for loop purposes.
if (!isset($r['_redirection'])) {
$r['_redirection'] = $r['redirection'];
}
/**
* Filter whether to preempt an HTTP request's return value.
*
* Returning a non-false value from the filter will short-circuit the HTTP request and return
* early with that value. A filter should return either:
*
* - An array containing 'headers', 'body', 'response', 'cookies', and 'filename' elements
* - A WP_Error instance
* - boolean false (to avoid short-circuiting the response)
*
* Returning any other value may result in unexpected behaviour.
*
* @since 2.9.0
*
* @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false.
* @param array $r HTTP request arguments.
* @param string $url The request URL.
*/
$pre = apply_filters('pre_http_request', false, $r, $url);
if (false !== $pre) {
return $pre;
}
if (function_exists('wp_kses_bad_protocol')) {
if ($r['reject_unsafe_urls']) {
$url = wp_http_validate_url($url);
}
if ($url) {
$url = wp_kses_bad_protocol($url, array('http', 'https', 'ssl'));
}
}
$arrURL = @parse_url($url);
if (empty($url) || empty($arrURL['scheme'])) {
return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
}
if ($this->block_request($url)) {
return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
}
/*
* Determine if this is a https call and pass that on to the transport functions
* so that we can blacklist the transports that do not support ssl verification
*/
$r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
// Determine if this request is to OUR install of WordPress.
$homeURL = parse_url(get_bloginfo('url'));
$r['local'] = 'localhost' == $arrURL['host'] || isset($homeURL['host']) && $homeURL['host'] == $arrURL['host'];
unset($homeURL);
/*
* If we are streaming to a file but no filename was given drop it in the WP temp dir
* and pick its name using the basename of the $url.
*/
if ($r['stream'] && empty($r['filename'])) {
$r['filename'] = get_temp_dir() . wp_unique_filename(get_temp_dir(), basename($url));
}
/*
* Force some settings if we are streaming to a file and check for existence and perms
* of destination directory.
*/
示例3: request
//.........这里部分代码省略.........
*
* @param array $r An array of HTTP request arguments.
* @param string $url The request URL.
*/
$r = apply_filters('http_request_args', $r, $url);
// The transports decrement this, store a copy of the original value for loop purposes.
if (!isset($r['_redirection'])) {
$r['_redirection'] = $r['redirection'];
}
/**
* Filters whether to preempt an HTTP request's return value.
*
* Returning a non-false value from the filter will short-circuit the HTTP request and return
* early with that value. A filter should return either:
*
* - An array containing 'headers', 'body', 'response', 'cookies', and 'filename' elements
* - A WP_Error instance
* - boolean false (to avoid short-circuiting the response)
*
* Returning any other value may result in unexpected behaviour.
*
* @since 2.9.0
*
* @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false.
* @param array $r HTTP request arguments.
* @param string $url The request URL.
*/
$pre = apply_filters('pre_http_request', false, $r, $url);
if (false !== $pre) {
return $pre;
}
if (function_exists('wp_kses_bad_protocol')) {
if ($r['reject_unsafe_urls']) {
$url = wp_http_validate_url($url);
}
if ($url) {
$url = wp_kses_bad_protocol($url, array('http', 'https', 'ssl'));
}
}
$arrURL = @parse_url($url);
if (empty($url) || empty($arrURL['scheme'])) {
return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
}
if ($this->block_request($url)) {
return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
}
// If we are streaming to a file but no filename was given drop it in the WP temp dir
// and pick its name using the basename of the $url
if ($r['stream']) {
if (empty($r['filename'])) {
$r['filename'] = get_temp_dir() . basename($url);
}
// Force some settings if we are streaming to a file and check for existence and perms of destination directory
$r['blocking'] = true;
if (!wp_is_writable(dirname($r['filename']))) {
return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.'));
}
}
if (is_null($r['headers'])) {
$r['headers'] = array();
}
// WP allows passing in headers as a string, weirdly.
if (!is_array($r['headers'])) {
$processedHeaders = WP_Http::processHeaders($r['headers']);
$r['headers'] = $processedHeaders['headers'];
}
示例4: handle_callback_redirect
/**
* Handle redirecting the user after authorization
*
* @param string $verifier Verification code
* @return null|WP_Error Null on success, error otherwise
*/
public function handle_callback_redirect($verifier)
{
if (!empty($this->token['callback']) && $this->token['callback'] === 'oob') {
return apply_filters('json_oauth1_handle_callback', null, $this->token);
}
if (empty($this->token['callback'])) {
// No callback registered, display verification code to the user
login_header(__('Access Token'));
echo '<p>' . sprintf(__('Your verification token is <code>%s</code>'), $verifier) . '</p>';
login_footer();
return null;
}
$callback = $this->token['callback'];
// Ensure the URL is safe to access
// wp_http_validate_url is overly restrictive for desktop applications which might use
// 127.0.0.1:xx for the callback. Add hook that allows localhost and check scheme/host of URL.
$filtered_callback = parse_url($callback);
$filtered_callback = $filtered_callback['scheme'] . '://' . $filtered_callback['host'];
add_filter('http_request_host_is_external', array('WP_JSON_Authentication_OAuth1_Authorize', 'http_request_allow_external'));
$filtered_callback = wp_http_validate_url($filtered_callback);
remove_filter('http_request_host_is_external', array('WP_JSON_Authentication_OAuth1_Authorize', 'http_request_allow_external'));
if (empty($filtered_callback)) {
return new WP_Error('json_oauth1_invalid_callback', __('The callback URL is invalid'), array('status' => 400));
}
$args = array('oauth_token' => $this->token['key'], 'oauth_verifier' => $verifier, 'wp_scope' => '*');
$args = apply_filters('json_oauth1_callback_args', $args, $token);
$args = urlencode_deep($args);
$callback = add_query_arg($args, $callback);
wp_redirect($callback);
return null;
}
示例5: handle_callback_redirect
/**
* Handle redirecting the user after authorization
*
* @param string $verifier Verification code
* @return null|WP_Error Null on success, error otherwise
*/
public function handle_callback_redirect($verifier)
{
if (!empty($this->token['callback']) && $this->token['callback'] === 'oob') {
return apply_filters('json_oauth1_handle_callback', null, $this->token);
}
if (empty($this->token['callback'])) {
// No callback registered, display verification code to the user
login_header(__('Access Token'));
echo '<p>' . sprintf(__('Your verification token is <code>%s</code>'), $verifier) . '</p>';
login_footer();
return null;
}
$callback = $this->token['callback'];
// Ensure the URL is safe to access
$callback = wp_http_validate_url($callback);
if (empty($callback)) {
return new WP_Error('json_oauth1_invalid_callback', __('The callback URL is invalid'), array('status' => 400));
}
$args = array('oauth_token' => $this->token['key'], 'oauth_verifier' => $verifier, 'wp_scope' => '*');
$args = apply_filters('json_oauth1_callback_args', $args, $this->token);
$args = urlencode_deep($args);
$callback = add_query_arg($args, $callback);
wp_redirect($callback);
return null;
}
示例6: image_exist
public function image_exist()
{
if (false == $this->image() || empty($this->img_src)) {
return false;
}
$result = array();
if (false == $this->is_local_attachment()) {
if (false == wp_http_validate_url($this->img_src)) {
return false;
}
$result['external'] = $this->img_src;
return $result;
}
$this->img_src = preg_replace('/-\\d+x\\d+(?=\\.(jpg|jpeg|png|gif)$)/i', '', $this->img_src);
$img_filename = str_replace($this->upurl . '/', '', $this->img_src);
$img_path = $this->updir . '/' . $img_filename;
if (file_exists($img_path) && false != getimagesize($img_path)) {
if (5 > getimagesize($img_path)[0] || 5 > getimagesize($img_path)[1]) {
$result['toosmall'] = array('filename' => $img_filename, 'path' => $img_path);
} else {
$result['exists'] = array('filename' => $img_filename, 'path' => $img_path, 'src' => $this->img_src);
}
} else {
$result['noexists'] = array('src' => $this->img_src);
}
return $result;
}
示例7: queue_purge_url
/**
* PURGE a single URL
*
* @param string $url The specific URL to purge the cache for
*
* @return bool True on success
*/
public function queue_purge_url($url)
{
$url = esc_url_raw($url);
$url = wp_http_validate_url($url);
if (false === $url) {
return false;
}
$this->purge_urls[] = $url;
return true;
}