[Plugin: WP to Twitter] Problem with WP 2.9, WP2T 1.5.6 & bit.ly API – Fix Noted
-
First, my extensive thanks for an excellent plugin.
WP 2.9 seems to have broken the bit.ly API shortening, at least in my install.
After some investigation, I tracked it down to the external_or_permalink function in wp-to-twitter.php. The function, out of the box, is:
// Function checks for an alternate URL to be tweeted. Contribution by Bill Berry. function external_or_permalink( $post_ID ) { $wtb_extlink_custom_field = get_option('jd_twit_custom_url'); $perma_link = get_permalink( $post_ID ); $ex_link = get_post_meta($post_ID, $wtb_extlink_custom_field, true); return ( $ex_link ) ? $ex_link : $perma_link; }
I have not specified a custom URL to use instead of the post’s permalink (i.e., the value of ‘jd_twit_custom_url’ in my wp_options table is NULL, a fact I know because I ran an update query to ensure it was NULL.)
As one would expect, the value of $wtb_extlink_custom_field is an empty string for me (verified by a var_dump called inside a die).
However, when Line 3 of the function sets the value of $ex_link via get_post_meta, rather than setting an empty string (or even just a string, as the documentation says it should return), I get an array of completely unassociated values from an entirely different plugin’s options (a fact I verified via var_dump / die).
This causes external_or_permalink to return a null as the value of $thispostlink in its calling function (in my case, jd_twit), which is in turn passed to jd_shorten_link, which in turn fails because the longUrl parameter passed to the bit.ly API is not present (a fact determined, again, by calling var_dump and die on $decoded in jd_shorten_link).
My fix to this problem was to add an if statement in the external_or_permalink function, checking if $wtb_extlink_custom_field is an empty string before setting the value of $ex_link:
// Function checks for an alternate URL to be tweeted. Contribution by Bill Berry. function external_or_permalink( $post_ID ) { $wtb_extlink_custom_field = get_option('jd_twit_custom_url'); $perma_link = get_permalink( $post_ID ); if($wtb_extlink_custom_field != '') { $ex_link = get_post_meta($post_ID, $wtb_extlink_custom_field, true); } return ( $ex_link ) ? $ex_link : $perma_link; }
Again, it is possible this is a problem specific to my install, or a problem specific to the other plug-in that provided its information in WP to Twitter’s stead.
But everything was working fine before the WP 2.9 upgrade and the function at issue appears to be a WP core function.
Not sure if this is a problem for others, but thought I should pass it along.
Again, a thousand thanks for a great plugin!
- The topic ‘[Plugin: WP to Twitter] Problem with WP 2.9, WP2T 1.5.6 & bit.ly API – Fix Noted’ is closed to new replies.