/** * Wrapper for mashsb_get_shorturl_singular() * * @param string $url * @return string */ function mashsb_get_shorturl($url) { if (!empty($url)) { $url = mashsb_get_shorturl_singular($url); } else { $url = ""; } return $url; }
function mashsb_get_shortened_url($url) { global $mashsb_options; // Return empty if (empty($url)) { return ""; } // Use native WP Shortlinks if ($mashsb_options['mashsu_methods'] === 'wpshortlinks') { return wp_get_shortlink(); } // If is_singular post store shorturl in custom post fields // and return it from there so user has the power to change values // on his own from the post edit page and the custom fields editor if (is_singular()) { return mashsb_get_shorturl_singular($url); } // Force cache rebuild if (mashsb_force_cache_refresh()) { MASHSB()->logger->info('mashsb_get_shorturl() -> refresh cache'); // bitly shortlink if (isset($mashsb_options['mashsu_methods']) && $mashsb_options['mashsu_methods'] === 'bitly') { $shorturl = mashsb_get_bitly_link($url); MASHSB()->logger->info('create shorturl: ' . $url . ' ' . $shorturl); } // Google shortlink if (isset($mashsb_options['mashsu_methods']) && $mashsb_options['mashsu_methods'] === 'google') { $shorturl = mashsb_get_google_link($url); } // Get expiration time $expiration = mashsb_get_expiration(); set_transient('mash_url_' . md5($url), $shorturl, $expiration); } else { $shorturl = get_transient('mash_url_' . md5($url)); } if (!empty($shorturl)) { return $shorturl; } else { return $url; } }