Plugin Unexpected Code
-
Hi, I have tried to make a simple twitter plugin that basically looks at the rss feed from a twitter account and then displays this wherever a widget is placed. It all works fine apart from the fact that i get a message when activating the plugin:
The plugin generated 305 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
Here’s the code for the plugin.
<?php /* Plugin Name: JCD Simple Twitter Plugin URI: https://jcookdesign.co.uk Description: Displays your latest tweet Version: 1.0 Author: Jcook Design Author URI: https://jcookdesign.co.uk */ add_action("widgets_init", array('jcd_simple_twitter', 'register')); register_activation_hook( __FILE__, array('jcd_simple_twitter', 'activate')); register_deactivation_hook( __FILE__, array('jcd_simple_twitter', 'deactivate')); class jcd_simple_twitter { function control(){ $data = get_option('jcd_simple_twitter'); ?> <p><label>Title <input name="title" type="text" value="<?php echo $data['title']; ?>" /></label></p> <p><label>Twitter Username <input name="username" type="text" value="<?php echo $data['username']; ?>" /></label></p> <p><label>Tweets to Display <input name="number" type="text" value="<?php echo $data['number']; ?>" /></label></p> <?php if (isset($_POST['username'])){ $data['username'] = attribute_escape($_POST['username']); $data['number'] = attribute_escape($_POST['number']); $data['title'] = attribute_escape($_POST['title']); update_option('jcd_simple_twitter', $data); } } function widget($args){ $data = get_option('jcd_simple_twitter'); echo $args['before_widget']; echo $args['before_title'] . $data['title'] . $args['after_title']; include_once(ABSPATH . WPINC . '/feed.php'); // Get a SimplePie feed object from the specified feed source. $rss = fetch_feed('https://twitter.com/statuses/user_timeline/'.$data['username'].'.rss'); if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly // Figure out how many total items there are, but limit it to 5. $maxitems = $rss->get_item_quantity($data['number']); // Build an array of all the items, starting with element 0 (first element). $rss_items = $rss->get_items(0, $maxitems); endif; ?> <ul> <?php if ($maxitems == 0) echo '<li>No items.</li>'; else // Loop through each feed item and display each item as a hyperlink. foreach ( $rss_items as $item ) : ?> <li> <a href="<?php echo $item->get_permalink(); ?>" title="<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>"><?php echo $item->get_title(); ?></a> </li> <?php endforeach; ?> </ul> <? echo $args['after_widget']; } function register(){ register_sidebar_widget('JCD Simple Twitter', array('jcd_simple_twitter', 'widget')); register_widget_control('JCD Simple Twitter', array('jcd_simple_twitter', 'control')); } } ?>
Any help appreciated ??
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Plugin Unexpected Code’ is closed to new replies.