WordPress.org

Forums

[resolved] [Plugin: WP to Twitter] Problem with WP 2.9, WP2T 1.5.6 & bit.ly API - Fix Noted (4 posts)

  1. dhvrm
    Member
    Posted 5 years ago #

    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!

    http://wordpress.org/extend/plugins/wp-to-twitter/

  2. dougvdotcom
    Member
    Posted 5 years ago #

    Also, it's possible this is a fix to the url_encode error someone else noted that is being caused by WP 2.9.

  3. Joe Dolson
    Member
    Posted 5 years ago #

    Thanks for tracking that down! I appreciate it. That's one *bizarre* bug, I must say, and I'm definitely optimistic that your thoroughness in identifying the issue will benefit others -- I have heard reports of this bug (or weirdness which could be this bug, rather) -- and have been a bit mystified.

    This function doesn't directly have to do with bit.ly shortening, except in that it impacts every use of any URL in the plugin...

    Thank you!

  4. leylap
    Member
    Posted 4 years ago #

    Can someone please tell me how to remove the TwitterAPI login box that keeps coming up on my site? It's driving people away! :-(

    Plus I don't have any plugins pointing to Twitter :-(

    Thank you!!

    http://www.motherhooddiaries.com

Topic Closed

This topic has been closed to new replies.

About this Topic