Support » Plugin: Twitter Widget Pro » [Plugin: Twitter Widget Pro] Removing URL Shortening

Viewing 1 replies (of 1 total)
  • Plugin Author Aaron D. Campbell

    (@aaroncampbell)

    It’s all possible with the existing filters, but will take some code to do it and probably an API that unshortens URLs (there are quite a few of these). Here’s some code to get you started in the right direction:

    function range_unshorten_urls( $attributes ) {
    	if ( false === strpos( $attributes['href'], 'twitter.com' ) ) {
    		$request_url = add_query_arg( array( 'r' => $attributes['href'], 't' => 'json' ), 'http://api.unshort.me/' );
    		$url_info = json_decode( wp_remote_retrieve_body( wp_remote_get( $request_url ) ) );
    		if ( $url_info && ! empty( $url_info->resolvedURL ) )
    			$attributes['href'] = $url_info->resolvedURL;
    	}
    	return $attributes;
    }
    add_filter( 'widget_twitter_link_attributes', 'range_unshorten_urls' );

    That will expand the href of the link. You’ll need to do something similar using the ‘widget_twitter_link_text’ filter expand the text for the link as well. Then you’ll REALLY want to add some caching so you’re not processing all these links every single time. I recommend using the TLC Transients included with Twitter Widget Pro.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Twitter Widget Pro] Removing URL Shortening’ is closed to new replies.