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
if ( !function_exists( 'gde_get_short_url' ) ) { require_once ABSPATH . PLUGINDIR . 'google-doc-embedder/functions.php'; } // The u. $u = null; // NOTICE! Understand what this does before running. $result = gde_get_short_url($u);
Defined (1)
The function is defined in the following location(s).
- /functions.php
- function gde_get_short_url( $u ) {
- $u = urlencode( $u );
- $service[] = "http://tinyurl.com/api-create.php?url=" . $u;
- $service[] = "http://is.gd/create.php?format=simple&url=" . $u;
- foreach ( $service as $url ) {
- $passed = false;
- $response = wp_remote_get( $url );
- if ( is_wp_error( $response ) || empty ( $response['body'] ) ) {
- continue;
- } else {
- // check for rate limit exceeded or othererrorresponse
- if ( ! gde_valid_link( $response['body'] ) ) {
- continue;
- } else {
- $passed = true;
- break;
- }
- }
- }
- if ( $passed ) {
- return $response['body'];
- } else {
- // can't shorten - return original URL
- gde_dx_log("Shorten URL failed: " . urldecode( $u ));
- return urldecode( $u );
- }
- }