• Home
  • Docs
  • About
  • Resume
  • Services
    • Testimonials
  • Contact
Humbug
Bah! Humbug!
Home 2010 Patch for YOURLS: Wordpress to Twitter – Filter Hook to Control the URL that is Fed into Yourls

Patch for YOURLS: WordPress to Twitter – Filter Hook to Control the URL that is Fed into Yourls

  • Leave a comment
  • Tweet
Pratik Sinha | July 18, 2010

Yourls: WordPress to Twitter is a wonderful plugin which bridges yourls with wordpress. In addition to yourls statistics, I also wanted to track the clicks on the shortened link using Google Analytics. This requires addition of Google Analytics tags to the permalink URL which then gets shortened by yourls. Hence I modified the plugin code so that the URL that is fed into yourls can be modified the wordpress way – using a filter hook. Here’s the patch that I made.

diff -aurN yourls-wordpress-to-twitter/inc/core.php /home/pratikmsinha/humbug.in/wp-content/plugins/yourls-wordpress-to-twitter/inc/core.php
--- yourls-wordpress-to-twitter/inc/core.php  2010-03-09 12:37:14.000000000 -0800
+++ /home/pratikmsinha/humbug.in/wp-content/plugins/yourls-wordpress-to-twitter/inc/core.php  2010-07-01 18:23:39.000000000 -0700
@@ -61,7 +61,8 @@
  global $wp_ozh_yourls;

  $post_id = $post->ID;
- $url = get_permalink( $post_id );
+ //$url = get_permalink( $post_id );
+ $url = apply_filters('yourls_blog_post_url', get_permalink($post_id));

  if ( $post->post_type != 'post' && $post->post_type != 'page' )
    return;
@@ -71,7 +72,8 @@
    return;

  $title = get_the_title($post_id);
- $url = get_permalink ($post_id);
+ //$url = get_permalink ($post_id);
+ $url = apply_filters('yourls_blog_post_url', get_permalink($post_id));
  $short = wp_ozh_yourls_get_new_short_url( $url );

  // Tweet short URL ?
diff -aurN yourls-wordpress-to-twitter/plugin.php /home/pratikmsinha/humbug.in/wp-content/plugins/yourls-wordpress-to-twitter/plugin.php
--- yourls-wordpress-to-twitter/plugin.php  2010-03-09 12:37:14.000000000 -0800
+++ /home/pratikmsinha/humbug.in/wp-content/plugins/yourls-wordpress-to-twitter/plugin.php  2010-07-01 18:26:14.000000000 -0700
@@ -68,7 +68,8 @@
  if ( !$short && !is_preview() ) {
    // short URL never was not created before, let's get it now
    require_once(dirname(__FILE__).'/inc/core.php');
-   $short = wp_ozh_yourls_get_new_short_url( get_permalink($id), $id );
+   $url = apply_filters('yourls_blog_post_url', get_permalink($id));
+   $short = wp_ozh_yourls_get_new_short_url( $url, $id );
  }

  return $short;

To use the above patch, copy-paste the code into a file, lets say yourls.patch. Go into the yourls plugin directory (wp-content/plugins/yourls-wordpress-to-twitter/) and execute the following command.

patch -p1 < yourls.patch

Do ensure that you use the correct path to yourls.patch.

Posted in Code-Snippets | Tagged google-analytics, wordpress, wordpress-filter, yourls | Leave a response

  • Tweet
Logging In...

Profile cancel

Sign in with Twitter Sign in with Facebook
or

Not published

 

« Previous Next »

Search

Recommend on Google
  • RSS
Follow @free_thinker

Get the latest posts delivered straight to your inbox.

Categories

  • Bookmarks
  • Code-Snippets
  • Guides
  • Info
  • Software
  • Testimonials
  • Tips-N-Tricks
  • Updates

Recently Popular

  • Make English the Default Language for Google Chrome Search
  • Parse Simple XML Files using Bash – Extract Name Value Pairs and Attributes
  • Kill/Quit and Restart Plasma on KDE
  • Bash Tricks: Split / Cut a String with Multi Character Delimiters
  • Enable SPDY in Firefox 11 on Ubuntu 12.04 beta
  • Utility to Send Commands or Data to Other Terminals (tty/pts)
  • A Sample Loop in XSL, Alternative for While, For Loops
  • Bash Tricks: Create variables dynamically using some eval magic
  • Kickstrap – CSS Framework: Enhancements for Bootstrap
  • WordPress Plugin: Cleaner WordPress Editor – Trying To Make WordPress Editing a Pleasure

Latest Tweets

  • 2 unexploded bombs found under Ho Chi Minh City house - Approximately 800,000 tons of bombs and mines still present humbug.in/z/9i #fb 4 weeks ago
  • 3 Vietnamese bloggers charged over their writing | Fox News humbug.in/z/9g #fb 1 month ago
  • Implement strong WiFi encryption the easy way with hostapd - Using WPA2-Personal with individual keys for each user humbug.in/z/9e 1 month ago
  • Soon, wonder vaccine that will kill 90% of cancers - Health - DNA humbug.in/z/9d 1 month ago
  • PHP like str_replace function in C: This post is part of a series of posts where I want to document a bunch of C f... humbug.in/z/9c 1 month ago

Services Offered

  • Embedded Linux Systems and Services
  • Gateway Routers (Frontend and Backend)
  • Free and Open Source Software Solutions
  • Network Monitoring Solutions
  • Device Driver Development


Mobile and Web Analytics

Recent Comments

  • Haakon Dahl commented on Make English the Default Language for Google Chrome Search
    (1 weeks ago)
  • pawan commented on Wordpress Error: The plugin generated 1 characters of unexpected output during activation
    (1 weeks ago)
  • simon commented on Detect Mobile Browser using Server Side Includes (SSI)
    (2 weeks ago)
  • hakatagroup commented on Twitter Weekly Updates between 2012-04-19 and 2012-04-25
    (3 weeks ago)

Tags

Address bar android awk bash C css custom post type debug Default Browser DNS dreamhost English Facebook firefox Google iphone JavaScript jquery KDE keyboard shortcuts Kubuntu Launchpad Linux Mozilla Firefox p2 page template pdf php plugin PPA python ruby ruby-on-rails Ruby1.9.2 Search Results SNMP theme tweets Twitter Ubuntu United States update-alternatives Vietnam wordpress xsl

Copyright © 2012 Humbug.

Powered by WordPress and Hybrid.