Title: Plugin Unexpected Code
Last modified: August 19, 2016

---

# Plugin Unexpected Code

 *  [james141](https://wordpress.org/support/users/james141/)
 * (@james141)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/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: http://jcookdesign.co.uk
       Description: Displays your latest tweet
       Version: 1.0
       Author: Jcook Design
       Author URI: http://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('http://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)

 *  [Reuben](https://wordpress.org/support/users/greuben/)
 * (@greuben)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-unexpected-code/#post-1647232)
 * You have not defined these two function in you Class jcd_simple_twitter
    `function
   activate(){}` & `function deactivate(){}`
 * if you don’t want to do anything while activating or deactivating your plugin,
   remove these two hooks
 *     ```
       register_activation_hook( __FILE__, array('jcd_simple_twitter', 'activate'));
       register_deactivation_hook( __FILE__, array('jcd_simple_twitter', 'deactivate'));
       ```
   
 *  [Reuben](https://wordpress.org/support/users/greuben/)
 * (@greuben)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-unexpected-code/#post-1647233)
 * and also `register_sidebar_widget` is deprecated, use `wp_register_sidebar_widget`
 * [http://codex.wordpress.org/Function_Reference/wp_register_sidebar_widget](http://codex.wordpress.org/Function_Reference/wp_register_sidebar_widget)
 *  Thread Starter [james141](https://wordpress.org/support/users/james141/)
 * (@james141)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-unexpected-code/#post-1647236)
 * Yeah makes sense I suppose :p
 * thanks for your help.
 *  Thread Starter [james141](https://wordpress.org/support/users/james141/)
 * (@james141)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-unexpected-code/#post-1647240)
 * Ok, i’ve tried everything but I can’t get `wp_register_sidebar_widget` to work
   properly in place of `register_sidebar_widget`
 * Any clues? The codex is no help to me.
 *  [Reuben](https://wordpress.org/support/users/greuben/)
 * (@greuben)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-unexpected-code/#post-1647248)
 * `wp_register_sidebar_widget` is almost same `register_sidebar_widget` but it 
   has an additional id field.
    eg:-
 *     ```
       wp_register_sidebar_widget('unique-id','JCD Simple Twitter', array('jcd_simple_twitter', 'widget'));
           wp_register_widget_control('unique-id','JCD Simple Twitter', array('jcd_simple_twitter', 'control'));
       ```
   
 * check this…I removed some deprecated functions.
    [http://pastebin.com/raw.php?i=DTd8f7KK](http://pastebin.com/raw.php?i=DTd8f7KK)
 *  [WebTechGlobal](https://wordpress.org/support/users/webtechglobal/)
 * (@webtechglobal)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-unexpected-code/#post-1647574)
 * Dealing with 203 characters myself in my new plugin. Fix then then I can release
   it for the first time.
 * I recommend you change your activate and deactive function names. They are too
   generic.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Plugin Unexpected Code’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * 6 replies
 * 3 participants
 * Last reply from: [WebTechGlobal](https://wordpress.org/support/users/webtechglobal/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-unexpected-code/#post-1647574)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
