You need to put your widget code in the functions.php file of your current theme or inside the plugin. To put it in a plugin, create a new folder in the plugins folder and create a .php file with the name of the folder created in this folder. In this file, use this code to run your plugin:
<?php ?>
Obviously change the values ββto something useful for your plugin. Then you can paste the widget code into this file, and it should be ready to use.
Sources:
http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Plugin_API
source share