Example #1
0
     * This would be much easier if we all spoke Esperanto (or Old Norse).
     *
     * @since   2.0
     */
    public function load_plugin_textdomain()
    {
        $languages = apply_filters('wpbitly_languages_dir', WPBITLY_DIR . '/languages/');
        $locale = apply_filters('plugin_locale', get_locale(), 'wp-bitly');
        $mofile = $languages . $locale . '.mo';
        if (file_exists($mofile)) {
            load_textdomain('wp-bitly', $mofile);
        } else {
            load_plugin_textdomain('wp-bitly', false, $languages);
        }
    }
}
/**
 * Call this in place of WP_Bitly::get_in()
 * It's shorthand.
 * Makes life easier.
 * In fact, the phpDocumentor block is bigger than the function itself.
 *
 * @return WP_Bitly
 */
function wpbitly()
{
    return WP_Bitly::get_in();
    // in.
}
wpbitly();
/**
 * 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;
}
Example #3
0
/**
 * 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;
}
 /**
  * Handles the display of the metabox.
  *
  * @since   2.0
  *
  * @param   object $post WordPress passed $post object
  * @param   array  $args Passed by our call to add_meta_box(), just the $shortlink in this case.
  */
 public function display_metabox($post, $args)
 {
     $wpbitly = wpbitly();
     $shortlink = $args['args'][0];
     // Look for a clicks response
     $url = sprintf(wpbitly_api('link/clicks'), $wpbitly->get_option('oauth_token'), $shortlink);
     $response = wpbitly_get($url);
     if (is_array($response)) {
         $clicks = $response['data']['link_clicks'];
     }
     // Look for referring domains metadata
     $url = sprintf(wpbitly_api('link/refer'), $wpbitly->get_option('oauth_token'), $shortlink);
     $response = wpbitly_get($url);
     if (is_array($response)) {
         $refer = $response['data']['referring_domains'];
     }
     echo '<label class="screen-reader-text" for="new-tag-post_tag">' . __('Bitly Statistics', 'wp-bitly') . '</label>';
     if (isset($clicks) && isset($refer)) {
         echo '<p>' . __('Global click through:', 'wp-bitly') . ' <strong>' . $clicks . '</strong></p>';
         if (!empty($refer)) {
             echo '<h4 style="padding-bottom: 3px; border-bottom: 4px solid #eee;">' . __('Your link was shared on', 'wp-bitly') . '</h4>';
             foreach ($refer as $domain) {
                 if (isset($domain['url'])) {
                     printf('<a href="%1$s" target="_blank" title="%2$s">%2$s</a> (%3$d)<br>', $domain['url'], $domain['domain'], $domain['clicks']);
                 } else {
                     printf('<strong>%1$s</strong> (%2$d)<br>', $domain['domain'], $domain['clicks']);
                 }
             }
         }
     } else {
         echo '<p class="error">' . __('There was a problem retrieving information about your link. There may be no statistics yet.', 'wp-bitly') . '</p>';
     }
 }