/** * Create widget frontend * * @param array $args * @param array $instance */ public function widget($args, $instance) { global $cb; $consumer_key = $instance['consumer_key']; $consumer_secret = $instance['consumer_secret']; $access_token = $instance['access_token']; $access_secret = $instance['access_secret']; Codebird\Codebird::setConsumerKey($consumer_key, $consumer_secret); $cb = Codebird\Codebird::getInstance(); $cb->setToken($access_token, $access_secret); $tweets = $this->get_tweets($args['widget_id'], $instance); if (!empty($tweets['tweets']) and empty($tweets['tweets']->errors)) { $title = apply_filters('widget_title', $instance['title']); // before and after widget arguments are defined by themes echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . $title . $args['after_title']; } $user = current($tweets['tweets']); $user = $user->user; ?> <div class="twitter-profile"> <img src="<?php echo $user->profile_image_url; ?> "> <h4><a class="heading-text-color" href="http://twitter.com/<?php echo $user->screen_name; ?> "><?php echo $user->screen_name; ?> </a></h4> <div class="description content"><?php echo $user->description; ?> </div> </div> <ul class="twitter-timeline"> <?php foreach ($tweets['tweets'] as $tweet) { if (is_object($tweet)) { $tweet_text = htmlentities($tweet->text, ENT_QUOTES); ?> <li> <span class="content"><?php echo $tweet_text; ?> </span> <div class="date"><?php echo human_time_diff(strtotime($tweet->created_at)); ?> ago </div> </li> <?php } } ?> </ul> <?php echo $args['after_widget']; } }