gde_valid_url

The Google Doc Embedder gde valid url function.

Description

gde_valid_url( $url, (string) $method = 'head', (int) $stop = 0 ); 

Parameters (3)

0. $url
The url.
1. $method — Optional. (string) => 'head'
The method.
2. $stop — Optional. (int)
The stop.

Usage

  1. if ( !function_exists( 'gde_valid_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/functions.php'; 
  3.  
  4. // The url. 
  5. $url = null; 
  6.  
  7. // The method. 
  8. $method = 'head'; 
  9.  
  10. // The stop. 
  11. $stop = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = gde_valid_url($url, $method, $stop); 
  15.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function gde_valid_url( $url, $method = "head", $stop = 0 ) { 
  2.  
  3. if ( $method == "head" ) { 
  4. $result = wp_remote_head( $url ); 
  5. } elseif ( $stop == 0 ) { 
  6. $stop++; 
  7. $result = wp_remote_get( $url ); 
  8. } else { 
  9. gde_dx_log("can't get URL to test; skipping"); 
  10. return false; 
  11.  
  12. if ( is_array( $result ) ) { 
  13. $code = $result['response']['code']; 
  14. if ( ! empty( $code ) && ( $code == "301" || $code == "302" ) ) { 
  15. // HEADrequestsdon't redirect. Probably a file/directory with spaces in it... 
  16. return gde_valid_url( $url, 'get', $stop ); 
  17. } else { 
  18. // capture file size if determined 
  19. if ( isset( $result['headers']['content-length'] ) ) { 
  20. $result['response']['fsize'] = $result['headers']['content-length']; 
  21. } else { 
  22. $result['response']['fsize'] = ''; 
  23. return $result['response']; 
  24. } elseif ( is_wp_error( $result ) ) { 
  25. // unable to get head 
  26. $error = $result->get_error_message(); 
  27. gde_dx_log("bypassing URL check; cant validate URL $url: $error"); 
  28. return false; 
  29. } else { 
  30. gde_dx_log("cant determine URL validity; skipping"); 
  31. return false;