gde_valid_url
The Google Doc Embedder gde valid url function.
Description
Parameters (3)
- 0. $url
- The url.
- 1. $method — Optional. (string) =>
'head'
- The method.
- 2. $stop — Optional. (int)
- The stop.
Usage
if ( !function_exists( 'gde_valid_url' ) ) { require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/functions.php'; } // The url. $url = null; // The method. $method = 'head'; // The stop. $stop = -1; // NOTICE! Understand what this does before running. $result = gde_valid_url($url, $method, $stop);
Defined (1)
The function is defined in the following location(s).
- /functions.php
- function gde_valid_url( $url, $method = "head", $stop = 0 ) {
- if ( $method == "head" ) {
- $result = wp_remote_head( $url );
- } elseif ( $stop == 0 ) {
- $stop++;
- $result = wp_remote_get( $url );
- } else {
- gde_dx_log("can't get URL to test; skipping");
- return false;
- }
- if ( is_array( $result ) ) {
- $code = $result['response']['code'];
- if ( ! empty( $code ) && ( $code == "301" || $code == "302" ) ) {
- // HEADrequestsdon't redirect. Probably a file/directory with spaces in it...
- return gde_valid_url( $url, 'get', $stop );
- } else {
- // capture file size if determined
- if ( isset( $result['headers']['content-length'] ) ) {
- $result['response']['fsize'] = $result['headers']['content-length'];
- } else {
- $result['response']['fsize'] = '';
- }
- return $result['response'];
- }
- } elseif ( is_wp_error( $result ) ) {
- // unable to get head
- $error = $result->get_error_message();
- gde_dx_log("bypassing URL check; cant validate URL $url: $error");
- return false;
- } else {
- gde_dx_log("cant determine URL validity; skipping");
- return false;
- }
- }