gde_get_short_url

Shorten ("mask") the URL to the embedded file.

Description

(string) gde_get_short_url( $u ); 

Returns (string)

Short url response from API call, or false on error

Parameters (1)

0. $u
The u.

Usage

  1. if ( !function_exists( 'gde_get_short_url' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/functions.php'; 
  3.  
  4. // The u. 
  5. $u = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = gde_get_short_url($u); 
  9.  

Defined (1)

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

/functions.php  
  1. function gde_get_short_url( $u ) { 
  2. $u = urlencode( $u ); 
  3. $service[] = "http://tinyurl.com/api-create.php?url=" . $u; 
  4. $service[] = "http://is.gd/create.php?format=simple&url=" . $u; 
  5.  
  6. foreach ( $service as $url ) { 
  7. $passed = false; 
  8. $response = wp_remote_get( $url ); 
  9. if ( is_wp_error( $response ) || empty ( $response['body'] ) ) { 
  10. continue; 
  11. } else { 
  12. // check for rate limit exceeded or othererrorresponse 
  13. if ( ! gde_valid_link( $response['body'] ) ) { 
  14. continue; 
  15. } else { 
  16. $passed = true; 
  17. break; 
  18.  
  19. if ( $passed ) { 
  20. return $response['body']; 
  21. } else { 
  22. // can't shorten - return original URL 
  23. gde_dx_log("Shorten URL failed: " . urldecode( $u )); 
  24. return urldecode( $u );