here's my scenario - i've got a widget that users enter their twitter name and the number of updates they want to display, then it puts the widget on the sidebar. however, 2 javascript files are required, and i'd like those to load in to the wp_footer, not into the sidebar (since they are from twitter, they're slow, and it stalls the rest of the sidebar + footer in loading).
so my question is there: since the 2 javascript files require variables collected from the widget to work, how do i inject variables from an active widget into the footer?
here's my widget:
class Tweets_Show extends WP_Widget {
function Tweets_Show() {
$widget_ops = array('classname' => 'tweets_show', 'description' => 'Shows latest 3 tweets, enter your username.' );
$this->WP_Widget('Tweets_Show', 'Show Tweets', $widget_ops);
}
function form($instance) {
$tw_username = esc_attr($instance['tw_username']);
$tw_updates = esc_attr($instance['tw_updates']); ?>
<p><label for="<?php echo $this->get_field_id('tw_username'); ?>"><?php _e('twitter username:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('tw_username'); ?>" name="<?php echo $this->get_field_name('tw_username'); ?>" type="text" value="<?php echo $tw_username; ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('tw_updates'); ?>"><?php _e('number of updates to display:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('tw_updates'); ?>" name="<?php echo $this->get_field_name('tw_updates'); ?>" type="text" value="<?php echo $tw_updates; ?>" /></label></p>
<?php }
function update($new_instance, $old_instance) {
return $new_instance;
}
function widget($args, $instance) {
extract($args, EXTR_SKIP);
$tw_username = $instance['tw_username'];
$tw_updates = $instance['tw_updates'];
echo $before_widget; ?>
<h4>Tweets from <a href="http://twitter.com/<?php echo $tw_username; ?>">@<?php echo $tw_username; ?></a></h4>
<ul id="twitter_update_list">
<li>Fetching latest tweet</li>
</ul>
<p class="button"><a href="http://twitter.com/<?php echo $tw_username; ?>">Follow on Twitter</a></p>
<script src="/wp-content/themes/NAME/library/twitter.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/<?php echo $tw_username; ?>.json?callback=twitterCallback2&count=<?php echo $tw_updates; ?>"></script>
<?php echo $after_widget;
} } register_widget('Tweets_Show');
what i'd like to have happen is the two lines that call the javascript:
<script src="/wp-content/themes/NAME/library/twitter.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/<?php echo $tw_username; ?>.json?callback=twitterCallback2&count=<?php echo $tw_updates; ?>"></script>
could appear in wp_footer, (but it needs to pull through $tw_username and $tw_updates.
how can i do this? i know it should be possible, it's just beyond what i know in php.