/** * Short circuits the `pre_get_shortlink` filter. * * @since 0.1 * * @param bool $shortlink False is passed in by default. * @param int $post_id Current $post->ID, or 0 for the current post. * * @return string A shortlink */ function wpbitly_get_shortlink($original, $post_id) { $wpbitly = wpbitly(); // Verify this is a post we want to generate short links for if (!in_array(get_post_type($post_id), $wpbitly->get_option('post_types'))) { return $original; } if (0 == $post_id) { $post = get_post(); $post_id = $post->ID; } $shortlink = get_post_meta($post_id, '_wpbitly', true); if (!$shortlink) { $shortlink = wpbitly_generate_shortlink($post_id); } return $shortlink ? $shortlink : $original; }
/** * Short circuits the `pre_get_shortlink` filter. * * @since 0.1 * * @param bool $shortlink False is passed in by default. * @param int $post_id Current $post->ID, or 0 for the current post. * * @return string A shortlink */ function wpbitly_get_shortlink($original, $post_id) { $wpbitly = wpbitly(); // Verify this is a post we want to generate short links for if (!in_array(get_post_type($post_id), $wpbitly->get_option('post_types'))) { return $original; } if (0 == $post_id) { $post = get_post(); $post_id = $post->ID; } $shortlink = get_post_meta($post_id, '_wpbitly', true); if (!$shortlink) { // EDIT: limit creating bitlinks by post date: $limit = $wpbitly->get_option('limit'); $post_date = strtotime(get_the_date('l, F j, Y', $post_id)); // If the limit is set and the post date is less than that many days ago, generate bitlink: if ($limit > 0 && time() - $post_date < 86400 * $limit) { $shortlink = wpbitly_generate_shortlink($post_id); } } return $shortlink ? $shortlink : $original; }