/** * Create a bitly url if one doesnt already exist for the passed post id * * @param int $post_id * * @return mixed */ function generate_bitly_url($post_id) { extract($this->options); $bitly_url = bitly_get_url($post_id); if (empty($bitly_url)) { // need to test this if the post is a time_slide $params = http_build_query(array('login' => $api_login, 'apiKey' => $api_key, 'longUrl' => get_permalink($post_id), 'format' => 'json')); $rest_url = 'https://api-ssl.bitly.com/v3/shorten?' . $params; $response = wp_remote_get($rest_url); // if we get a valid response, save the url as meta data for this post if (!is_wp_error($response)) { $json = json_decode(wp_remote_retrieve_body($response)); if (isset($json->data->url)) { update_post_meta($post_id, 'bitly_url', $json->data->url); return $json->data->url; } } } return false; }
/** * Create a bitly url if one doesnt already exist for the passed post id * * @param int $post_id * * @return mixed */ function generate_bitly_url($post_id) { extract($this->options); $bitly_url = bitly_get_url($post_id); if (empty($bitly_url)) { $permalink = get_permalink($post_id); $shortlink = $this->shortlink_for_url($permalink, $post_id); if ($shortlink) { update_post_meta($post_id, 'bitly_url', $shortlink); } } return false; }