Friday 9 November 2012

Wordpress Twitter Widget Pro doesn't update - Heart Internet issues

The first problem here was with the Wordpress Plugin - Twitter Widger Pro not updating.  I eventually found the cause of this to be with Heart Internet.  Check here for the fix  Twitter Widget Pro Not Updating Fix for Heart Internet. 

Although this fix at first seemed to work fine I found that it would only work intermittently; and kept showing a 'No Tweets Available' message. 

The following code is probably a ugly hack; but to be fair at this point my experience of the Wordpress framework and logic is very basic.  However it does now work; so feel free to use.

OPEN twitter-widget-pro/wp-twitter-widget.php

FIND

if ( count( $tweets ) == 0 ) {


REPLACE this with the following IF statment


        if ( count( $tweets ) == 0 ) {
        global $wpdb;
    // here I'm going to check the database for any old results
//$tweet_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '%_transient_twp_%' " ) );
 $tweet_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->options WHERE option_name LIKE '%%_transient_twp_%%' ;" ) );
// echo"$tweet_count
";

    if($tweet_count==0){
        $widgetContent .= '
  • ' . __( 'No Tweets Available', $this->_slug ) . '
  • ';
    } else {
    $lasttweetrow = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name LIKE '%_transient_twp_%'
    ORDER BY option_id DESC
    LIMIT 1;");

    $options = $lasttweetrow->option_value;   
    $options_array = explode(';', $options);
    $tweetrow = $options_array[11];       
    $tweet_array = explode(':', $tweetrow);
    $tweet = $tweet_array[2];
    $tweet = str_replace("\"", "", $tweet);

    $tweetusernamerow = $options_array[34];       
    $tweetusername_array = explode(':', $tweetusernamerow);
    $tweetusername = $tweetusername_array[3];
    $tweetusername = str_replace("\"", "", $tweetusername);

    $tweetcreatedrow = $options_array[52];       
    $tweetcreated_array = explode(':', $tweetcreatedrow);
    $tweetcreated = $tweetcreated_array[3];
    $tweetcreated = str_replace("\"", "", $tweetcreated);




    $args['title'] = "Twitter: $tweetusername";

            $args['title'] = apply_filters( 'twitter-widget-title', $args['title'], $args );
            $args['title'] = "Twitter";
            $widgetContent .= $args['before_title'] . $args['title'] . $args['after_title'];
           

    $widgetContent .= "

  • $tweet



  • ";

        }

            }


    No comments: